Checking boot time is essential in determining the server or
workstation uptime.
If ever there is a server or computer that is not supposed
to be rebooted or shutdown but then to check whether the server or computer hasn’t
done a power cycle is to check its uptime.
Checking the uptime will determine how long the server has
been online.
PowerShell is just an awesome tool to do this kind of task.
Here’s the script:
#run a command line using PowerShell
$boot_time = & systeminfo | find "System Boot Time"
Write-Output $boot_time
#display a pop-up message box using PowerShell
[System.Windows.MessageBox]::Show('Hello,
the ' + $boot_time)
#split string using regex and match spaces
$splitx = $boot_time -split
'\s+' -match
'\S'
#get the 4th array on the array element
$xtime = Get-Date $splitx[4]
#get the current date and time of the system
$Date = Get-Date
Write-Output $date
#subtract the current date and time with the boot time
$get_duration = $Date - $xtime
$xmin_total = $get_duration.TotalMinutes
#convert the minutes to hours and minutes
$time_var = new-timespan -minutes
$xmin_total
$uptime_hours = $time_var.Hours
$uptime_minutes=
$time_var.Minutes
$uptime_total = ($uptime_hours, " hours and " ,$uptime_minutes ,
" minutes")
Write-Output $uptime_total
[System.Windows.MessageBox]::Show('Hello,
server uptime is: ' + $uptime_total)
Sample output:
Cheers!
================================
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
Heaven's Dew Fall Prayer app for Android :
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment