How to install SNMP on remote servers using Powershell

6

Hi there,

Recently I was working on a task for enabling monitoring on different servers which included ESXi hosts and a bunch Windows Servers.

One of the requirement was to install the SNMP Services feature on all the Windows Servers. Now I had somewhere around 100 odd servers that this action had to performed.

You must have guessed it by now that I will be using Powershell to complete this task. Hence the title How to install SNMP on remote servers using Powershell.

In order to achieve this we will be making use of the cmdlet Invoke-Command.

The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. With a single Invoke-Command command, you can run commands on multiple computers.

At first you will have to make a .ps1 file stating that you want to install SNMP services on a server.

Import-Module ServerManager
Install-WindowsFeature SNMP-Service

Now save this as .ps1 file. I will save it as InstallSNMP.ps1 on the C drive.

You need to make sure that Remoting is enabled on the machines that you will perform this action.

You cantake a look at the article that I have written to enable Remoting using Group Policy.

Next up, say I want to install this on 3 or 4 computers. Then I will make use of the below command to achieve the requires results.

Invoke-Command -ComputerName Computer1, Computer2 -FilePath C:\InstallSNMP.ps1

This will install the SNMP feature on the two remote servers Computer1 and Computer 2.

In an another scenario, lets say that you have 100's of servers on which you would like to enable this feature.

In that case, first we would make a list of servers in a text file called servers.txt

And then execute the below lines and you could save it as a script as well for future reference.

$Servers = Get-Content C:\servers.txt
foreach ($Server in $Servers){
Invoke-Command -ComputerName $Server -Filepath C:\InstallSNMP.ps1
}

As yoiu can see that I have assigned the text to a variable called $Servers.

In the next step, we are using foreach loop to apply a certain code to the list of servers.

Voila! You just installed a feature on hundreds of servers even without logging into them.

I hope this has been informative and thank you for reading.

Share.

About Author

I am Adil Arif, working as a Senior Technical Support Engineer at Rubrik as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

6 Comments

  1. this just mess up my server win 2012.
    the SNMP service is there but no option to configure the service and I am now unable to remove it!

    • You just needed to exit Services and Start Services back up and you will see it – But I’m guessing you figured that out by now ….

Leave A Reply