[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1196
  • Last Modified:

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.
0
Jason Thomas
Asked:
Jason Thomas
2 Solutions
 
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 VicenteCommented:
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
David Paris VicenteCommented:
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
 
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 VicenteCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now