Last active
February 18, 2018 15:36
-
-
Save Agazoth/30dd89bde330489154c52b32fe99a765 to your computer and use it in GitHub Desktop.
Gets the uptime from Windows and Linux machines. A possible solution for Iron Scripter Prequel 2018 Puzzle 6
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)][string]$ComputerName,[PSCredential]$Credential,$Authentication) | |
$Parameters = @{ | |
ScriptBlock = [scriptblock]::Create('if($env:OS -match "Windows"){$strBoot = $((systeminfo | find "System Boot Time") -replace "^.+:\s+|,")} else {$strBoot = (who -b) -replace "^\D+"}; Get-Date $strBoot') | |
} | |
if (!$ComputerName){$ComputerName = hostname} | |
if ($Credential){$Parameters.Add('Credential',$Credential);$Parameters.Add('ComputerName',$ComputerName)} | |
if ($Authentication){$Parameters.Add('Authentication',$Authentication)} | |
$BootDate = icm @Parameters | |
[PSCustomObject]@{ | |
ComputerName = $ComputerName | |
LastBootTime = $BootDate | |
Uptime = [math]::Round($(New-TimeSpan $BootDate).TotalDays,3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment