【发布时间】:2022-01-11 19:35:38
【问题描述】:
我有一个 .csv 文件,用于修改 Active Directory 中用户的自定义属性,但 PowerShell 不喜欢该脚本:
Import-Csv -path c:\users\user\desktop\doc.csv | ForEach-Object {
Set-ADUser $_.mail -replace @{
ExtensionAttribute1 = $_.ExtensionAttribute1
}
}
我收到以下错误:
Set-ADUser : 替换
在 line:2 char:4
Set-ADUser $_.mail -replace @{
CategoryInfo: InvalidOperation: (user123:ADUser) [Set-ADUser], ADInvalidOperationException
FullyQualifiedErrorId: ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser
CSV 只有 2 列:
extensionAttribute1,mail
任何帮助将不胜感激
【问题讨论】:
-
去掉
@和左括号{之间的空格 -
这甚至不是
Set-ADUser的有效语法,也不是将管道 (|) 放在新行中。此外,您需要在同一行中为Foreach-Object使用左大括号,除非您使用继续/转义标记:反引号:`。没有-Replace参数,如果您指的是运算符,它是仍然是无效的语法。你的意图是什么?预期的结果是什么? -
@Theo 代码粘贴的方式加了一个空格。原始代码是 @{ 很抱歉造成混淆
-
我正在尝试根据他们的邮件属性将 extensionAttribute1 添加到 AD 中的用户
-
@Santiago,我的错!在我评论之前必须确认,哈哈,但是,现在仔细检查,我看到
-Replace是一个参数。谢谢!:)
标签: powershell active-directory custom-attributes