VMware Cloud Community
awestfall
Contributor
Contributor

Problems With New PSObject For Audit Report

   Hi All,

I'm attempting to write a script that will gather information about the VMs in a vCenter environment, namely Name, vCPUs, Memory, Operating System, and, the kicker, disk information (specifically, capacity and free space).  The script is attached, with many parts borrowed.

Now, typically, I would use the New-Object -TypeName PSObject -Property @{ }, but I couldn't find any way to use any sort of logic (i.e. a ForEach loop within this), and this is required.  For some reason, the columns for vCPU, MemoryGB, and GuestOS are blank.  Also, it's transposing the two disks, swapping the C:\ and E:\ drives (attached as well).  The Name works, but has been blanked out to protect the innocent.

Thank you, in advance, for any help!

Tags (2)
Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

You're mixing 2 different objects.

With Get-View you get VirtualMachine objects (a View object), but some of your Add-Member lines are referring to properties of the VirtualMachine object (a PowerCLI object) as it is returned by Get-VM.

Some of these properties, like for example NumCpu doesn't exist, at level 1, in the View object.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos