【问题标题】:Trying to bulk update phone number in AD via Powershell尝试通过 Powershell 批量更新 AD 中的电话号码
【发布时间】:2014-05-17 02:46:38
【问题描述】:

我正在尝试通过 Powershell 脚本从导出和更新的 CSV 文件中导入和替换 AD 中的电话号码。

我使用的脚本是:

Import-Csv C:\test2.csv | ForEach-Object {
  Set-ADUser -Identity $_.samAccountName -Replace @{
    telephoneNumber=$_.OfficePhone;HomePhone=$_.HomePhone;MobilePhone=$_.MobilePhone}
}

CSV 的格式为:

samaccountname,OfficePhone,HomePhone,MobilePhone
Username,Phone no, phone no, phone no

尝试导入时出现错误:

C:\Users\account\Desktop\ps2.ps1:2 char:13
+   Set-ADUser <<<<  -Identity $_.samAccountName -Replace @{telephoneNumber=$_.OfficePhone;HomePhone=$_.HomePhone;Mobil
ePhone=$_.MobilePhone}
    + CategoryInfo          : InvalidOperation: (1305:ADUser) [Set-ADUser], ADInvalidOperationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

有人知道吗?

【问题讨论】:

    标签: powershell csv active-directory


    【解决方案1】:

    我只看到 -Replace 运算符要求您使用 LDAP 显示字段并且 MobilePhone 不存在。请改用移动设备。

    查看this site,查看列出所有 LDAP 用户属性的好表。或者您可以使用MSDN page,它的用处要小得多,因为除非您单击每个字段的链接,否则它不会显示 LDAP 显示名称。

    【讨论】:

    • 他有 2 个MobilePhones:只是为了澄清,就像 Karan 提供的一样 - 第一个必须是 Mobile。但是 +1 用于提供指向属性映射表的链接。
    【解决方案2】:

    效果很好。

    Import-Csv E:\test.csv | ForEach-Object {Set-ADUser -Identity $_.samAccountName -Replace @{Mobile=$_.MobilePhone}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 2018-05-17
      相关资源
      最近更新 更多