Skip to content

Instantly share code, notes, and snippets.

@heyvoon
Last active August 29, 2015 14:23
Show Gist options
  • Save heyvoon/cce0e94c7bc5e00405dd to your computer and use it in GitHub Desktop.
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!
# ------------------------------------------------------------------------
# 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