Code original address: https://gallery.technet.microsoft.com/scriptcenter/get-timezone-powershell-4f1a34e6
<#. Synopsis This script retreives the timezone of a local or remote computer via WMI: DESCRIPTION This script retreives the timezone of a local or remote computer via WMI: NOTES Created By:jason Wasser Modified:9/11/2015 03:27:30PM Changelog:*Added credential support. * Simplified code as per suggestions from Jeffrey Hicks @jeffhicks.example Get-TimeZone shows the localhost TimeZone. EXAMPLE Get-timezone-ComputerName SERVER1 shows the timezone of SERVER1. EXAMPLE Get-timezone-computername (get-Content C:\temp\computerlist.txt) Shows the timezone of a list of computers. LINK https:gallery.technet.microsoft.com/scriptcenter/get-timezone-powershell-4f1a34e6#>#get-timezone-computername (get-content d:\computerlist20160407.txt)Functionget-TimeZone {[cmdletbinding ()] [Alias ()]Param ( #Computer name[Alias (' Name ')] [Parameter (Mandatory=$false, Valuefrompipeline=$true, Valuefrompipelinebypropertyname=$true, Position=0)] [string[]]$ComputerName=$env: COMPUTERNAME, $Credential= [System.Management.Automation.PSCredential]::Empty)Begin { } Process { foreach($Computer inch $ComputerName) {try {$ServerInfo= Get-wmiobject-class Win32_timezone-computername$Computer-erroraction stop-credential$Credential $CN=$ServerInfo. __server$TimeZone=$ServerInfo. Caption} catch {$TimeZone=$_. Exception.Message}finally { $propHash= @{Computername=$ComputerTimeZone=$TimeZone } $objTimeZone= New-object-type Psobject-property$propHash $objTimeZone } } } End { }}
Powershell Function Get-timezone