See if the code below works?
# Output CSV file
$outputCsv = "VMFolder_vsphereLocal_Groups.csv"
# Array to hold results
$results = @()
# Get all VM folders recursively
$folders = Get-Folder -Type VM | Sort-Object Name
foreach ($folder in $folders) {
$folderPath = $folder.ExtensionData.Name
$parent = $folder.Parent
# Build full path
while ($parent -ne $null -and $parent.Name -ne "vm") {
$folderPath = "$($parent.Name)/$folderPath"
$parent = $parent.Parent
}
$folderPath = "vm/$folderPath"
# Get permissions for the folder
$permissions = Get-VIPermission -Entity $folder | Where-Object {
$_.Principal -like "*@vsphere.local" -and $_.IsGroup
}
foreach ($perm in $permissions) {
$groupName = $perm.Principal
# Get members of the group
try {
$group = Get-VMHostAccount -Group -Id $groupName -ErrorAction Stop
$members = ($group | Get-VMHostAccount -Member).Id -join "; "
} catch {
$members = "Unable to retrieve members"
}
$results += [PSCustomObject]@{
FolderPath = $folderPath
GroupName = $groupName
Role = $perm.Role
Propagate = $perm.Propagate
Members = $members
}
}
}
# Export to CSV
$results | Export-Csv -Path $outputCsv -NoTypeInformation -Encoding UTF8
Write-Host "CSV file saved to: $outputCsv"
Original Message:
Sent: Jun 18, 2025 01:00 AM
From: the1960
Subject: Manage user and groups of center 8.0
Hi all,
I need a script that displays and write in csv-file all VM folders (with paths) along with the groups and their corresponding members. This is only required for vsphere.local groups. AD connectivity is irrelevant.
Or how do you manage your users/groups?