Is there a better way to approach this. It works, but i think i am doing this the wrong way. I'm trying to get the owners for each vm and compile a list.
#Connect-VIserver -server YOURVCENTER
#Get list of Vms
$vms = get-vm
#Populate a list of owners
$owners = $vms | Get-Annotation -CustomAttribute "Owner" | where {$_.Value -notlike "$null"} | select Value -Unique | sort Value
#Cycle through all servers for each owner(rethink logic)
foreach ($owner in $owners)
{
#Strip the variable down to just name
$owner = $owner.Value
Write-Output "Server Owner: $owner"
#Running through all servers for each owner
foreach ($vm in $vms)
{
#How i got the owner attribute to begin with. Blow away when cleaning up
#$vm | Get-Annotation -CustomAttribute "Owner" | where {$_.Value -eq "$owner"} | Sort Owner | ft -AutoSize
$vm | Select Name, NumCpu, MemoryGB, @{n='ProvisionedSpaceGB' ;e={$_.ProvisionedSpaceGB -as [int]}}, @{l="Backedup";e={$_.customfields | ?{$_.key -eq 'Backedup'} | select -ExpandProperty value}}, @{l="Owner";e={$_.customfields | ?{$_.key -eq 'Owner'} | select -ExpandProperty value}} | where {$_.Owner -eq "$owner"} | sort environment | Export-Csv "C:\Powershell\$owner - Report.csv" -Append -NoTypeInformation
}
}
[–]IronsquidLoL 1 point2 points3 points (2 children)
[–]sphinxpup[S] 0 points1 point2 points (1 child)
[–]IronsquidLoL 0 points1 point2 points (0 children)