Page 2 of 2

Re: Calling line in CSV to pipe into powershell argument

Posted: Fri Aug 03, 2018 4:21 pm
by jvierra
Unfortunately your code doesn't make any sense. You aer not using the OU anywhere you are just getting a collection of objects and trying to pass them

Also all you need to do to get users is use "Get-AdUser"

Get-AdUser -Filter * -SearchBase $OU[0].RecipientOU | Set-AdUser -Add @{msExchExtensionCustomAttribute1 = $_.ExchangeDistrictCode }/b]

I suggest starting by doing a tutotial on basic PowerShell instrad of trying to guess at things. Without the basics you will likely copy bad code and try to use it as you seem to have done here.

Here is how to use a collection:

Code: Select all

import-csv c:\temp\book1.csv |
        Get-AdUser -Filter * -SearchBase $_.RecipientOU | 
            Set-AdUser -Add @{msExchExtensionCustomAttribute1 = $_.ExchangeDistrictCode}

Re: Calling line in CSV to pipe into powershell argument

Posted: Sat Aug 04, 2018 9:36 am
by Carpe_diem
WOW thank you for your help

I really appreciate your help and I am here to tell you that the lines in the last post work. running it, made the change on all contacts in the OU based on the value defined behind "msExchExtensionCustomAttribute1" as stated the only thing that does not work is the value added from CSV under this.

I forgot to add to the last post that I made the csv changes you hinted towards and updated the last post with it as well.

Also, I said that I am trying to change Contacts not users so I think Get-ADObject is correct., I also stated that I am trying to only filter out only Groups, Rooms and Contacts. those are the only once I am interested in change the attribute on.

the last script you posted would not incorporate the filters I was looking for ... lters.aspx

All distribution groups (Notes 4, 15)
All contact objects
All contact objects
and rooms

I know that you have way more experience then I in Powershell, however I do find your last comment a bit condescending and don’t think that this is helping moving people along, rather the shutting them down and feeling uncomfortable to ask questions in this forum. So, your last statement (if you felt obligated to say that) should have been in a private message.

However I do see the many post you made and I thank you for all the people you help including me.

feel free to have the moderator delete the entire post.

Carpe Diem

Re: Calling line in CSV to pipe into powershell argument

Posted: Sat Aug 04, 2018 10:50 am
by jvierra
Sorry if you think I was being condescending but the code you posted clearly indicate a complete lack of knowledge of basic PowerShell. Without the fundamentals you will not be able to understand most of the simplest things you need to know to understand how to write code. My statement is a suggestion that would save you a lot of time and confusion.

On simple thing is how to read an error (exception). The exception is telling you something very fundamental. Knowing basic PowerShell would have led you to seeing one of the issues you face with what you have coded.

What we are doing is debugging your code one line at a time. Effectively you are asking us to help you learn the basics one line at time. Forums are not a good place to ask for individual training. It is time consuming and does not provide a good understanding of the process and discipline of coding.

You have a smattering of exposure to coding with PwoerShell. A tutorial or book would move you towards becoming a proficient PowerShell scripter. Why not take the plunge.

There are a number of excellent books that any new user should get and read. Even reading the first 3 or four chapters would be extremely enlightening to anyone with no programming training or experience.

There is also one excellent video tutorial done by the inventor of PwoerShell which is excellent in teaching new people what PowerShell is and how it is used. ... shell-8276

My favorite newest book is: ... rd-edition

It is the most up to date version of the book. THe second edition is available at a huge discount from many sellers and is also an excellent choice but doesn't cover the newest features of WMF 5