Powershell - Check for Timezone on multiple servers and change Timezone.

 $Servers = Get-Content "C:\Temp\Servers.txt"


foreach ($Server in $Servers) {
try {
$TimeZone = Invoke-Command -ComputerName $Server -ScriptBlock {
(Get-TimeZone).DisplayName
}

[PSCustomObject]@{
Server = $Server
TimeZone = $TimeZone
}
}
catch {
[PSCustomObject]@{
Server = $Server
TimeZone = "Unable to connect"
}
}
}

---------------

Change Time Zone to Eastern Time on Multiple Servers


$Servers = Get-Content "C:\Temp\Servers.txt"

foreach ($Server in $Servers) {
try {
Invoke-Command -ComputerName $Server -ScriptBlock {
Set-TimeZone -Id "Eastern Standard Time"
}

Write-Host "$Server - Time zone updated successfully" -ForegroundColor Green
}
catch {
Write-Host "$Server - Failed: $_" -ForegroundColor Red
}
}


Verify after change:

$Servers = Get-Content "C:\Temp\Servers.txt"

foreach ($Server in $Servers) {
Invoke-Command -ComputerName $Server -ScriptBlock {
[PSCustomObject]@{
Server = $env:COMPUTERNAME
TimeZone = (Get-TimeZone).Id
CurrentTime = Get-Date
}
}
}

Comments

Popular posts from this blog

Troubleshooting Netlogon Error Codes

Troubleshooting SCEP certificate profile deployment to Android devices in Microsoft Intune