如何在脚本中使用Power
shell确定操作系统类型(
Linux,Windows)?
当我的脚本的这部分在Linux主机上运行时,无法识别ResponseUri.
$UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority
所以我想要一个If语句来确定与此类似的操作系统类型:
If ($OsType -eq "Linux")
{
$UrlAuthority = ($Request.BaseResponse).RequestMessage | Select-Object -ExpandProperty RequestUri | Select-Object -ExpandProperty host
}
Else
$UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority
我可以使用Get-CimInstance Win32_OperatingSystem但它在Linux上会因为无法识别而失败.