英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论