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