Hash Table not working for one vCenter

This post was originally published on this site

HI All,


I’ve the below script that works across a range of vCenters, except for one.

All vCenters are VCSA


I realize this probably isn’t a PowerCLI question but, don’t understand why the script will not work when run on this one VCSA


foreach ($line in $targetList){

    Write-Progress -Activity “Collecting details on provided VMs” -Status “Working on $line” -PercentComplete (($i*100)/$count.Lines)

    try {

        write-host “inside TRY, working on $line”

        $script:target = Get-VM $line -ErrorAction SilentlyContinue

        $powerState = $script:target.PowerState

        $ip = $script:target.guest.IPAddress[0]

        $memory = $script:target.memoryGB

        $hddSize = [math]::Round(((Get-HardDisk -VM $script:target).CapacityGB | Measure-Object -Sum).Sum)

        $vraManaged = $script:target.customFields.Item(“vrmManagedMachine”)

        $vraOwner = $script:target.customFields.Item(“VRM Owner”)

        $script:vmProperty = [ordered] @{

            ‘vCenter’ = $script:target.Uid.Split(‘@’)[1].Split(‘:’)[0]

            ‘Cluster’ = $script:target.VMHost.Parent.Name

            ‘VM Name’ = $script:target.Name

            ‘IP Address’ = $ip

            ‘PowerState’ = $powerState

            ‘Memory (GB)’ = $memory

            ‘Disk Capacity (GB)’ = $hddSize

            ‘Attribute: vRA Managed’ = if ($vraManaged) {“True”} else {“False”}

            ‘Attribute: vRA Owner’ = $vraOwner



        $script:vm_Found_YES += New-Object -TypeName psobject -Property $Script:vmProperty



    catch {

        Write-Host “inside CATCH working on $line”

        $script:notFound = [ordered] @{

            ‘VM Name’ = $line

            ‘VM Exists’ = “NO”


        Write-Host -ForegroundColor Red “$line does not exist on the vCenter being searched”

        $vm_Found_NO += New-Object -TypeName psobject -Property $script:notFound




$script:vm_Found_YES | Sort-Object -Property ‘VM Name’ | Export-Excel -Path $vm_Found_YES_ReportPath -AutoFilter -AutoSize -TableStyle Light2 -Show


if ($vm_Found_NO){

    $vm_Found_NO | Export-Excel -Path $vm_Found_NO_ReportPath -AutoFilter -AutoSize -TableStyle Light3 -Show




I can confirm that the VM’s in the $targetList do exist on this particular vCenter.

When outputting the contents of the variables, they are all populated except for the $script:vmProperty hashtable, which is blank.

For the output of this script, i would expect the $script:vm_Found_YES to ve exported to Excel and, have all the relevant fields populated. Instead, it opens as an empty spreadsheet.


the $vm_Found_NO on the other hand is populated with the VM Names. Even though these VM’s do exist in this VCSA.


As i’ve said, this script works as expected across a lot of other 6.5 VCSA’s. Just one is giving this issue and i can’t figure it out.

I thought it may be the Inventory Service on the VCSA but, all variables except the Hash table are populated.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.