Automation

 View Only
  • 1.  Uptime parameter shows blank

    Posted Jul 30, 2019 06:02 AM

    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



  • 2.  RE: Uptime parameter shows blank
    Best Answer

    Posted Jul 30, 2019 06:36 AM

    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.



  • 3.  RE: Uptime parameter shows blank

    Posted Jul 30, 2019 07:42 AM

    LucD, Still Uptime shows blank without any error



  • 4.  RE: Uptime parameter shows blank

    Posted Jul 30, 2019 07:48 AM

    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?



  • 5.  RE: Uptime parameter shows blank

    Posted Jul 30, 2019 09:12 AM

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