代码原文地址: 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
{
}
}

最新文章

  1. Ubuntu使用MyEclipse闪退的解决办法
  2. kettle参数、变量详细讲解[转]
  3. ./yy.sh -d bash 执行脚本时所加的参数
  4. C++ 中的模板类声明头文件和实现文件分离后,如何能实现正常编译?
  5. 分布式数据存储 - MySQL主从复制高可用方案
  6. 将UIImage保存成JPG或PNG格式存储在本地
  7. ZigBee绑定细节
  8. (转)百度Map API
  9. 用日志文件备份sqlserver
  10. less封装样式有规律的类选择器-遁地龙卷风
  11. Java第一个程序之HelloWorld
  12. dic and set
  13. asp.net对接拼多多
  14. Java代码封装redis工具类
  15. SpringMVC @RequestParam和@RequestBody的区别
  16. day 28 hasattr getattr serattr delattr 和带__内置__ 类的内置方法
  17. 【LeetCode】数组--合并区间(56)
  18. ssh端口转发(之kettle ssh方式连接数据库)
  19. 如何下载spring的jar包?
  20. eclipse 断点找到同名的其它类

热门文章

  1. Canvas转换为Blob对象并使用Ajax发送
  2. Mysql暴错注入代码-webshell
  3. mysql 常用功能
  4. RS232接口
  5. [sh]清理memcached缓存
  6. NSArray、NSMutableArray和NSMutableDictionary的用法
  7. JSON的String字符串与Java的List列表对象的相互转换
  8. 李洪强iOS开发之Xcode快捷键
  9. mybatis的foreach写用法
  10. hbase java Api练习