Is there a way to find out the uptime for the Linux based Vms through powershell script. I am able to find the uptime for windows based VMs but I am unable to find uptime for the Linux based VMs.

  • Do you have ssh client on the machine where you run the script? – Romeo Ninov Mar 28 '17 at 7:24
  • Depending on the hypervisor you might be able to query the hypervisor guest tools, if installed on the VMs. – Lambert Mar 28 '17 at 10:21
  • yes, vmware tools are installed on those machine. How do I acheive this ? I can easily do it with a bash script if I am in a Linux machine. But I am running a query on Vcentre; it works for all the windows machine but I need one for linux machines – Mintu Mar 29 '17 at 2:03

Your best bet would probably be to run the uptime command remotely via SSH. If you don't have a powershell ssh client, you can install Posh SSH pretty easily.

With Posh SSH you can accomplish your objective by runnning:

New-SSHSession -ComputerName "example.com" -Credential (Get-Credential)

Invoke-SSHCommand -Index 0 -Command "uptime"

You can add '-KeyFile' on the New-SSHSession command if you want to use an RSA key.

The Get-SSHSession command will give you the index number above, but if you only have one connection open it should always be 0.

  • Hi Ian, I already have a bash script that provide me the uptime for all the linux machine when I am logged in to a linux machine. What I am trying to achieve is that if there is any way where I should be able to run the query on the Vcentre and get the desired results. I am able to fetch the information for windows server but it want to able to achieve the same results for Linux machine as well. – Mintu Mar 29 '17 at 2:07
  • I'm not following. You said you wanted to use powershell right? The above solution will run on powershell in Windows and get the uptime of any Linux based machine. Or are you looking for something vCenter specific? – Ian Blais Mar 29 '17 at 9:34
  • vCentre Specific. However, I will try that option too and share an update soon. – Mintu Mar 29 '17 at 13:20
  • I would suggest editing your question to clarify that. Regrettably I do not have a vCenter server to test with so I will be of little help here. Best of luck. – Ian Blais Mar 30 '17 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.