Home Mail MemberMap Chat (0) Wallpapers
Go Back   ChiefsPlanet > The Ed & Dave Lounge > Media Center

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 02-08-2013, 08:23 AM   Topic Starter
QuikSsurfer QuikSsurfer is offline
Got swag?
 
QuikSsurfer's Avatar
 
Join Date: Aug 2003
Location: Madison, MS
Casino cash: $108999
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,748
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
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump




All times are GMT -6. The time now is 10:48 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.