PowerShell script passing distinguishedName

I want to run this script to set an AD attribute:

$ad = [adsi]"LDAP://CN=\#SomeObject,OU=SomeOU,DC=SomeDC,DC=SomeDC";


$list = Get-ADGroupMember "SomeGroup" -recursive | Select distinguishedName;

foreach ($group_name in $list)
	#this works as expected and returns a distinguishedName
	#write-output $group_name

	#this doesn't work:


Open in new window

It works, when I replace $group_name with a static distinguishedName. Unfortunately it fails in the above version:

Ausnahme beim Aufrufen von "Add" mit 1 Argument(en):  "Unbekannter Fehler
Bei C:\Users\Admin_Knell\test.ps1:11 Zeichen:32
+     $ad.msExchDelegateListLink.Add <<<< ($group_name)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Open in new window

Did I miss something?

Thanks and best regards
Who is Participating?
SubsunConnect With a Mentor Commented:
Change line 6 to
$list = Get-ADGroupMember "SomeGroup" -recursive | Select -expand distinguishedName;

Open in new window

mbwjkAuthor Commented:
Perfect - thanks a lot!

Best regards
You are welcome!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.