Skip to content

Get-TimeZoneInfo

Windows: Retrieves current time zone settings

#Requires -Version 5.1

[CmdletBinding()]
Param
(
    [string]$ComputerName = $env:COMPUTERNAME,

    [switch]$ListAvailable,

    [pscredential]$Credential
)

Process
{
    try
    {
        $scriptBlock = {
            Param($List)
            if ($List)
            {
                Get-TimeZone -ListAvailable | Select-Object Id, DisplayName, BaseUtcOffset
            }
            else
            {
                Get-TimeZone | Select-Object Id, DisplayName, BaseUtcOffset
            }
        }

        if ($ComputerName -ne $env:COMPUTERNAME)
        {
            $invokeParams = @{
                'ComputerName' = $ComputerName
                'ScriptBlock'  = $scriptBlock
                'ArgumentList' = $ListAvailable
                'ErrorAction'  = 'Stop'
            }
            if ($null -ne $Credential)
            {
                $invokeParams.Add('Credential', $Credential)
            }

            $result = Invoke-Command @invokeParams
        }
        else
        {
            $result = &$scriptBlock -List $ListAvailable
        }

        # Add ComputerName to output
        $results = foreach ($r in $result)
        {
            $r | Add-Member -MemberType NoteProperty -Name ComputerName -Value $ComputerName -PassThru
        }

        Write-Output $results
    }
    catch
    {
        throw
    }
}

Specifies the name of the computer to query. Defaults to the local computer.

Off

If set, returns a list of all time zones available on the system.

Specifies a PSCredential object for remote connection.

An interactive directory of PowerShell scripts.