Solved

PowerShell script passing distinguishedName

Posted on 2014-09-15
3
335 Views
Last Modified: 2014-09-18
I want to run this script to set an AD attribute:

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

$ad.msExchDelegateListLink.Clear();
$ad.SetInfo();

$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:
	$ad.msExchDelegateListLink.Add($group_name)

	$ad.SetInfo();
}

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
Chris
0
Comment
Question by:mbwjk
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40322794
Change line 6 to
$list = Get-ADGroupMember "SomeGroup" -recursive | Select -expand distinguishedName;

Open in new window

0
 

Author Comment

by:mbwjk
ID: 40331345
Perfect - thanks a lot!

Best regards
Chris
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40331352
You are welcome!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question