Solved

help with getting  custom annotations from VMWare powercli

Posted on 2015-02-04
5
427 Views
Last Modified: 2015-02-10
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
0
Comment
Question by:jsparnova
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Dawid Fusek
Comment Utility
You should probably to use "Get-CustomAttribute -Name Business.Unit" command and integrate it to this script.

regards
NTShad0w
0
 

Author Comment

by:jsparnova
Comment Utility
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
0
 

Accepted Solution

by:
jsparnova earned 0 total points
Comment Utility
Solved this myself:

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}},
@{N='Description';E={ ($_ | Get-Annotation -Name 'Description').Value}},
@{N='Category';E={ ($_ | Get-Annotation -Name 'BU').Value}}
0
 
LVL 5

Expert Comment

by:Dawid Fusek
Comment Utility
good you found a way mate,

best regards
NTShad0w
0
 

Author Closing Comment

by:jsparnova
Comment Utility
I figured it out myself.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Teach the user how to install log collectors and how to configure ESXi 5.5 for remote logging Open console session and mount vCenter Server installer: Install vSphere Core Dump Collector: Install vSphere Syslog Collector: Open vSphere Client: Config…
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now