如何從腳本中使用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