Marco
April 27, 2025, 11:34am
1
Product: PowerShell Universal
Version: 5.4.2
Hi everyone,
I saw that in PowerShell Universal you can use New-UDTable -Data $Data -OnRowExpand
. Unfortunately, I currently can’t find a solution to display all “member of” entries individually in -OnRowExpand
. I only get all entries from “MemberOf” listed one after the other. However, I would like only the names of the groups to be displayed one below the other, if this is possible.
New-UDApp -Content {
$CredAD = $secret:TestUser
$users = get-aduser -filter * -Properties description, displayname, Lastlogon, memberof -Credential $CredAD | Where-Object {$_.name -like "*test"} | select-object -First 1
$Data = foreach($user in $users){
try{
$endUser = $user.Name -replace "test",""
$check = get-aduser -Identity $endUser -Properties company, department -Credential $CredAD
[PSCustomObject]@{
Benutzer = $user.name
Anzeigename = $user.displayname
Beschreibung = $user.description
Aktiviert = if ($User.Enabled -eq $true) { "active" } else { "inactive" }
Anmeldung = if ($User.LastLogon) { ([datetime]::FromFileTime($User.LastLogon)).ToString("dd-MM-yyyy") } else { "Nie" }
EnduserVorhanden = "ja"
Firma = $check.company
Abteilung = $check.department
Berechtigung = $user.memberof
}
} catch {
[PSCustomObject]@{
Benutzer = $user.name
Anzeigename = $user.displayname
Beschreibung = $user.description
Aktiviert = if ($User.Enabled -eq $true) { "active" } else { "inactive" }
Anmeldung = if ($User.LastLogon) { ([datetime]::FromFileTime($User.LastLogon)).ToString("dd-MM-yyyy") } else { "Nie" }
EnduserVorhanden = "nein"
Berechtigung = $user.memberof
}
}
}
New-UDTable -Data $Data -OnRowExpand {
new-UDTypography -Text $eventdata.Berechtigung
} -Columns @(
New-UDTableColumn -Title 'Benutzer' -Property 'Benutzer' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Anzeigename' -Property 'Anzeigename' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Beschreibung' -Property 'Beschreibung' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Aktiviert' -Property 'Aktiviert' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Anmeldung' -Property 'Anmeldung' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Enduser vorhanden' -Property 'EnduserVorhanden' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Firma' -Property 'Firma' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Abteilung' -Property 'Abteilung' -ShowSort -IncludeInSearch -IncludeInExport
) -Dense -Export -PageSize 100 -ShowSearch -ShowPagination -ShowSort -ExportOption 'XLSX'
}
As always, I am grateful for your help.
Marco
April 27, 2025, 7:37pm
2
Hey again,
i ve found two solutions for the moment:
New-UDTable -Data $Data -OnRowExpand {
$groups = $eventdata.Berechtigung | sort-Object
$groups | ForEach-Object {
#New-UDListItem -Label $_.Replace("CN=", "").Split(",")[0]
new-UDAlert -Text $_.replace("CN=","").split(",")[0]
}
These two ways work definetly. To bad, the include search doesnt work on -OnRowExpand
@Marco i threw this together as a quick test. I’m not using AD in my dev env, so I faked up some data and used that instead of Get-ADUsers. I think you were close to getting it. Hope this helps.
function Get-TestADUsers {
$testUsers = @(
[PSCustomObject]@{
Name = "John Doe"
SamAccountName = "jdoe"
Enabled = $true
MemberOf = @(
"CN=Domain Users,CN=Users,DC=contoso,DC=com",
"CN=Sales Team,CN=Users,DC=contoso,DC=com"
)
},
[PSCustomObject]@{
Name = "Jane Smith"
SamAccountName = "jsmith"
Enabled = $true
MemberOf = @(
"CN=Domain Users,CN=Users,DC=contoso,DC=com",
"CN=IT Team,CN=Users,DC=contoso,DC=com",
"CN=Administrators,CN=Users,DC=contoso,DC=com"
)
},
[PSCustomObject]@{
Name = "Bob Wilson"
SamAccountName = "bwilson"
Enabled = $false
MemberOf = @(
"CN=Domain Users,CN=Users,DC=contoso,DC=com"
)
}
)
return $testUsers
}
New-UDDashboard -Title "AD Users" -Content {
New-UDDynamic -Id "userTable" -Content {
$users = Get-TestADUsers
New-UDTable -Id "userTable" -Data $users -Columns @(
New-UDTableColumn -Property "Name" -Title "Display Name"
New-UDTableColumn -Property "SamAccountName" -Title "Username"
New-UDTableColumn -Property "Enabled" -Title "Account Status"
) -ShowPagination -Dense -OnRowExpand {
$user = $EventData
$groups = $user.MemberOf | ForEach-Object {
($_ -split ",")[0] -replace "CN=", ""
}
New-UDTypography -Text "Group Memberships:" -Variant h5 -Style @{ fontWeight = "bold"; marginBottom = "8px" }
New-UDStack -Content {
foreach ($group in $groups) {
New-UDTypography -Text "$group" -Variant body2
}
} -Direction 'column'
}
}
}
Marco
April 29, 2025, 6:22am
4
@AMurphy-Leavitt thank you for your support. I have now found a good way to write the data neatly in a structured manner and have also made some enhancements to the output. Thank you for your time.
@Marco glad it works and that you could improve it! Can you share a version of your final product for future generations? The more we share the more we all learn.
Marco
April 29, 2025, 6:05pm
6
Hi @AMurphy-Leavitt of course, I’m happy to share my experience with the community. My goal was to evaluate users who are related to “Test.” For these users, I created a table using a PSCustomObject, containing all the information that was relevant to me. I had already described my issue above, which was that the “memberof” attribute was not properly listed one below the other. After I managed to resolve this, I also wanted to check which users are members of a selected AD group. If any of the users were in the group, I wanted to exclude them visually by marking them with a color and making this distinction clearly visible in the evaluation.
function Report_Testuser {
# Credentials
$CredAD = $secret:Testuser
# Suche alle Testuser aus der AD
$users = get-aduser -filter * -Properties description, displayname, Lastlogon, memberof -Credential $CredAD | Where-Object {$_.name -like "*Test"}
# Erstellt eine Datensammlung aller Testuser und prüfe, ob ein Enduser existiert
$Data = foreach($user in $users){
try{
$endUser = $user.Name -replace "test",""
$check = get-aduser -Identity $endUser -Properties company, department -Credential $CredAD
[PSCustomObject]@{
Benutzer = $user.name
Anzeigename = $user.displayname
Beschreibung = $user.description
Aktiviert = if ($User.Enabled -eq $true) { "aktiviert" } else { "deaktiviert" }
Anmeldung = if ($User.LastLogon) { ([datetime]::FromFileTime($User.LastLogon)).ToString("dd-MM-yyyy") } else { "Nie" }
EnduserVorhanden = "ja"
Firma = $check.company
Abteilung = $check.department
Berechtigung = $user.memberof
}
} catch {
[PSCustomObject]@{
Benutzer = $user.name
Anzeigename = $user.displayname
Beschreibung = $user.description
Aktiviert = if ($User.Enabled -eq $true) { "aktiviert" } else { "deaktiviert" }
Anmeldung = if ($User.LastLogon) { ([datetime]::FromFileTime($User.LastLogon)).ToString("dd-MM-yyyy") } else { "Nie" }
EnduserVorhanden = "nein"
Berechtigung = $user.memberof
}
}
}
# Erstellt eine Tabelle als Übersicht und prüft, ob eine ausgewählte AD-Gruppe als Ausnahme gefunden wird
New-UDTable -Data $Data -OnRowExpand {
$groups = $eventdata.Berechtigung | sort-Object
if($groups){
$groups | ForEach-Object {
$groupname = $_.Replace("CN=", "").Split(",")[0]
if($groupname -like "*AD_Testgroup*"){
New-UDListItem -Label $groupname -Icon (new-UDIcon -Icon check -Size lg -Color '#f2b632')
} else {
New-UDListItem -Label $groupname -Icon (new-UDIcon -Icon check -Size lg -Color '#b5b5b7')
}
#new-UDAlert -Text $_.replace("CN=","").split(",")[0]
}
} else {
New-UDListItem -Label "keine Berechtigungen vorhanden" -Icon (new-UDIcon -Icon check -Size lg -Color '#b5b5b7')
}
} -Columns @(
New-UDTableColumn -Title 'Benutzer' -Property 'Benutzer' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Anzeigename' -Property 'Anzeigename' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Beschreibung' -Property 'Beschreibung' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Aktiviert' -Property 'Aktiviert' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Anmeldung' -Property 'Anmeldung' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Enduser vorhanden' -Property 'EnduserVorhanden' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Firma' -Property 'Firma' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Abteilung' -Property 'Abteilung' -ShowSort -IncludeInSearch -IncludeInExport
New-UDTableColumn -Title 'Status' -Property 'Status' -ShowSort -IncludeInSearch -IncludeInExport -OnRender {
$gruppenAusnahme = $EventData.Berechtigung
if($gruppenAusnahme){
if ($gruppenAusnahme -like "*AD_Testgroup*"){
new-UDTypography -Text "Prüfen" -Style @{color = '#f2b632'; 'font-weight' = 'bold'}
} else {
new-UDTypography -Text "OK" -Style @{color = '#b5b5b7'; 'font-weight' = 'bold'}
}
} else {
new-UDTypography -Text "Achtung" -Style @{color = '#f28532'; 'font-weight' = 'bold'}
}
}
) -Dense -Export -PageSize 100 -ShowSearch -ShowPagination -ShowSort -ExportOption 'XLSX'
}
1 Like