Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Code Snippet from aperturescience.su
- # Parameters
- [Parameter(Position=5, Mandatory=$false, HelpMessage="Maximum uptime allowed")]$maxuptime=45,
- # Function to help format the strings
- function WMIDateStringToDate($Bootup) {
- [System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup)
- }
- # Main Body
- $negmax = -$maxuptime
- $system = Get-WmiObject -class Win32_OperatingSystem
- $Bootup = $system.LastBootUpTime
- $LastBootUpTime = WMIDateStringToDate($Bootup)
- $now = Get-Date
- $Uptime = $now - $LastBootUpTime
- $d = $Uptime.Days
- $h = $Uptime.Hours
- $m = $uptime.Minutes
- Write-Verbose "System Up for: $($d) days, $($h) hours, $($m) minutes"
- if ($LastBootUpTime -lt $now.adddays($negmax))
- {
- Write-Verbose "System has been up longer than $maxuptime days"
- }
- else
- {
- Write-Verbose "System has not been up longer than $maxuptime days"
- }
- # Code Snippet from aperturescience.su
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement