Get-ADPrincipalgroupmembership table GroupScope value different to console output

Product: PowerShell Universal
Version: 1.5.6

I`m running a query to return the SamAccountName and GroupScope of the AD groups a user is a member of.

If I output to the console or to a text file, the GroupScope values are returned as Universal, Global or DomainLocal as expected.

If I output to a New-UDTable, the GroupScope values are all numerical (0, 1 or 2) which I understand
are enum values.

How can I ensure that I get the names of the GroupScopes and not enum values in my table?

Cheers

Hi @Badgerface,

The same issue as get-service where the status returns a [system.serviceprocess.servicecontrollerstatus] and not a simple string.

The simple solutions, which should to the trick for your case aswell:

#get the service 
$service = get-service
#check the typename of the property
$service.status | gm

#returns:  TypeName: System.ServiceProcess.ServiceControllerStatus

When you format the data for the UD-Table simply cast the value to the Typename and then to string

[string][System.ServiceProcess.ServiceControllerStatus]4

You can validate that every step works by running convertto-json on it, should show the same data as the UD Table.

1 Like

Hey @BoSen29,

Thanks for taking the time to explain this :slightly_smiling_face: it’s very much appreciated.

I spent some time earlier trying to use your recommendation but couldn’t figure out exactly where to use the casting or how to format it.

I did actually find a fix which works in a Get-Service table so assume it will also work in my Get-ADPrincipalgroupmembership table. I tried in my home lab but for some reason, that is actually returning the GroupScope as strings which is very confusing… I’ll have to wait until I get back to work to test in AD (or sneak upstairs to the office when the missus isn`t looking :wink:)

I don’t want to be “that guy” who says, “yeah its fixed now k thx bai” so here’s what I ended up with for the Get-Service table:

$GetServices = Get-Service | Select-Object Name,DisplayName,@{ Name='Status'; Expression={ $_.Status.ToString() } }

$Rowcount = $GetServices.Count

Show-UDToast -Message $Rowcount

$Columns = @(

New-UDtableColumn -Property Name -Title "Name"
New-UDtableColumn -Property DisplayName -Title "DisplayName"
New-UDtableColumn -Property Status -Title "Status"

)

New-UDTable -Data $GetServices -Columns $Columns -PageSize $Rowcount
1 Like

Awesome!
Appreciate the complete solution, people over at StackOverflow could learn a thing from you!
Fingers crossed that it works on your production dashboard aswell!

1 Like

Just in case anyone stumbles across this post, I can confirm this is now working.