在AD用户描述前添加PS – 使用ForEach进行重复更新

huangapple go评论131阅读模式
英文:

Prepend AD User description with PS - Duplicate Update with ForEach

问题

我曾看过很多代码示例,其中可以使用Get-ADUser来使用以下代码追加描述信息:

get-aduser username -Properties Description | ForEach-Object { Set-ADUser $_ -Description "$($_.Description) 添加更多内容" }

我原以为我可以简单地倒转代码的顺序来在前面添加,像这样:

get-aduser username -properties Description | ForEach-Object { Set-ADUser $_ -Description "要使用的内容 - $($_.Description)"}

然后输出变成了:

"要使用的内容 - 要使用的内容"

实际上,无论最初有什么,都会完全被替换为预期目标的结果的两倍。我错过了什么?

英文:

I've seen many code examples where Get-ADUser can be used to append a description with the following code:

get-aduser username -Properties Description | ForEach-Object { Set-ADUser $_ -Description "$($_.Description) Some more stuff" }

I had thought I could simply invert the order of the code in order to prepend, like so:

get-aduser username -properties Description | ForEach-Object { Set-ADUser $_ -Description "Stuff To Use - $($_.Description)"}

The output then becomes:

"Stuff To Use - Stuff To Use"

In essence, whatever is there to start with is wiped out completely and replaced with a doubled up result of the intended goal.

What am I missing here?

答案1

得分: 1

代码部分:The code is good and it likely ran twice accidentally.
翻译:代码部分良好,可能意外运行了两次。

代码部分:Reset the description, run the code, then refresh Active Directory Users and Computers and recheck.
翻译:代码部分:重置描述,运行代码,然后刷新Active Directory用户和计算机,然后重新检查。

英文:

The code is good and it likely ran twice accidentally.

Reset the description, run the code, then refresh Active Directory Users and Computers and recheck.

huangapple
  • 本文由 发表于 2020年1月7日 01:47:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定