I needed to massively change the region and timezone settings for all computers. To do this, I created a small script for Powershell:
# Get timezone and region settings from the current computer
$timezone = Get-TimeZone | Select-Object -ExpandProperty Id
$region = (Get-Culture).Name
# Print timezone and region settings to console
Write-Host "Current timezone: $timezone"
Write-Host "Current region: $region"
# Get a list of currently online computers in Active Directory
$onlineComputers = Get-ADComputer -Filter {Enabled -eq $true} -Properties OperatingSystem,OperatingSystemVersion | Where-Object { Test-Connection $_.Name -Count 1 -Quiet }
# Loop through the list of online computers and set the timezone and region
foreach ($computer in $onlineComputers) {
$computerName = $computer.Name
$currentRegion = Invoke-Command -ComputerName $computerName -ScriptBlock {
(Get-Culture).Name
}
Write-Host "Current region on $computerName: $currentRegion"
Write-Host "Setting timezone and region on $computerName..."
Invoke-Command -ComputerName $computerName -ScriptBlock {
param($tz, $rgn)
Set-TimeZone -Id $tz -PassThru
Set-Culture -CultureInfo $rgn -ErrorAction SilentlyContinue
} -ArgumentList $timezone, $region
}
# Display a message once the settings have been applied to all computers
Write-Host "Timezone and region settings applied to all online computers in Active Directory.
Description of the PowerShell code:
- First, the script retrieves the current timezone and region settings from the local computer using the
Get-TimeZoneandGet-Culturecmdlets. - Then, the current timezone and region settings are displayed on the console using the
Write-Hostcmdlet. - The script uses the
Get-ADComputercmdlet to retrieve a list of all currently enabled computers in the Active Directory domain. It filters the list to include only online computers by checking their connectivity status with theTest-Connectioncmdlet. - The script loops through each online computer in the list and performs the following actions:
- The name of the current computer is stored in a variable called
$computerName. - The script retrieves the current region setting for the remote computer using the
Invoke-Commandcmdlet and theGet-Culturecmdlet wrapped in a script block. - The current region setting for the remote computer is displayed on the console using the
Write-Hostcmdlet. - The script sets the new timezone and region settings for the remote computer using the
Invoke-Commandcmdlet and theSet-TimeZoneandSet-Culturecmdlets wrapped in a script block.
- The name of the current computer is stored in a variable called
- After all the online computers have been processed, a final message is displayed on the console using the
Write-Hostcmdlet to indicate that the timezone and region settings have been applied to all online computers in Active Directory.
This script allows you to update the timezone and region settings on multiple computers in Active Directory at once, and also provides feedback on the current region setting for each computer before and after the new settings are applied.