Programmatically check if a Windows Server 2008 Feature is installed, and Install it
Solution 1
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?
Solution 2
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
}
Related videos on Youtube
sahil
I am a software developer working for a data centre based in Reading, UK
Updated on September 17, 2022Comments
-
sahil almost 2 years
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.
-
sahil almost 14 yearsYeah, 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).
-
harrymc almost 14 years@Richard: See my edit.
-
sahil almost 14 yearsThe 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