Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to be able to detect in a script whether a Windows Server 2008 installation has specific Windows features enabled, and install them if necessary. I do not simply want to use a "try to install the feature, even if it is already installed" approach, as I need to be able to perform additional steps at the install time.

For example, I know I can install the SNMP Service using the command line:

pkgmgr /iu:SNMP

What I don't know is how to check whether this package has been installed, ideally from VBScript/WMI, but from a command-line tool if necessary.

Ideally I also want to find a solution that does not involve Powershell, as I don't want to have to lower the powershell execution privileges that are set by default in a Windows 2008 install.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

It seems to me that you can do this easily with a powershell script (run as administrator).

Here is an example powershell script found on the internet:

#Powershell Script To Install SNMP Services
Import-Module ServerManager
#Check If SNMP Services Are Already Installed
$check = Get-WindowsFeature | Where-Object {$_.Name -eq "SNMP-Services"}
If ($check.Installed -ne "True") {
        #Install/Enable SNMP Services
        Add-WindowsFeature SNMP-Services | Out-Null
}

You can find more information about finding out a feature's name in:
Windows Server 2008 R2: Adding Features via PowerShell

If WMIC is an option, see these articles:
New Server Core Tips
Using the new Windows Server 2008 Core OCList and OCSetup CLI tools to Add & Remove Server Roles

If programming is an option, see this stackoverflow article:
How can I programmatically check if a server feature is installed in Windows Server 2008?

share|improve this answer
    
Yeah, I actually figured out this method too, but I'm trying to do this without Powershell (this script is intended to be run as part of an OS installation, and I don't want to change the PowerShell default security settings, which prevent powershell scripts from being executed). –  Richard Aug 25 '10 at 18:59
    
@Richard: See my edit. –  harrymc Aug 25 '10 at 19:32
    
The programming option using WMI was exactly what I was looking for - thanks. I'd looked at WMI classes, but hadn't found the WMI_ServerFeature class –  Richard Aug 26 '10 at 7:25

The suggested answer can actually be simplified a little bit:

$check = get-windowsfeature -name SNMP-Services
if ($check.Installed -ne "True") {
        #Install/Enable SNMP Services
        Add-WindowsFeature SNMP-Services | Out-Null
}
share|improve this answer

Here is a powershell command that works perfectly. It installs SNMP Services (SNMP Service + SNMP WMI Provider)

Servermanagercmd –install SNMP-Services
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.