# Get the directory where the script is located $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition # Path to the server list file $serverListPath = Join-Path $scriptDir "servers.txt" # Prompt for username and credentials $username = Read-Host "Enter the username (e.g., DOMAIN\user or user@domain.com)" $cred = Get-Credential -UserName $username -Message "Enter the password for $username" # Read server names from file $servers = Get-Content -Path $serverListPath foreach ($server in $servers) { Write-Host "`n--- Syncing time on $server ---" -ForegroundColor Cyan try { Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock { Write-Host " Current time: $(Get-Date)" Write-Host " Forcing time sync from domain controller..." w32tm /resync /nowait Write-Host " Time sync initiated." } Write-Host " Time sync command sent successfully." -ForegroundColor Green } catch { Write-Host " Failed to sync time on $server: $_" -ForegroundColor Red } }