如何从脚本中使用Powershell来确定操作系统类型(Linux,Windows)?从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上失败。
不'得到-host'包含数据? – 4c74356b41
[这可能有用](http://www.sqlserver-dba.com/2012/06/how-to-check-operating-system-type-with-powershell.html) – gms0ulman
不是我能说的。也不是从文档[链接](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/get-host) – boomcubist