我想提示用户提供时区。然后,如果服务器设置为该时区,则返回true,否则返回false。我无法弄清楚为什么我的代码总是返回false ...
提前致谢!
cls
$InTimeZone = Read-Host -Promt "What Time Zone should this server be in?"
$HostName = $env:Computername
$ServerInfo = Get-WmiObject -Class win32_timezone -ComputerName $HostName
$TimeZone = $ServerInfo.Caption
If ($InTimeZone -like $TimeZone ){$ResTimeZone = "Validation Passed: Server time zone is $TimeZone"}
Else {$ResTimeZone = "Nope."}
$TimeZone
$ResTimeZone
答案 0 :(得分:1)
这里有两件事不正确。
更好的解决方案是:
If ($TimeZone -match $InTimeZone) {
$ResTimeZone = "Validation Passed: Server time zone is $TimeZone"
} Else {
$ResTimeZone = "Nope."
}