Re: Calling line in CSV to pipe into powershell argument
Posted: Fri Aug 03, 2018 4:21 pm
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:
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 |
ForEach-Object{
Get-AdUser -Filter * -SearchBase $_.RecipientOU |
Set-AdUser -Add @{msExchExtensionCustomAttribute1 = $_.ExchangeDistrictCode}
}