VMware Cloud Community
dmetcalfe92
Enthusiast
Enthusiast

Extract ImageProfile using PowerCLI with readonly account

Hi guys,

I use PowerCLI a lot, primarily to export information on our virtual estate & import into a SQL database for further querying.

I want to audit the ImageProfile field across our virtual estate, however I'm struggling to find a way of getting this value from the hosts using PowerCLI.

I am having to execute Get-ESXCLI which requires a lot more permission than my readonly user account has.

This is what I've knocked up, however I can't run with this using a read-only user account:

$Data = Get-VMHost | ForEach {

     $esxcli = Get-EsxCli -VMhost $_

     $_ | Select    Name,

                    @{Expression={$_.Client.ServerUri.Split("@") | Select -last 1};Label="vCenter"},

                    @{Expression={$esxcli.software.profile.get().Name};Label="ImageProfile"}

}

Is there any other method of extracting this information?

Thanks

0 Kudos
1 Reply
lamw
Community Manager
Community Manager

Responded on Reddit thread, but here's the reply:

If you just want to simply just want to retrieve the Image Profile used by an ESXi host, you don't need to use ESXCLI, there's a native vSphere API that you can use which only requires RO-role

See HostImageConfigGetProfile() method https://code.vmware.com/apis/196/vsphere#/doc/vim.host.ImageConfigManager.html#queryHostImageProfile

If you need to get details of the Image Profile, you'll need a bit more privs as defined by the API, but here's an PCLI example of using one of the new APIs https://github.com/lamw/vghetto-scripts/blob/master/powershell/ESXInstalledVIBs.ps1 just to give you an example of how to call into this interface

The other nice benefit of using this over ESXCLI, is that you don't need direct ESXi host access and you can centrally manage this from vCenter Server which is always a plus for me Smiley Happy

0 Kudos