View Single Post
Old 02-08-2013, 09:23 AM  
QuikSsurfer QuikSsurfer is offline
Got swag?
 
QuikSsurfer's Avatar
 
Join Date: Aug 2003
Location: Madison, MS
Casino cash: $10008287
Any PowerShell gurus out there?

I've got over 400 windows 2008 R2 servers and I need to install SNMP services and then set the community string and host for it to accept packets from.
Now a few of these servers already have SNMP services installed.. I've put together a PS script to check if SNMP services (a windows feature essentially) is installed -- if it's not, install it - if it is, skip installation and go to deleting the existing strings and creating the new ones.
I've got two local servers here that I'm testing on (both do not have SNMP services installed) and I'm getting the script to run but it fails (says it fails but it actually does install the SNMP services) and doesn't set the community strings UNLESS you run the script a second time. After running the script a second time, all is well..... I've been looking at this for far too long and need another pair of eyes.

And all execution policies are set to RemoteSigned.

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

cls
echo "This script installs and configures SNMP to accept packets from NTOMEAPP and Community Names"
echo "-------------------------------------------------------------------------------------------------------------------------- "

import-module servermanager

#Variables
$pmanagers = "172.17.66.206"
$commstring = '0m$aGr0p3r'

#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
echo "SNMP not installed"
echo "Installing . ."
Add-WindowsFeature SNMP-Services | Out-Null
}

##Verify Windows Servcies Are Enabled
If ($check.Installed -eq "True"){
# Delete existing values
echo "Deleting existing permitted hosts"
reg DELETE "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /va /f

#Set SNMP Permitted Manager(s)
Foreach ($manager in $pmanagers){
echo "Setting permitted managers"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d 172.17.66.206 /f | Out-Null

}
#Set SNMP Community String(s)- *Read Only*
Foreach ( $string in $commstring){
echo "Setting READ ONLY PUBLIC as Accepted Community Names"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $string /t REG_DWORD /d 4 /f | Out-Null
}
echo "Restarting/starting SNMP service"
Restart-Service "snmp service"
echo " "
echo "Done!"
}
Else {Write-Host "Error: SNMP Services Not Installed (and failed trying to install)."}
Posts: 11,847
QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.QuikSsurfer has parlayed a career as a truck driver into debt free trailer and jon boat ownership.
    Reply With Quote