I am having issue with Powershell.I try and run my script which is
Param (
[string]$ComputerName
)
$ComputerName = $ComputerName -replace " ", ","
Get-WmiObject Win32_OperatingSystem -ComputerName $ComputerName | select csname, @{LABEL='LastBootUpTime' ;EXPRESSION= {$_.ConverttoDateTime($_.lastbootuptime)}}
I run it with:
.\GetBootTime.ps1 -ComputerName localhost,<another computer>
I get Error Message:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).
However if I run:
Get-WmiObject Win32_OperatingSystem -ComputerName localhost,<another computer> | select csname, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
which is the main line in the script then it works. Any suggestions?
<another computer>
. You could simplify your test to just.\GetBootTime.ps1 -ComputerName <another computer>
. The "However if I run:" section of your question isn't very clear - what value does $ComputerName have in that context? – Frank Boyne