2

I have an online learning management system with most of its data in sql server but its page structure and contents in an AD LDS instance. I have a few classes which have already been set up with 50 pages called "Unused Portfolio 01" through "Unused Portfolio 50". These are their displaynames. Their CNs are "Portfolio 01" through "Portfolio 50".

I need to change the displaynames to each have a different student's name, in the format "Last, First". I am trying to use Active Directory Module for Windows Powershell. Right now I am on a test server trying to make this work for just a few pages. I can't manage to change more than one displayname at a time.

I can get a list of the objects for these pages:

Get-ADObject -Server localhost:389 -filter 'displayname -like "*Portfolio*" -and cn -like "Portfolio*"' -searchbase 'CN=DMIN2013-LMS 101-02,CN=LMS 101,CN=LMS,CN=Academics,CN=Portal,O=Jenzabar,C=US'

I get the distinguishedname, name, objectclass, and objectguid for all three expected objects and no unexpected objects. Great.

I can change any one object's displayname at a time:

set-adobject -Server localhost:389 -identity "CN=Portfolio 01,CN=DMIN2013-LMS 101-02,CN=LMS 101,CN=LMS,CN=Academics,CN=Portal,O=Jenzabar,C=US" -displayname "testing"

The specified object has its displayname changed to "testing". Awesome.

I'm trying to use this to change all of the displaynames for these three objects to "testing" at once, and obviously I have something wrong because it is not working:

Get-ADObject -Server localhost:389 -filter 'displayname -like "*Portfolio*" -and cn -like "Portfolio*"' -searchbase 'CN=DMIN2013-LMS 101-02,CN=LMS 101,CN=LMS,CN=Academics,CN=Portal,O=Jenzabar,C=US' | foreach-object 'set-adobject -Server localhost:389 -identity $_ -displayname "testing"'

The ultimate goal is that I will have a csv file (which I will have gotten from an sql query from the sql server) containing a "number" column 01 to 50, a "lastname" column, and a "firstname" column, and I will change each page's display name to match ", " for each student, but I'm not at that point yet.

Thanks for any help you can offer.

MasterOfNone
  • 827
  • 1
  • 8
  • 12

2 Answers2

2

Foreach-Object uses a script block and not a string, so use:

something | Foreach-Object {Do something with $_}
ojk
  • 2,502
  • 15
  • 17
  • Thanks ojk. I'm pretty new with Powershell and I'm not able to figure out the syntax you're suggesting I use. For the last part I tried several variations of what I thought might be correct based on your reply. Many of these execute without errors, but the displaynames never change. If you could provide a more explicit example, I would be grateful (and I already am grateful!). – MasterOfNone Oct 24 '14 at 17:39
1

This might be due to the fact that $_ contains an object and not its DN. $_.DistinguishedName. Also what ojk says

Get-ADObject -Server localhost:389 -filter 'displayname -like "*Portfolio*" -and cn -like "Portfolio*"' -searchbase 'CN=DMIN2013-LMS 101-02,CN=LMS 101,CN=LMS,CN=Academics,CN=Portal,O=Jenzabar,C=US' | foreach-object {set-adobject -Server localhost:389 -identity $_.DistinguishedName -displayname "testing"}
Paul
  • 5,524
  • 1
  • 22
  • 39
  • This solved my problem. I was able to set all of the displaynames to "testing" at once. For my final goal, I still have further work to do, but this answered the question I asked. Thank you! – MasterOfNone Oct 24 '14 at 19:18