Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - SNMP Service Install (Server 2008)

$
0
0

Hello, so this is a follow up to the assistance that was provided to me yesterday about checking to see if the SNMP service was installed across multiple servers.  I was able to gather a list of devices that require the SNMP service to be installed, and (thankfully) most of them are Server 2008 machines.  The pre-2008 machines I will just hit manually, since there are less than 20 of them, and to minimize confusion, and a lack of powershell knowledge from my side.

I have approximately 120 servers that will require the service to be installed onto them, and was looking to do this via powershell.  Luckily, I was able to find this great script online, and I have tested it with my own variables inserted, and it works great (for one server, ran manually on it).  I was wondering if somebody could help me figure out how to get the script to do the following two things:

1.  Install the SNMP service to multiple servers from a text file (I attempted this with the get-content).
2.  Output the results to either a text file or a csv file (also tried this as can be seen below).

Here is the script, with what I tried (and failed).  The only two lines of code that are mine, are the very top one and the very bottom one, I will bold them to indicate that.  Thanks for any help that may be offered.

    #Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider)
     
    Get-Content .\servers.txt
    #Variables :)
    $pmanagers = "MY VARIABLE 1"
    $commstring = "MY VARIABLE 2"
         
    #Import ServerManger 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 Servcies 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 /f /t REG_SZ /d localhost | 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 /f /t REG_SZ /d $manager | 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 /f /t REG_DWORD /d 4 | Out-Null
                    }
    }
    Else {Write-Host "Error: SNMP Services Not Installed"}| Export-Csv .\SNMP_Install.csv -NoTypeInformation


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>