PowerCLI

  • 1.  Unable to get VM Info based on particular folders

    Posted Nov 11, 2024 05:24 AM

    Hi,

    I am trying to get the VM information from multiple vCenters, where few folders are not present on few vCenters

    for example, HR folder exists on all vcenters but If the HR folders has 10 VMs in vCenter 1, it gathers and output in output file but same HR folder on vcenter 2 has more than 10 VMs, it would gather only 10 VM info. It is not gathering for all VMs in vcenter2

    Please help!!!

    $vmNotesInfo = Foreach ($vc in $global:DefaultVIServers)
    {
    Get-Folder "HR", "DevOps", "Release-1" -Server $vc | Get-VM -Server $vc | Select @{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
    @{N="Folder"; E={$_.Folder.Name}},
    @{N='VM Name';E={$_.Name}},
    @{N="IP Address";E={($_.guest.IPAddress[0])}},
    @{N="VM PowerState";E={($_.PowerState)}},
    @{N="Operating System"; E={@($_.guest.OSFullName)}},
    @{N="CPU Count";E={@($_.NumCPU)}},
    @{N="MemoryInGB";E={[math]::round($_.MemoryGB)}},
    @{N="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
    @{N="Notes";E={@($_.Notes)}}
    }
    $vmNotesInfo | Export-Excel -Path $reportlocation1 -AutoFilter -AutoSize -WorksheetName All_VMs_Info



  • 2.  RE: Unable to get VM Info based on particular folders

    Posted Nov 11, 2024 05:30 AM

    Try like this

    $vmNotesInfo = @()
    Foreach ($vc in $global:DefaultVIServers)
    {
       $vmNotesInfo += Get-Folder "HR", "DevOps", "Release-1" -Server $vc | Get-VM -Server $vc | Select @{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}},
          @{N="Folder"; E={$_.Folder.Name}},
          @{N='VM Name';E={$_.Name}},
          @{N="IP Address";E={($_.guest.IPAddress[0])}},
          @{N="VM PowerState";E={($_.PowerState)}},
          @{N="Operating System"; E={@($_.guest.OSFullName)}},
          @{N="CPU Count";E={@($_.NumCPU)}},
          @{N="MemoryInGB";E={[math]::round($_.MemoryGB)}},
          @{N="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
          @{N="Notes";E={@($_.Notes)}}
    }
    
    $vmNotesInfo | Export-Excel -Path $reportlocation1 -AutoFilter -AutoSize -WorksheetName All_VMs_Info


    ------------------------------


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


    ------------------------------



  • 3.  RE: Unable to get VM Info based on particular folders

    Posted Nov 11, 2024 12:37 PM

    LucD,

    I am able to get the information from all the folder except HR. HR folder 126 VMs but it is gathering only 67 VM information. There are no subfolders in HR.

    But If execute Get-Folder HR | Get-VM command, I am able to get all 126 VMs list but from above script is fetching only 67 VMs info




  • 4.  RE: Unable to get VM Info based on particular folders
    Best Answer

    Posted Nov 11, 2024 02:48 PM

    "HR folder 126 VMs but it is gathering only 67 VMHR folder 126 VMs but it is gathering only 67 VM"

    Do I understand correctly that you do get a partial list for the VMs in the HR folder?

    Did you try leaving out the AutoFilter switch on the Export-Excel cmdlet?



    ------------------------------


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


    ------------------------------



  • 5.  RE: Unable to get VM Info based on particular folders

    Posted Nov 13, 2024 04:59 AM

    That worked LucD. Not sure, why it was not gathering with autofilter option all of a sudden?




  • 6.  RE: Unable to get VM Info based on particular folders

    Posted Nov 13, 2024 04:59 AM

    There seems to have been a bug with the AutoFilter switch.



    ------------------------------


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


    ------------------------------