相关疑难解决方法(0)

从Powershell确定操作系统版本,Linux和Windows

如何在脚本中使用Powershell确定操作系统类型(Linux,Windows)?

当我的脚本的这部分在Linux主机上运行时,无法识别ResponseUri.

$UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority
Run Code Online (Sandbox Code Playgroud)

所以我想要一个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
Run Code Online (Sandbox Code Playgroud)

我可以使用,Get-CimInstance Win32_OperatingSystem但它会在Linux上失败,因为它无法识别.

linux windows powershell operating-system

15
推荐指数
6
解决办法
1万
查看次数

标签 统计

linux ×1

operating-system ×1

powershell ×1

windows ×1