VMware Cloud Community
justinsmith
Enthusiast
Enthusiast
Jump to solution

Script to get all info from a vCenter

Looking for a powercli script to get me the following info from vCenter, for all vm's

vmname, ram, cpu, os, cluster name, and description and /or notes of the VM

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You need to replace the line

@{N="Notes";E={($_ | Get-VM Select-Object -Property Name,Notes).Name}},


with

Notes,


With the Get-VM cmdlet you already got VirtualMachine objects that contain the Notes property. So you don't need a calculated property for the Notes.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
7 Replies
justinsmith
Enthusiast
Enthusiast
Jump to solution

So I think I got what I need, but need something to pull the NOTES section of each VM....

Here's what I have.

Set-ExecutionPolicy Remotesigned -force
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core}
$VC1 = read-host "vcenter server name"
$date = Get-Date -DisplayHint DateTime -Format "yyyy-M-d"
Connect-VIServer -Server $VC1 -WarningAction SilentlyContinue
Get-VM | Select Name,PowerState, @{N="SnapName";E={
($_ | Get-Snapshot).Name}},@{N="Datastore";E={
($_ | Get-Datastore).Name}},@{ N="TotalDisk"; E={ 
($_ | Get-harddisk | measure-object -property CapacityKB -sum).Sum}},@{N="GuestOS";E={
($_ | Get-VMGuest).OSFullName}},@{N="Cluster";E={
($_ | Get-Cluster).Name}}| Export-Csv -NoTypeInformation -Path \\path\folder
Disconnect-VIServer -server $VC1 -Force -Confirm:$false

0 Kudos
michaelstump
Enthusiast
Enthusiast
Jump to solution

You mean the annotations? Just making sure I understand. If so, take a look at this: http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Get-Annotation.html.

Looks like:

Get-Annotation [[-CustomAttribute] <CustomAttribute[]>] [-Entity] <InventoryItem> [-Server <VIServer[]>] [<CommonParameters>]

mike

Data Center Virtualization with VMware - theeagerzero.blogspot.com
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

I saw that, but what Im trying to get is the Notes from that field and I cant seem to find the command to run with the get-annotations command.

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

In PowerCLI 5.1 the Notes are in the VirtualMachine's Notes field. It used to be in the Description field in previous PowerCLI versions. So you can use:

Get-VM | Select-Object -Property Name,Notes
Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
justinsmith
Enthusiast
Enthusiast
Jump to solution

I got that command to work by itself, but when I try to add it to my script it doesnt out put anything and I get no errors. Can someone tell me what Im missing?

# To Get the VM data with Snapshot, Datastore, Total Disk Size, Cluster Name, OS Name
Set-ExecutionPolicy Remotesigned -force
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core}
$VC1 = read-host "vcenterserver"
$date = Get-Date -DisplayHint DateTime -Format "yyyy-M-d"
Connect-VIServer -Server $VC1 -WarningAction SilentlyContinue
Get-VM | Select Name,PowerState,
@{N="GuestOS";E={($_ | Get-VMGuest).OSFullName}},
@{N="Notes";E={($_ | Get-VM Select-Object -Property Name,Notes).Name}},
@{N="Cluster";E={($_ | Get-Cluster).Name}}| Export-Csv -NoTypeInformation -Path C:\Excel_Reports\All_VM_Info.csv
Disconnect-VIServer -server $VC1 -Force -Confirm:$false

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You need to replace the line

@{N="Notes";E={($_ | Get-VM Select-Object -Property Name,Notes).Name}},


with

Notes,


With the Get-VM cmdlet you already got VirtualMachine objects that contain the Notes property. So you don't need a calculated property for the Notes.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

Brilliant. Works great.

Thanks!

0 Kudos