Search code examples
powershellexchange-server

DistributionGroup managedBy show only the Names not OU


When I use this script:

Get-DistributionGroup -Filter {Displayname -like "DG_Group"}|Select managedBy|ft

I get the OU together with the Name, Output:

{work.place/EUR/User/Surname, FirstName}

But I only want the Name, example Output:

{Surname, FirstName}


Solution

  • If all you want returned is the last part of whatever is in the ManagedBy (multivalue) property, try this (untested):

    Get-DistributionGroup -Filter 'Displayname -like "DG_Group"' | 
        Select-Object Name, 
                      @{Name = "ManagedBy"; Expression={($_.ManagedBy | ForEach-Object {$_.Split("/")[-1]})}}