Get TimeZone - PowerShell
Overview
Get-TimeZone retrieves information about time zones on the local computer or remote servers. It provides details such as time zone name, offset from Coordinated Universal Time (UTC), and daylight saving time (DST) settings.
Syntax
Get-TimeZone [-Credential <PSCredential>] [-ComputerName <String>] [-ListAvailable]
Options/Flags
- -Credential
: Specifies a PSCredential object for authenticating to remote computers. - -ComputerName
: Indicates the name of the remote computer to retrieve time zone information from. - -ListAvailable: Lists all available time zones on the local computer.
Examples
Example 1: Get local computer’s time zone
Get-TimeZone
Example 2: Get remote computer’s time zone
Get-TimeZone -ComputerName server1.contoso.com
Example 3: List available time zones
Get-TimeZone -ListAvailable
Common Issues
- If the credentials supplied in -Credential are invalid, the command may fail with an error message stating “The user name or password is incorrect.”
- If the target remote computer is unreachable, the command may fail with an error message indicating a network issue.
Integration
Get-TimeZone can be integrated with other PowerShell commands to perform complex operations, such as:
# Check if a time zone is supported on a remote computer:
if (Get-TimeZone -ComputerName server1.contoso.com -Name 'Central Standard Time') {
Write-Output "Time zone is supported."
} else {
Write-Output "Time zone is not supported."
}