Created
June 6, 2019 07:38
-
-
Save bobalob/501295587968cf9456b0fcdfc6539bf3 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
function Get-ADTime { | |
Param( | |
[Switch]$IncludeUptime | |
) | |
$pdcName = Get-ADForest | Select-Object -ExpandProperty RootDomain | Get-ADDomain | Select-Object -ExpandProperty PDCEmulator | |
net time \\$pdcName /set /y | |
$outtab = @() | |
(Get-ADForest).GlobalCatalogs | sort | % { | |
$rawtime = w32tm /stripchart /computer:$_ /dataonly /samples:1 | Select -Last 1 | |
$out = "" | Select DC, LocalTime, OffsetFromLocal | |
$out.DC = $_ | |
$out.LocalTime = $rawTime.Split(",")[0].Trim() | |
$out.OffsetFromLocal = [float]($rawTime.Split(",")[1].Trim() -replace "s","") | |
if ($IncludeUptime) { | |
$lastboot = (Get-CimInstance -ComputerName $_ -ClassName win32_operatingsystem).lastbootuptime | |
$uptime = [Math]::Round(((Get-Date) - $lastboot).TotalDays,1) | |
$out | Add-Member NoteProperty UpDays $Uptime | |
} | |
$out | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment