Hi.
I need some help tweaking my script to report the correct uptime of each VM;
The script:
Get-VM |
select Name, @{N="DNSName";E={$_.ExtensionData.Guest.Hostname}}, @{N="FolderName";E={ $_.Folder.Name}},
@{N='FolderPath';E={
$path = $_.Name
$parent = Get-View -Id $_.ExtensionData.Parent
while($parent){
$path = "$($parent.Name)\$path"
if($parent.Parent){
$parent = Get-View -Id $parent.Parent
}
else{
$parent = $null
}
}
$path}},
NumCpu, MemoryGB,
@{N="Up Time";E={$Timespan = New-Timespan -Seconds (Get-Stat -Entity $VM.Name -Stat sys.uptime.latest -Realtime -MaxSamples 1).Value
"" + $Timespan.Days + " Days, "+ $Timespan.Hours + " Hours, " +$Timespan.Minutes + " Minutes"}},
Notes
|
Export-Csv "C:\Reporting\uptimetest_$((Get-Date).ToString("yyyy-MM-dd")).csv" -NoTypeInformation
This script runs fine, but the "uptime" column shows the same for all VMs.
Anyone have any good ide?
...And yes...I'm new to PS scripting...