Windows boot time using Pssession

This topic contains 4 replies, has 4 voices, and was last updated by  Graham Beer 1 year, 2 months ago.

  • Author
  • #66772

    Parth Gandhi

    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.

  • #66775

    Sam Boutros

    This script gets the LastBootTime among other things.

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

  • #66778

    Graham Beer

    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.

  • #66832

    Richard Siddaway

    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

  • #66846

    Graham Beer

    That's good to know Richard, thanks.

You must be logged in to reply to this topic.