【发布时间】:2018-05-30 03:08:26
【问题描述】:
我在使用 Powershell 时遇到问题。我尝试运行我的脚本
Param (
[string]$ComputerName
)
$ComputerName = $ComputerName -replace " ", ","
Get-WmiObject Win32_OperatingSystem -ComputerName $ComputerName | select csname, @{LABEL='LastBootUpTime' ;EXPRESSION= {$_.ConverttoDateTime($_.lastbootuptime)}}
我运行它:
.\GetBootTime.ps1 -ComputerName localhost,<another computer>
我收到错误消息:
Get-WmiObject : RPC 服务器不可用。 (例外来自 HRESULT: 0x800706BA)。
但是,如果我运行:
Get-WmiObject Win32_OperatingSystem -ComputerName localhost,<another computer> | select csname, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
这是脚本中的主线 然后它工作。 有什么建议吗?
【问题讨论】:
-
错误很可能是告诉您它无法与
<another computer>上的 WMI 通信。您可以将测试简化为.\GetBootTime.ps1 -ComputerName <another computer>。您问题的“但是,如果我运行:”部分不是很清楚 - $ComputerName 在这种情况下有什么价值? -
@FrankBoyne 如果我运行 .\GetBootTime.ps1 -ComputerName
它工作正常,似乎是当我使用两台计算机时它不起作用。也希望让它更清楚
标签: windows powershell