【发布时间】:2017-11-25 23:36:42
【问题描述】:
如何在脚本中使用 Powershell 确定操作系统类型(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 上会失败,因为它无法被识别。
【问题讨论】:
-
get-host不包含该数据吗? -
我不能说。也不是来自文档link
标签: linux windows powershell operating-system powershell-core