Link to home
Start Free TrialLog in
Avatar of jsparnova
jsparnova

asked on

help with getting custom annotations from VMWare powercli

I have the following script to list all VMs and their datastore. The script will list vm, datastore, provisioned and used space, and folder name. I cannot figure out how to add a a line to also list a custom attribute.

I have a custom attribute called Business.Unit. how would I add this to my script?

Get-VM |
Select Name,
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},
@{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,1)}},
@{N="ProvisionedSpaceGB";E={[math]::Round($_.ProvisionedSpaceGB,1)}},
@{N="Folder";E={$_.Folder.Name}} |
Export-Csv F:\report.csv -NoTypeInformation -UseCulture
Avatar of Dawid Fusek
Dawid Fusek

You should probably to use "Get-CustomAttribute -Name Business.Unit" command and integrate it to this script.

regards
NTShad0w
Avatar of jsparnova

ASKER

I am able to run both commands seperatly and get the output needed. Can someone help me combine these. It looks like one is outputting to a list and the other to a table.:
PART 1:

Get-VM | Get-Annotation | Select @{N="VM";E={$_.AnnotatedEntity.Name}},Value

OUTPUT:
VM                                                     Value
--                                                     -----
IE8TESTER                                              Solutions

Part 2:
Get-VM |
Select Name,
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},
@{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,1)}},
@{N="ProvisionedSpaceGB";E={[math]::Round($_.ProvisionedSpaceGB,1)}},
@{N="Folder";E={$_.Folder.Name}}

output:
Name               : IE8TESTER
Datastore          : VNXe:Storage1
UsedSpaceGB        : 13.1
ProvisionedSpaceGB : 52.3
Folder             : Discovered virtual machine
ASKER CERTIFIED SOLUTION
Avatar of jsparnova
jsparnova

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
good you found a way mate,

best regards
NTShad0w
I figured it out myself.