Monday, December 30, 2013

Uptime in Powershell using WMI

The below script is written in power shell and is used to compute up-time for remote Windows system using WMI WIn32_OperatingSystem . You need to have Power shell installed to run this and also would require Administrative rights on Remote hosts  which you are targeting this script. Copy the below script in green to notepad and save it as get-uptime.ps1.

Go to powershell, and set-location to the directory where you have saved the script.

Execute the script .\get-uptime.ps1 hostname to get the uptime of remote system

#Script to Find the uptime of remote host
#pass the paramter hostname after the script during usage
#Author: Shashanka Haritsa 2011
#Function to Convert Date String
Function datestringtodate($stringdata){
if ($args -eq “Help”) {
Write-host “Usage get-uptime.ps1 hostname” -Foregroundcolor Cyan
Write-host “Ex: get-uptime.ps1 server01, where server01 is the hostname” -Foregroundcolor Cyan
$lastuptimedate = (get-wmiobject win32_operatingsystem -Computername $args).LastBootUpTime
$convert = datestringtodate($lastuptimedate)
$currentdate =(get-wmiobject win32_operatingsystem -Computername $args).localDateTime
$convert1 =datestringtodate($currentdate)
$up =$convert1-$convert
$uptimet = ” System is up for ” + $up.Days + ” Days ” + $up.Hours + ” Hours ” + $up.Minutes + ” Minutes ” + $up.Milliseconds + ” Milliseconds”
#End of the script
I hope it helps you all!

1 comment:

  1. The payout share tells you how much of your cash wager 바카라사이트 might be paid out in winnings. This is very necessary when you're planning on enjoying in} for real cash. While free slots are great to play only for fun, many players favor the thrill of half in} real cash video games as it can possibly} result in big wins. As you can to|you presumably can} see from the desk under, each real cash and free video games include advantages and drawbacks.