zoukankan      html  css  js  c++  java
  • Powershell Function Get-TimeZone

    代码原文地址: 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:30 PM 
    
        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:	empcomputerlist.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)
    
    
    Function Get-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 in $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 = $Computer
                        TimeZone = $TimeZone
                    }
                    $objTimeZone = New-Object -type PSObject -Property $propHash
                    $objTimeZone
                    }
                }
        }
        End
        {
        }
    }
  • 相关阅读:
    自制电脑红外遥控接收器(PC软解码) 转
    .NET Micro Framework介绍
    如何测试移动web?
    自行开发高效精简的二进制序列化库(支持精简框架集) 转
    35个优秀的电子商务网站界面
    .Net Micro Framework中的线程
    《肖申克的救赎》 阅后小记
    分享 MSDN 下载工具(Word/PDF)
    OEA ORM中的分页支持
    OEA 中的多国语言实现
  • 原文地址:https://www.cnblogs.com/thescentedpath/p/timezone.html
Copyright © 2011-2022 走看看