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.
LVL 1
Jason ThomasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prashant GirennavarCommented:
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.
0
David Paris VicenteSystems and Comunications  Administrator Commented:
Enables SNMP via Add-WindowsFeature (If not already enabled)
Configures SNMP Settings via reg add calls (Warning this will overwrite current settings)

#Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider)

#Variables :)
$pmanagers = "ADD YOUR MANAGER(s)"
$commstring = "ADD YOUR COMM STRING"

#Import ServerManager Module
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
}

##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


Test it first and let us know

Hope this helps.
0
Jason ThomasAuthor Commented:
Hi David, many thanks. How do I target the script at a remote server?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

David Paris VicenteSystems and Comunications  Administrator Commented:
Hi Jason,

First open notepad and save the script posted above. Something like this SNMPConfig.ps1.

Then I advise you to first to enter in a test machine that you want to run cmdlet remotely and run the Enabled-PSremoting -force from an elevated Windows powershell command line.

Then from your machine you have to open powershell command line from a elevated privileges and use this cmdlet to connect remotely to the other machine Enter-PSSession -ComputerName "Remote Machine name or IP" -credentials domain\username
In the open Powershell command line run the script.


If everything is ok you can enable PSremoting in the machines that you want to access remotely, by GPO.
Check this tutorial.

Let us know if helped.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MortgageCenterCommented:
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.
0
Jason ThomasAuthor Commented:
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?
0
David Paris VicenteSystems and Comunications  Administrator Commented:
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
0
Jason ThomasAuthor Commented:
Many thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.