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
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.
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
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
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.
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
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
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.
Brilliant. Works great.
Thanks!