Last active
January 7, 2016 21:30
-
-
Save mmarchese/ca100c94b5159f1d9b75 to your computer and use it in GitHub Desktop.
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
[CmdletBinding()] | |
param ( | |
[parameter(ValueFromPipeline=$true)] | |
[string[]]$ComputerName = $env:COMPUTERNAME | |
) | |
foreach ($Computer in $ComputerName) { | |
if (Test-Connection $Computer -Quiet -Count 1 -BufferSize 16) { | |
try { | |
$os = Get-WmiObject -Class win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop | |
$uptime = (New-TimeSpan $($os.converttodatetime($os.lastbootuptime)) $(Get-Date)).days | |
$lastBootTime = $os.converttodatetime($os.lastbootuptime) | |
$status = "OK" | |
if ($uptime -ge 30) { | |
$MightNeedPatched = $true | |
} | |
} catch { | |
$uptime = "ERROR" | |
$lastBootTime = "ERROR" | |
$status = "ERROR" | |
$MightNeedPatched = "ERROR" | |
} | |
[PSCustomObject]@{ | |
"Computer Name" = $Computer | |
"Status" = $status | |
"Last Booted Up" = $lastBootTime | |
"Uptime" = "$uptime days" | |
"Might Need to be Patched" = $MightNeedPatched | |
} | |
} else { | |
Write-Output "Computer $Computer is OFFLINE." | |
[PSCustomObject]@{ | |
"Computer Name" = $Computer | |
"Status" = "OFFLINE" | |
"Last Booted Up" = "Unknown" | |
"Uptime" = "Unknown" | |
"Might Need to be Patched" = "Unknown" | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment