Last active
August 29, 2015 14:23
-
-
Save heyvoon/cce0e94c7bc5e00405dd to your computer and use it in GitHub Desktop.
This script creates gets the LastBootUpDate from the PC and stores it on $LBT. Compares it with the specified variable $timeSpan and if LastBootUpTime is Less or Equal to the $timeSpan the PC is considered NON-COMPLIANT. This script is backward compatible with PowerShell 2.0!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------ | |
# NAME: DiscoverLastBootUpTime.ps1 | |
# AUTHOR: Andre @ http://blog.teksoporte.es | |
# DATE:06/16/2015 | |
# | |
# COMMENTS: This script creates gets the LastBootUpDate from the PC and | |
# stores it on $LBT. Compares it with the specified variable $timeSpan | |
# and if LastBootUpTime is Less or Equal to the $timeSpan the PC is | |
# considered NON-COMPLIANT. | |
# This script is backward compatible with PowerShell 2.0! | |
# | |
# ------------------------------------------------------------------------ | |
cls | |
$Compliance = $Null | |
$LBT = [System.Management.ManagementDateTimeconverter]::ToDateTime("$((gwmi Win32_OperatingSystem -computername $env:COMPUTERNAME).LastBootUpTime)") | |
$TimeSpan = (get-date).AddDays(-2) | |
if ($LBT -le $TimeSpan ) { | |
$Compliance = "NON-COMPLIANT" | |
} else { | |
$compliance = "COMPLIANT" | |
} | |
$Compliance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment