Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SamErde committed Dec 9, 2024
1 parent 3543bdd commit c804787
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Windows/Get-NtpClientConfig-Alt (WIP).ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Work in Progress
# See original at https://github.com/samerde/powershell/windows/Get-NtpClientConfig.ps1

function Test-ThisApproach {
$computerName = 'ABC-V-12345'

$Hive = [Microsoft.Win32.RegistryHive]::LocalMachine
$Path = 'SYSTEM\CurrentControlSet\Services\W32Time'

try {
$BaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive, $ComputerName)
$SubKey = $BaseKey.OpenSubKey($Path)
if (!$SubKey) {
Write-Warning "Registry key '$Path' does not exist." -WarningAction Stop
} else {
$Result = foreach ($ValueName in $SubKey.GetValueNames()) {
[PsCustomObject]@{
'ValueName' = if (!$ValueName -or $ValueName -eq '@') { '(Default)' } else { $ValueName }
'ValueData' = $SubKey.GetValue($ValueName)
'ValueKind' = $SubKey.GetValueKind($ValueName)
}
}
}
} catch {
throw
} finally {
if ($SubKey) { $SubKey.Close() }
if ($BaseKey) { $BaseKey.Close() }
}

# output on screen
$Result | Sort-Object ValueName

# or output to CSV file
# $Result | Sort-Object ValueName | Export-Csv -Path 'X:\output.csv' -NoTypeInformation
}

0 comments on commit c804787

Please sign in to comment.