Sorting bits into bytes...

Exporting vCenter Roles and Permissions with PowerShell

## Simplify vCenter Role and Permission Management with PowerShell

In the world of IT infrastructure, managing virtual environments efficiently is crucial. vCenter, VMware’s management platform, plays a vital role in this. One key aspect of vCenter management is handling roles and permissions, ensuring the right people have the right access. Today, we’ll delve into a handy PowerShell script, vCenterRolesAndPermissions (VRAR), which simplifies this task by exporting vCenter inventory details along with their roles and permissions.

The VRAR script is a powerful tool for vCenter administrators, simplifying the process of managing and reviewing roles and permissions within their virtual environments. By exporting this information into a CSV file, it allows for easier auditing, reporting, and compliance checks. Whether you’re a seasoned admin or new to vCenter, this script can help streamline your role and permission management tasks.

Feel free to reach out to me for any queries or further information. Happy scripting!

 

<#
.SYNOPSIS
Script: vCenterRolesAndPermissions (VRAR)
Version: 1.0 (Tested)
Date: Aug 6, 2024
Author: Kabir Ali - info@kablog.nl
Description: This script will create an export of the vCenter inventory along with the roles and permissions of those objects.
Version history:
1.0 - Aug 6 - Initial version

.EXAMPLE
.\VRAR.ps1 -vCenterServer "vcenter01.local.domain" -vCentersUsername "Admin" -vCenterPassword "VMware1!"
#>

Param (
    [Parameter(Mandatory = $true)][string]$vCenterServer,
    [Parameter(Mandatory = $true)][string]$vCenterUsername,
    [Parameter(Mandatory = $true)][string]$vCenterPassword
)

# Zorg ervoor dat je de VMware.PowerCLI-module hebt geïnstalleerd en geïmporteerd
# Install-Module -Name VMware.PowerCLI -Scope CurrentUser
# Import-Module VMware.PowerCLI

# Verbind met je vCenter-server
try {
    Connect-VIServer -Server $vCenterServer -User $vCenterUsername -Password $vCenterPassword -ErrorAction Stop
} Catch {
    Write-Warning -Message "Error: Kan geen verbinding maken met vCenter: $($vCenterServer). Script gestopt."
    Break
}
  

# Haal alle rollen (groepen) op
$allRoles = Get-VIRole

# Haal alle entiteiten op waarvoor we de permissies willen controleren
$entities = Get-Inventory

# Initialiseer een array voor het opslaan van de resultaten
$results = @()

# Loop door elke entiteit
foreach ($entity in $entities) {
    # Haal de permissies voor deze entiteit op
    $permissions = Get-VIPermission -Entity $entity
    
    # Loop door elke permissie
    foreach ($permission in $permissions) {
        # Controleer of de rol voorkomt in de permissie
        foreach ($role in $allRoles) {
            if ($permission.Role -eq $role) {
                # Haal de privileges op voor deze rol en zet ze om naar een string
                $privileges = ($role | Get-VIPrivilege) -join ", "
                
                # Voeg het resultaat toe aan de array
                $results += [PSCustomObject]@{
                    RoleName    = $role.Name
                    EntityName  = $entity.Name
                    EntityType  = $entity.GetType().Name
                    Principal   = $permission.Principal
                    Permissions = $privileges
                }
            }
        }
    }
}

# Exporteer de resultaten naar een CSV-bestand
$results | Export-Csv -Path "vCenter_Groups_Permissions.csv" -NoTypeInformation -Append

# Ontkoppel van de vCenter-server
Disconnect-VIServer -Server $vCenterServer -Confirm:$false

 

Leave a Reply