Created
January 12, 2016 08:29
-
-
Save dennisrhodes/b3c611a694161d3ce7df to your computer and use it in GitHub Desktop.
january-2016-scripting-games-puzzle
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
function Get-Uptime{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true)] | |
[ValidateNotNullOrEmpty()] | |
[String[]]$ComputerName = $env:COMPUTERNAME | |
) | |
PROCESS{ | |
foreach($computer in $ComputerName){ | |
$isAlive = Test-Connection -ComputerName $computer -Count 1 -Quiet | |
if($isAlive -eq $true){ | |
$compSystem = Get-WmiObject -ComputerName $computer -ClassName Win32_ComputerSystem | |
$osSystem = Get-WmiObject -ComputerName $computer -ClassName Win32_OperatingSystem | |
$bool = ((Get-Date)-$osSystem.ConvertToDateTime($osSystem.LastBootUpTime)).Days -gt 30 | |
$hash = [ordered]@{ | |
ComputerName = $compSystem.Name | |
StartTime = $osSystem.ConvertToDateTime($osSystem.LastBootUpTime) | |
"Uptime (Days)" = ((Get-Date)-$osSystem.ConvertToDateTime($osSystem.LastBootUpTime)).Days | |
Status = "OK" | |
MightNeedPatched = $bool | |
} | |
$obj = New-Object -TypeName psobject -Property $hash | |
$obj | |
} | |
else{ | |
$hash = [ordered]@{ | |
ComputerName = $computer | |
StartTime = "" | |
"Uptime (Days)" = "" | |
Status = "ERROR" | |
MightNeedPatched = "" | |
} | |
Write-Warning -Message "$computer is Offline" | |
$obj = New-Object -TypeName psobject -Property $hash | |
$obj | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment