I have a script that is connecting to a Novell eDirectory (yes, I know, eDirectory) in order to retrieve user information.
I am using System.DirectoryServices.DirectoryEntry and System.DirectoryServices.DirectorySearcher. The searching is working well.
One of the fields I am retrieving from Novell eDirectory is the user’s group membership. I am able get the membership, format the entries the way I want without issue. The problem I am having is when I am displaying the information.
I am using the following code:
Add-Type -AssemblyName System.DirectoryServices
#Setup eDirectory Connection Variables
$eDirPath = “LDAP://SomeNovellServer/o=SomeOrg”
$eDIrAuthType = ‘None’
#Establish eDirectory Connection and Enumerate
$Root = New-Object System.DirectoryServices.DirectoryEntry -argumentlist $eDirPath,$null,$null,$eDirAuthType
$Query = New-Object System.DirectoryServices.DirectorySearcher
$Query.SearchRoot = $Root
$Query.Filter = “(uid=miked)”
$SearchResults = $Query.FindAll()
$prop = [pscustomobject]@{
“Name” = $SearchResults.Properties.fullname
“NovellGroupMembership” = ($SearchResults.Properties.GroupMembership.ForEach({((($_ -split “,”) -replace “(ou=)|(o=)”,“.”) -replace “cn=”).ToUpper() -join “”}) | Sort-Object)
}
Write-Output -InputObject $prop
Output looks like this
Name NovellGroupMembership
Mike Delaney {GROUP1.SOMEORG, GROUP2.SOMEORG, GROUP3.SOMEORG…}
This works…but the NovellGroupMembership property when Write-Output sends it to the screen, it is enclosed in in { }. I did pipe $prop to the Get-Member cmdlet, and it returns that NovellGroupMembership is a NoteProperty whose definition is Object NovellGroupMembership=System.Object
Ultimately, I could then pipe it to Select-Object -ExpandProperty NovellGroupMembership, but I would like it to display like this
Name NovellGroupMembership
Mike Delaney GROUP1.SOMEORG
GROUP2.SOMEORG
GROUP3.SOMEORG
GROUP4.SOMEORG
GROUP5.SOMEORG
Is that possible?
Windows 7 SP1, PowerShell 5.0.10586.117