代码之家  ›  专栏  ›  技术社区  ›  Travis

尝试批量编辑成本中心(costCenter)属性时发生Windows PowerShell错误

  •  0
  • Travis  · 技术社区  · 4 月前

    我正在尝试更改“costCenter”属性。我注意到架构中的描述最初是“成本中心”。我想也许空间是个问题,所以把它改成了“成本中心”。属性名称为“costCenter”。我不知道我在这里错过了什么。任何帮助感谢。

    下面是脚本:

    导入模块ActiveDirectory

    $Attribcsv=导入csv“C:\Temp\ADUsers_BulkEdit.csv” ForEach($Attribcsv中的$User)

    { 获取ADUser-标识$User.samAccountName|设置ADUser-“成本中心”$($User.costCenter) }

    不断出现的错误如下:

    Set ADUser:找不到接受参数“MM”的位置参数。 第5行字符:45

    • …$User.samAccountName|设置ADUser-“成本中心”$($User.costCenter)
    •                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      • 类别信息:无效参数:(:)[Set ADUser],参数绑定异常
      • FullyQualifiedErrorId:未找到位置参数,Microsoft。活动目录。管理。命令。设置AD用户
    
    
    I've run the script with different attributes--for testing purposes--successfully:
    1. Using the "description" attribute under the General tab in AD
    2. Using the "comment" attribute under the Attribute Editor tab in AD
    
    Both of those worked successfully
    
    2 回复  |  直到 4 月前
        1
  •  0
  •   Santiago Squarzon    4 月前

    添加/替换/删除自定义属性或不存在的属性 Parameter 对于您必须使用的cmdlet -Add / -Replace / -Remove .

    因此,假设您想更改属性值,并且该属性名称为 Cost-Center 然后你可以使用 -更换 :

    $Attribcsv = Import-Csv 'C:\Temp\ADUsers_BulkEdit.csv'
    foreach ($User in $Attribcsv) {
        Get-ADUser -Identity $User.samAccountName |
            Set-ADUser -Replace @{ 'Cost-Center' = $User.costCenter }
    }
    
        2
  •  0
  •   Travis    4 月前

    谢谢圣地亚哥。以下是我使用的确切语法: 注意:我只是为像我这样的Powershell新手发帖。我不知道这个确切的语法是否与Santiago给我的语法不同。我打赌它们都有效。

    Import-Module Activedirectory
    

    $Attribcsv=导入csv“C:\Temp\ADUsers_BulkEdit.csv”

    ForEach($Attribcsv中的$User)

    {

    获取ADUser-标识$User.samAccountName|设置ADUser-替换@{costCenter=$($User.costCenter)}

    }