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
        {
        }
    }
  • 相关阅读:
    二叉树的线索
    关于JavaScript变量提升的理解
    HTML label标签的一点理解
    超详细轮播图,让你彻底明白轮播图!
    javascript 入门——this属性的理解!
    《机电传动控制》第二次作业
    第四周学习笔记
    学习笔记
    linux下,让命令提示符显示完整路径
    kafka api消费集群中kafka数据报错问题
  • 原文地址:https://www.cnblogs.com/thescentedpath/p/timezone.html
Copyright © 2011-2022 走看看