Update windows_time_sync

This commit is contained in:
vijay 2025-06-04 02:28:47 +00:00
parent 0fa2855e23
commit 9b469c36cf

View File

@ -1,6 +1,5 @@
# Invoke-Expression (Invoke-WebRequest -Uri "https://git.technozone.com.au/vijay/Scripts/raw/branch/main/windows_time_sync" -UseBasicP | Select-Object -ExpandProperty Content) # Invoke-Expression (Invoke-WebRequest -Uri "https://git.technozone.com.au/vijay/Scripts/raw/branch/main/windows_time_sync" -UseBasicP | Select-Object -ExpandProperty Content)
function Show-Menu { function Show-Menu {
Clear-Host Clear-Host
Write-Host "==============================" Write-Host "=============================="
@ -9,7 +8,8 @@ function Show-Menu {
Write-Host "1. Check NTP Server Configuration" Write-Host "1. Check NTP Server Configuration"
Write-Host "2. Sync Time with Domain Controller" Write-Host "2. Sync Time with Domain Controller"
Write-Host "3. Set to Nearest NTP Server" Write-Host "3. Set to Nearest NTP Server"
Write-Host "4. Exit" Write-Host "4. Check Windows Time Service"
Write-Host "5. Exit"
} }
function Check-NTPConfiguration { function Check-NTPConfiguration {
@ -38,15 +38,30 @@ function Set-ToNearestNTP {
Pause Pause
} }
function Check-WindowsTimeService {
$service = Get-Service w32time
if ($service.Status -ne 'Running') {
Write-Host "Windows Time service is not running. Starting the service..."
Start-Service w32time
Write-Host "Windows Time service started."
} else {
Write-Host "Windows Time service is already running."
}
# Ensure it's syncing to the nearest time server
Set-ToNearestNTP
}
do { do {
Show-Menu Show-Menu
$choice = Read-Host "Please enter your choice (1-4)" $choice = Read-Host "Please enter your choice (1-5)"
switch ($choice) { switch ($choice) {
1 { Check-NTPConfiguration } 1 { Check-NTPConfiguration }
2 { Sync-TimeWithDC } 2 { Sync-TimeWithDC }
3 { Set-ToNearestNTP } 3 { Set-ToNearestNTP }
4 { Write-Host "Exiting..."; break } 4 { Check-WindowsTimeService }
5 { Write-Host "Exiting..."; break }
default { Write-Host "Invalid choice. Please select again." } default { Write-Host "Invalid choice. Please select again." }
} }
} while ($true) } while ($true)