Windows boot time using Pssession

Tagged: 

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Graham Beer Graham Beer 4 months ago.

  • Author
    Posts
  • #66772
    Profile photo of Parth Gandhi
    Parth Gandhi
    Participant

    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.
    thanks.

  • #66775
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    This script gets the LastBootTime among other things.

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

  • #66778
    Profile photo of Graham Beer
    Graham Beer
    Participant

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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
    Profile photo of Graham Beer
    Graham Beer
    Participant

    That's good to know Richard, thanks.

You must be logged in to reply to this topic.