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
Try like this
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
Try like this
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
LucD, Still Uptime shows blank without any error
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was able to fix, there was typo error from my end. Thanks a lot for your help