Windows boot time using Pssession

hi, I am looking to get the windows boot time using the PSsession from a remote computer. I am looking for a script/command that will run New-pssession in a loop till the connection is established with the remote machine. i can then use it with Measure-command cmdlet to get the time taken. Can someone please help with it.

This script gets the LastBootTime among other things.

Not sure where the PSSession comes in the picture here !?

Hi Parth,

From what you write I believe you are trying to check remote machines for the there last boot time ?

If this is the case you are much better of using the ‘Invoke-Command’ cmdlet. You can pass machines to the pipeline and run a scriptblock against them with a command to check lastBootTime. An example always helps, this might be what you are after:

'PC1', 'PC2' | foreach  {
    Invoke-Command -ComputerName $_ -ScriptBlock { 
        Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime 

Hope this helps.

If you’re using Get-CimInstance you don’t need to wrap it in Invoke-Command. Get-CimInstance uses WSMAN to talk to remote machines and its -ComputerName parameter can take an array of computer names

Get-CimInstance -ClassName win32_operatingsystem -ComputerName ‘PC1’, ‘PC2’ | select csname, lastbootuptime

Wrapping a call to Get-WmiObject in Invoke-Command may be a good move as the WMI cmdlets use DCOM for remote access which is blocked by default on modern Windows systems

If you need to make multiple CIM calls to the remote machines create a CIM session

That’s good to know Richard, thanks.