I'm trying to change the "costCenter" attribute. I noticed in the Schema the description was originally "Cost Center". I thought maybe the space was an issue so changed it to "Cost-Center". The attribute name is "costCenter". I have no idea what I'm missing here. Any help appreciated.
Below is the script:
Import-Module ActiveDirectory
$Attribcsv=Import-csv "C:\Temp\ADUsers_BulkEdit.csv"
ForEach ($User in $Attribcsv)
{
Get-ADUser -Identity $User.samAccountName | set-ADUser -"Cost-Center" $($User.costCenter)
}
The error that keeps spitting out is below:
Set-ADUser : A positional parameter cannot be found that accepts argument 'MM'.
At line:5 char:45
+ ... $User.samAccountName | set-ADUser -"Cost-Center" $($User.costCenter)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
I've run the script with different attributes--for testing purposes--successfully:
Both of those worked successfully
To add / replace / remove custom attributes or those attributes that do not exist as a Parameter for that cmdlet you have to use -Add
/ -Replace
/ -Remove
.
So assuming you want to change the attribute value, and that attribute name is Cost-Center
then you can use -Replace
:
$Attribcsv = Import-Csv 'C:\Temp\ADUsers_BulkEdit.csv'
foreach ($User in $Attribcsv) {
Get-ADUser -Identity $User.samAccountName |
Set-ADUser -Replace @{ 'Cost-Center' = $User.costCenter }
}