Created: 10/25/20
Update: 10/25/20
Below is a script to update SNMP IP address and string on all domain servers and then restart the SNMP service:
Invoke-command -ComputerName @((Get-ADComputer -Filter ‘OperatingSystem -Like “Windows Server*”‘).Name) -ScriptBlock {
#Variables
$pmanagers = @(“IP Address or FQDN address”)
$CommString = @(“YourStringHERE”)#Import ServerManger Module
Import-Module ServerManager#Check if SNMP-Service is already installed
$check = Get-WindowsFeature -Name SNMP-ServiceIf ($check.Installed -ne “True”) {
#Install/Enable SNMP-Service
Write-Host “Enabling PSRemoting temporarily….”
Enable-PSRemoting -Force
Write-Host “SNMP Service Installing…”
Get-WindowsFeature -name SNMP* | Add-WindowsFeature -IncludeManagementTools | Out-Null
}$check = Get-WindowsFeature -Name SNMP-Service
##Verify Windows Services Are Enabled
If ($check.Installed -eq “True”){
Write-Host “Configuring SNMP Services…”
#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#Set SNMP Traps and SNMP Community String(s) – *Read Only*
Foreach ($String in $CommString){
reg add (“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\” + $String) /f | Out-Null
# Set the Default value to be null
reg delete (“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\” + $String) /ve /f | Out-Null
reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities” /v $String /t REG_DWORD /d 4 /f | Out-Null
$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
reg add (“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\” + $String) /v $i /t REG_SZ /d $manager /f | Out-Null
$i++
Write-Host “SNMP Successfully Updated, Restarting Service…”
Restart-Service -Name SNMP -Force
Write-Host “SNMP Service Restarted on $env:computername, moving on…”
Write-Host “Session closing on $env:computername, End Transmission. ERROR #! – No Connection”
}
}
}
Else {Write-Host “SNMP Services Not Install & Change Not Performed”
}
}