You can use a VIProperty I once wrote to retrieve the full blue folderpath. To avoid having to call the VIProperty twice I used the script scope to store the $path variable.
New-VIProperty -Na...
See more...
You can use a VIProperty I once wrote to retrieve the full blue folderpath. To avoid having to call the VIProperty twice I used the script scope to store the $path variable.
New-VIProperty -Name 'BlueFolderPath' -ObjectType 'VirtualMachine' -Value {
param($vm)
function Get-ParentName{
param($object)
if($object.Folder){
$blue = Get-ParentName $object.Folder
$name = $object.Folder.Name
}
elseif($object.Parent -and $object.Parent.GetType().Name -like "Folder*"){
$blue = Get-ParentName $object.Parent
$name = $object.Parent.Name
}
elseif($object.ParentFolder){
$blue = Get-ParentName $object.ParentFolder
$name = $object.ParentFolder.Name
}
if("vm","Datacenters" -notcontains $name){
$blue + "/" + $name
}
else{
$blue
}
}
(Get-ParentName $vm).Remove(0,1)
} -Force | Out-Null
#Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope AllUsers
$stat = 'sys.osuptime.latest'
$now = Get-Date
$vms = Get-VM
Get-Stat -Entity $vms -Stat $stat -Realtime -MaxSamples 1 |
Select @{N='VM';E={$_.Entity.Name}},
@{N='GuestOS';E={$_.Entity.ExtensionData.Guest.GuestFullName}},
@{N='Notes';E={$_.Entity.ExtensionData.Summary.Config.Annotation}},
@{N='VMware Tools State';E={$_.Entity.ExtensionData.Guest.ToolsStatus}},
@{N='VMware Tools Version';E={$_.Entity.ExtensionData.Guest.ToolsVersion}},
@{N='CreateDate';E={$_.Entity.CreateDate}},
@{N='LastOSBoot';E={$now.AddSeconds(- $_.Value)}},
@{N='UptimeDays';E={[math]::Floor($_.Value/(24*60*60))}},
@{N="DNS";E={$_.Entity.ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},
@{N='Tag';E={(Get-TagAssignment -Entity $_.Entity -Category 'Backup').Tag.name}},
@{N='IT Team';E={
$script:path = $_.Entity.BlueFolderPath
$script:path.Split('/')[-2]
}},
@{N='Application';E={$script:path.Split('/')[-1]}} |
Export-Csv -Path .\VM_Uptime_Report.csv -NoTypeInformation -UseCulture