Nick's Blog

如何使用Powershell来查看SNMP服务的设置

本篇将介绍如何使用Powershell来查看SNMP服务中的设置。

本脚本会通过调取注册表中的信息和服务的运行状态来实现功能。

本脚本会测试,服务是否运行,SNMP Agent的contact, Location, Trap Infomation, Accepted IP Addresses以及SNMP Service

$snmp = get-service snmp
if($snmp.Status -eq "Running"){
"SNMP Service is running."
$sysContact = (get-itemproperty HKLM:SYSTEMCurrentControlSetServicesSNMPParametersRFC1156Agent sysContact).syscontact
$sysLocation = (get-itemproperty HKLM:SYSTEMCurrentControlSetServicesSNMPParametersRFC1156Agent sysLocation).sysLocation
$sysServices = (get-itemproperty HKLM:SYSTEMCurrentControlSetServicesSNMPParametersRFC1156Agent sysServices).sysServices
$trapInfo = "HKLM:SYSTEMCurrentControlSetServicesSNMPParametersTrapConfiguration"
$acceptedIPadd = "HKLM:SYSTEMCurrentControlSetServicesSNMPParametersPermittedManagers"
if ($sysContact -eq "admin@901it.com") {
"SNMP Service Agent Contact is admin@901it.com."
}else{
"SNMP Service Agent Contact is not admin@901it.com."
}

if ($sysLocation -ne $null){
"SNMP Service Agent Location repersent " + $sysLocation
}else{
"SNMP Service Agent Location has not configured."
}

if ($sysServices -eq "79"){
"All the services are ticked."
}else{
"Please check SNMP Service > Agent Tab, see if all the services are ticked."
}

if($trapInfo){
"Trap infomation:"
get-childitem $trapInfo
}else{
"Cannnot find trap info, please check the SNMP Service > Trap tab."
}

if($acceptedIPadd){
"Accept IP Addresses:"
Get-Item $acceptedIPadd
}else{
"cannot find accepted IP address, please check the SNMP Service > Security tab"
}
}else{
"Please check SNMP Service, because it's not running"
}