Avatar of Jay Thomas
Jay Thomas
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Add feature using powershell to server 2008r2

Hi all,
I need to add the SNMP feature to over 200 windows server 2008 R2 servers. I have the command to add the feature using powershell when I logged on locally but I'd like the command to add it to a remote server on the same domain,   I am using a domain admin account.

 I have googled a solution but I'm not a powershell guy so having difficulty understanding it.

For local I know it is:
Import-Module servermanager
Get-WindowsFeature
Add-WindowsFeature SNMP-Services


Any help appreciated.
Windows Server 2008PowershellActive Directory

Avatar of undefined
Last Comment
Jay Thomas

8/22/2022 - Mon
Prashant Girennavar

Try below.

http://social.technet.microsoft.com/wiki/contents/articles/4032.how-to-install-snmp-remotely.aspx

This does not use powershell but it uses batch file and PSExec.

Thanks,

-Prashant Girennavar.
SOLUTION
David Paris Vicente

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jay Thomas

ASKER
Hi David, many thanks. How do I target the script at a remote server?
ASKER CERTIFIED SOLUTION
David Paris Vicente

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MortgageCenter

If you only need to do this once, I would suggest using the SNMP Enabler from Solarwinds.

http://www.solarwinds.com/products/freetools/snmp-enabler-for-windows/enable-snmp.aspx

It is a free tool and worked wonders when I enabled SNMP on our systems.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Jay Thomas

ASKER
Thank you for the info David - much appreciated.

Can I just check that I have this correct. The script will add the SNMP feature on the target machine and not cause an issue if the feature was already enabled. Will it then go on to populate the SNMP community within the SNMP service too?
David Paris Vicente

Hi Jason,

Just a note the name of the service is SNMP-Service and not SNMP-Services so you will have to remove the last s character from the name of the service, if you don´t do this you will be presented with an error.

"The script will add the SNMP feature on the target machine ".
Yes, this piece of code will check if the service is installed or not, if not the service will be installed.
#Check If SNMP Services Are Already Installed
$check = Get-WindowsFeature | Where-Object {$_.Name -eq "SNMP-Service"}
If ($check.Installed -ne "True") {
	#Install/Enable SNMP Services
	Add-WindowsFeature SNMP-Service | Out-Null
}

Open in new window


 "if the feature was already enabled"

This is checked by this piece of code, if the service is not enabled and not configured this will be configured.
But if the service is already enabled and configured, the settings will be override on the Reg Keys. So be carefully.


##Verify Windows Services Are Enabled
If ($check.Installed -eq "True"){
	#Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
	reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
	#Used as counter for incremting permitted managers
	$i = 2
	Foreach ($manager in $pmanagers){
		reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
		$i++
		}
	#Set SNMP Community String(s)- *Read Only*
	Foreach ( $string in $commstring){
		reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $string /t REG_DWORD /d 4 /f | Out-Null
		}
}
Else {Write-Host "Error: SNMP Services Not Installed"}

Open in new window


I hope this will be what you want.

Regards
Jay Thomas

ASKER
Many thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.