ganapa2000
Hot Shot
Hot Shot

Uptime parameter shows blank

Jump to solution

Hi,

I am getting the blank output for uptime days, Hours and Minutes, please help

Script

$script = @'

Get-WmiObject win32_operatingsystem | %{

  $_.ConverttoDateTime($_.lastbootuptime)

  }

'@

$machines = Get-Content .\CS_VM1.txt

Invoke-VMScript -VM $machines -ScriptText $Script -GuestUser "admin" -GuestPassword "password" |

Select @{N ='VM';E={$_.VM.Name}},

@{N='LastBootUpTime'; E={[DateTime]$_.ScriptOutput}},

@{N='Uptime';E={[math]::Round((New-TimeSpan -Start ([DateTime]$_.ScriptOutput) -End (Get-Date).Days + " Days " + (Get-Date).Hours + "Hours" + (Get-Date).Minutes + "Minutes"))}} | ft -auto

Output :

VM         LastBootUpTime    Uptime

APP04      05/26/2019 5:45:37 AM

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try like this

$script = @'

Get-WmiObject win32_operatingsystem | %{

  $_.ConverttoDateTime($_.lastbootuptime)

  }

'@

$machines = Get-Content .\CS_VM1.txt

Invoke-VMScript -VM $machines -ScriptText $Script -GuestUser "admin" -GuestPassword "password" |

Select @{N ='VM';E={$_.VM.Name}},

@{N='LastBootUpTime'; E={[DateTime]$_.ScriptOutput}},

@{N='Uptime';E={

   $diff = New-TimeSpan -Start ([DateTime]$_.ScriptOutput) -End (Get-Date)

   "$($diff.Days) Days $($diff.Hours) Hours $($diff.Minutes) Minutes"

   }} |

ft -auto

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try like this

$script = @'

Get-WmiObject win32_operatingsystem | %{

  $_.ConverttoDateTime($_.lastbootuptime)

  }

'@

$machines = Get-Content .\CS_VM1.txt

Invoke-VMScript -VM $machines -ScriptText $Script -GuestUser "admin" -GuestPassword "password" |

Select @{N ='VM';E={$_.VM.Name}},

@{N='LastBootUpTime'; E={[DateTime]$_.ScriptOutput}},

@{N='Uptime';E={

   $diff = New-TimeSpan -Start ([DateTime]$_.ScriptOutput) -End (Get-Date)

   "$($diff.Days) Days $($diff.Hours) Hours $($diff.Minutes) Minutes"

   }} |

ft -auto

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD, Still Uptime shows blank without any error

0 Kudos
LucD
Leadership
Leadership

Seems to work perfectly for me.

How are you running this?
Is the script returning anything for the VMs you specified in the .TXT file?

uptime.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot

I was able to fix, there was typo error from my end. Thanks a lot for your help Smiley Happy

0 Kudos