Change ExtensionAttribute15 with csv

Hi all.
i have a little problem and i am a newbee in powershell :smiley:
i have a csv with the column “sAMAccountName” and the Column “extensionAttribute15”
with this file i want to get the users from the csv and set the informations from Column “Batch” to the extensionAttribute15.

sAMAccountName Batch
User1 160576

Hier my script.

$attribute = Import-Csv -path “C:\Temp\AttibuteUniflow.csv” -Delimiter “;”

Foreach ($user in $attribute)

get-aduser $attribute.sAMAccountName | Set-ADUser - $attribute.Batch -add @{extensionAttribute15 = $attribute.Batch}


The error i get:
Set-ADUser : A positional parameter cannot be found that accepts argument ‘160576’.
At C:\Temp\uniflow.ps1:6 char:40

  • … countName | Set-ADUser - $attribute.Batch -add @{extensionAttribute …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidArgument: (:slight_smile: [Set-ADUser], ParameterBindingE
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirector

Many thanks for your Help :wink:

Set-ADUser is expecting an Identity at position 0, but you are trying to pass $attribute.Batch. Since you already have the samaccountName you don’t need to call Get-ADUser.

Set-ADUser -Identity $user.sAMAccountName -add @{extensionAttribute15 = $user.Batch}

Welcome to the forum. :wave:t3:

please When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in 1 <---- Click :point_up_2:t4: :wink:

@neemobeer is on the right path but missed one little detail though … :wink:

You are using $attribute for the list you’re CSV data is in - what’s actually a bad idea to call it $attribute - and then you use $user for each element in it. Then in your loop you use the variable name for your list instead of the single variable. :wink:

$UserList = Import-Csv -path 'C:\Temp\AttibuteUniflow.csv' -Delimiter ';'

Foreach ($User in $UserList){
    Set-ADUser -Identity $User.sAMAccountName -add @{extensionUserList15 = $User.Batch}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.