Saturday, March 15, 2014

My office is located in EST and we have a data center onsite but we also have another data center in CST. I don't know why but every so often we get some developers that don't understand that. So I have to sometimes find out why their code is an hour wrong or show them that they need to make their code time insensitive. I use this to do it.


Function Get-TimeZone {
Param(
[Parameter(Mandatory=$True,Position=1)]
[Array]$ComputerName
)
$AllTime=@()
ForEach ($Computer in $ComputerName ) {
IF((gwmi -class Win32_SystemTimeZone -ComputerName $Computer -ErrorAction SilentlyContinue) -gt $null){
$Time = (Get-Time $Computer)
$Zone1 = (gwmi -class Win32_SystemTimeZone -ComputerName $Computer).setting
$Zone = $Zone1.split('=')[-1]
$obj=New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "ServerName" -Value $Time.ServerName
$obj | Add-Member -MemberType NoteProperty -Name "DateTime" -Value $Time.DateTime
$obj | Add-Member -MemberType NoteProperty -Name "TimeZone" -Value $Zone
$AllTime += $obj
}ELSE{
Write-Output "Your current Credentials do not have access to this system ($Computer)"
}
}
IF($AllTime.count -gt 0){
Write-Output $AllTime
}
}
I decided to give up on the code highlighter and throw some business the way of https://gist.github.com

No comments:

Post a Comment