WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Quick Tip - Audit vCenter Server Role & Permission Usage

Quick Tip - Audit vCenter Server Role & Permission Usage

02.26.2025 by William Lam // 2 Comments

vCenter Server ships out of the box a number of system and custom roles, which can be used or users can create their own custom roles containing the required privileges. If you wanted to understand which roles are actively being used, the following PowerCLI snippet can help provide insights to roles that have been assigned. Furthermore, the script will also output to a file, that contains all he privileges defined for the vCenter Roles that are in active use.

$roles = Get-VIRole
$permissions = Get-VIPermission

$results = @{}
foreach ($permission in $permissions) {
    $role = $permission.Role
    if($results.ContainsKey($role)) {
        $results[$role]+=1
    } else {
        $results[$role]=1
    }
}

Write-Host "`nTotal Roles: $($roles.count)"
Write-Host "Total Roles Used: $($results.count)"
Write-Host "Role Usage:"

$results.GetEnumerator() | Sort-Object -Property Value -Descending

$outfile = "used-roles.txt"
foreach ($key in $results.keys) {
    $role = Get-VIRole $key
    if(!$role.IsSystem) {
        $key | Out-File -Append -LiteralPath $outfile
        "=========================================================" | Out-File -Append -FilePath $outfile
        $role.ExtensionData.Privilege | Out-File -Append -LiteralPath $outfile
        "" | Out-File -Append -LiteralPath $outfile
    }
}

Here is an example output of running the script:


Here is an example output from used-roles.txt file that is generated, which contains the list of privileges for each role that is in use:

More from my site

  • vCenter Identity Federation with Authelia
  • vCenter Server Identity Federation with Kanidm
  • Quick Tip - Retrieving vCenter Identity Federation Secret Token Expiry
  • vCenter Server Identity Federation with Zitadel
  • vCenter Server Identity Federation with Pocket ID

Categories // Automation, PowerCLI, vSphere Tags // permission, vCenter Server

Comments

  1. *protectedPaul Bardo says

    04/03/2025 at 12:46 pm

    William,
    Since you are talking about vCenter permissions again, as far as I know your 2017 post on the subject is still the only way I have found to add/remove Global Permissions with something approaching PowerCLI

    But I notice that the vCenter GUI when displaying the object-level permissions will show that a permission is 'defined in' Global Permission (if it is), but I can't figure out how to pull that information out of Get-VIPermission. Is it available there? Or is there a way to modify your GlobalPermissions.ps1 code from 2017 to do something like a Get-GlobalPermission instead of just New- and Remove-

    Or I am missing something obvious?

    Reply
    • William Lam says

      04/07/2025 at 8:41 am

      The APIs for vSphere Global Permissions are currently priviate, hence the need to rely on vSphere MOB hack to access its functions. See https://williamlam.com/2025/04/quick-tip-listing-vsphere-global-permissions-using-powershell.html for your answer 🙂

      Reply

Thanks for the comment!Cancel reply

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

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • VMware Flings is now available in Free Downloads of Broadcom Support Portal (BSP) 05/19/2025
  • VMUG Connect 2025 - Minimal VMware Cloud Foundation (VCF) 5.x in a Box  05/15/2025
  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...