Showing posts with label snmp. Show all posts
Showing posts with label snmp. Show all posts

Monday, 14 November 2011

Remotely installing SNMP on Server 2008

1. On one server, install SNMP 2008 (C:\ocsetup SNMP), configure the service and export HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ to C:\snmp.reg


2. Create a batch file that will a). import the key exported from step 1. b). delete the 1 value which needs to be removed to allow 'Any host' to connect to the SNMP service.
reg import C:\snmp\snmp.reg
reg delete HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers /v 1 /f


3. Copy these files to all of the servers via this script (make sure to create the C:\computers.txt and populate):
Const ForReading = 1
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\computers.txt")
Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    strRemoteFile = "\\" & strComputer & "\C$\snmp.reg"
    objFSO.CopyFile "C:\snmp\snmp.reg", strRemoteFile, OverwriteExisting
Loop


4. Use psexec to execute the snmp.bat on each server via:
C:\runas /user:domain\username "psexec \\server\ C:\snmp.bat"


5. Use snmpwalk from this page and run
snmpwalk -v 1 -c community-here 127.0.0.1

6. Remove all of the files using:
Const ForReading = 1
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\computers.txt")

Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    strRemoteFile = "\\" & strComputer & "\C$\snmp.reg"
    objFSO.DeleteFile strRemoteFile
Loop



Steps 4 & 6 can be improved by getting the @file command with psexec, but since it's paired with runas it might be tricky to get that to work.