VMware Cloud Community
COS
Expert
Expert

Get-InventoryPlus - Pull CPU and RAM assignment for each VM

I use the Get-InventoryPlus function like below and it used to work....

Get-InventoryPlus | where {$_.Type -eq 'VirtualMachine'} |

ForEach-Object -Process {

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Datastore -Value ((Get-Datastore -VM $_.Name).Name -join '|')

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Network -Value ((Get-VirtualPortGroup -VM $_.Name).Name -join '|') -PassThru

} |

Export-Csv C:\Temp\Test.txt

Now I get this....

Cannot convert the "System.Object[]" value of type "System.Object[]" to type "VMware.Vim.ManagedEntity".

At C:\Temp\GetInventoryPlus-FolderPathDatastorePortgroup.ps1:125 char:11

+           $Object = Get-View -Id $Parent -Property Name,Parent

+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException

    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException

Any ideas?

Thanks

0 Kudos
1 Reply
LucD
Leadership
Leadership

Could it be that you have multiple vSphere Server connections open?

Check what is in $global:DefaultVIServers.

Can you try by using the Server parameter on the call to Get-InventoryPlus?

Get-InventoryPlus -Server $global:DefaultVIServer | where {$_.Type -eq 'VirtualMachine'} |


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

0 Kudos