Geeks With Blogs

Lance's TextBox

Brandon updated his get-uptime script to output a custom object. Brandon's script works with the LastBootUpTime property returned from WMI Win32_OperatingSytem.

I already talked briefly about the get-snmp, set-snmp, get-trap, and send-trap cmdlets that are included in NetCmdlets. Here's how you can use get-snmp to get the sysUpTime from any SNMP-enabled device. Note: sysUpTime is defined as the time since the last re-initialization (ie, boot) of the device, in 100ths of a second.

get-snmp -agent [string] -oid sysUpTime.0

Here are my SNMP-versions of Brandon's examples:

This gets uptime on a Single Server:

PS C:\> get-snmp -agent 10.0.1.11 -oid sysUpTime.0                                                                      
                                                                                                                        
Host                          OID                           OIDValue                      OIDType                       
----                          ---                           --------                      -------                       
10.0.1.11                     1.3.6.1.2.1.1.3.0             155734659                     TimeTicks                     
                                                                                                                        
                                                                                                                        
PS C:\> get-bufferhtml | out-file sample.html                                                                           


This gets all servers up for more than 30 days: (the "magic number": there are 8640000 hundreths of a second in 1 day)

PS C:\> (get-snmp -agent 255.255.255.255 -oid sysUpTime.0) | ?{$_.OIDValue / (8640000) -gt 30}                          
                                                                                                                        
Host                          OID                           OIDValue                      OIDType                       
----                          ---                           --------                      -------                       
10.0.1.219                    1.3.6.1.2.1.1.3.0             296372079                     TimeTicks                     
                                                                                                                        
                                                                                                                        
PS C:\> get-bufferhtml | out-file sample.html                                                                           

This Displays the Last Reboot Time of a list of servers.

PS C:\> (get-snmp -agent 255.255.255.255 -oid sysUpTime.0) | %{([datetime]::Now).AddSeconds(-($_.OIDValue/100))}        
                                                                                                                        
Wednesday, January 24, 2007 8:56:18 AM                                                                                  
Friday, February 09, 2007 3:22:27 PM                                                                                    
Monday, February 19, 2007 1:15:43 AM                                                                                    
                                                                                                                        
                                                                                                                        
PS C:\> get-bufferhtml | out-file sample.html                                                                           

Technorati : , , ,

Posted on Tuesday, February 27, 2007 3:26 PM PowerShell | Back to top


Comments on this post: PowerShell cmdlet for SNMP (part 2: sysUpTime)

# re: PowerShell cmdlet for SNMP (part 2: sysUpTime)
Requesting Gravatar...
I just Ran accross this post. I really love the get/set-snmp snapin's. Not exactly for the uptime, but we use snmp at work alot and this snap-in has proved very useful. Great stuff Lance.
Left by Brandon (BSonPosh) on Mar 05, 2007 7:53 PM

# re: PowerShell cmdlet for SNMP (part 2: sysUpTime)
Requesting Gravatar...
You sure about this?
-------------
sysUpTime is defined as the time since the last re-initialization (ie, boot) of the device, in 100ths of a second.
-------------

I don't know about windows hosts, but if we are talking net-snmp, sysUpTime is number of ticks since snmpd was started. Usually this is when the box restarts via init scripts, but it's not guaranteed as snmpd could have been restarted months later.
Left by adam on Apr 26, 2008 12:06 AM

# re: PowerShell cmdlet for SNMP (part 2: sysUpTime)
Requesting Gravatar...
Adam - you're right. Boot != initialization of the agent, but for most practical purposes it is a safe assumption to make.
Left by Lance on Dec 29, 2009 3:53 AM

# re: PowerShell cmdlet for SNMP (part 2: sysUpTime)
Requesting Gravatar...
How do i get the snmp traps set on a server and the ip addresses set with them?
Left by Hecktor on Jul 07, 2011 1:46 PM

Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net