Tuesday, April 28, 2015

[Powershell] Getting uptime for a service, saved to a database

Needed this for someone in a different group. 

  • Get a list of servers
  • For every server on that list:
    • use get-wmiobject to get the list of open processes that match my search term.
    • Select relevant fields like computername, starttime, processid, and the exec path
    • Include a rounded up/down number of hours the process has been up
    • Write to a table.
Prereqs are the old standbys: out-datatable, write-datatable. 

Technical bits:
Powershell has some crazy syntax.  The $starttime is one example.
The most annoying part was having to get the times converted from the WMI format (MDTF) to something normal. 

No comments: