Skip to content

Instantly share code, notes, and snippets.

@bobalob
Created June 6, 2019 07:38
Show Gist options
  • Save bobalob/501295587968cf9456b0fcdfc6539bf3 to your computer and use it in GitHub Desktop.
Save bobalob/501295587968cf9456b0fcdfc6539bf3 to your computer and use it in GitHub Desktop.
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