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:\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)

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
    {
    }
}
时间: 2024-10-29 19:06:57

Powershell Function Get-TimeZone的相关文章

Powershell function to get all dhcp lease

前提是安装RSAT tool for win10,这样才有相应的powershell module 来管理DHCP 另外要有权限来查询DHCP服务器 加入下面代码到$profile 中 function get-dhcplease{ $dhcpservers=Get-DhcpServerInDC $dhcpscopes=$dhcpservers|%{$computername=$_.dnsname;Get-DhcpServerv4Scope -ComputerName $computername

Powershell Function Get-PendingReboot

获取系统中Restart Pending的计算机 $servers=get-content D:\serverlist.txt Get-PendingReboot -ComputerName $servers | select computer,CBServicing,WindowsUpdate,CCMClientSDK,PendComputerRename,PendFileRename,{$_.PendFileRenval},RebootPending | Export-Csv d:\pend

Powershell 创建炫丽美观的Html报表

我们通过PowerShell可以获取各种信息,如何保存这些获取的信息呢?最简单的方法是保存为csv或者是xml文件,这样可以轻松的导入导出.不过这两种文件在人眼的可读性上都不够美观.xml从程序的角度非常方便,但是看起来很不舒服:同样的,尽管csv文件可以通过Excel打开,但是最重要的一点,他没有颜色!对于很多习惯把Excel表格标注的五颜六色的人来说,csv的世界实在是太昏暗了. 那么直接保存为XLSX文件如何呢?传统的PowerShell对Office的支持很不好,只能通过ComObjec

SharePoint网站测试数据自动化系列——Upload files to SharePoint library using PowerShell.

日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的脚本越来越多,所以我决定整理一下,并把一些常用的可复用的方法陆续发布上来. 今天先讲一下用PowerShell上传文件到SharePoint library中的方法,代码如下: Add-PSSnapin Microsoft.SharePoint.PowerShell function CreateAgendaDocumentData { param($siteUrl,$listTitle,$file

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint Lists

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.sharepoint.powershell function CreateSPLists() { $sites = Get-SPSite if($sites.count -eq 0) { Write-Warning "There is no site available." CreateSPLists } else { Write-Host "C

通过PowerShell创建SharePoint Site Collection。

通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function CreateTeamSite() { $webApps = Get-SPWebApplication $webAppsUrl = $webApps.Url if($webApps.count -eq 1) { Write-Host "You have only one web applicatio

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint List Items

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.sharepoint.powershell function CreateSPListItems() { $sites = Get-SPSite if($sites.count -eq 0) { Write-Warning "There is no site available." CreateSPListItems } else { Write-Host

Unit Testing PowerShell Code with Pester

Summary: Guest blogger, Dave Wyatt, discusses using Pester to analyze small pieces of Windows PowerShell code. Note   This is a five-part series that includes the following posts: What is Pester and Why Should I Care?Learn about a new test framework

通过PowerShell创建SharePoint Web

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin Microsoft.SharePoint.PowerShell function createSPWeb() { $webApps = Get-SPWebApplication chooseWebAppAndSelectSite $webApps } function chooseWebAppAndSelectSite($webApps) { Write-Host "Web appli