Active Directory Powershell附加到现有属性值

问题描述 投票:0回答:2

我正在寻找一种方法使用Set-ADuser将值附加到现有属性的末尾。

到目前为止我有:(因为敏感性而忽略我的过滤器)

Get-ADUser -Filter (<filter>) -Properties Name,DisplayName,EmployeeID,SAMAccountName | ? {$_.Samaccountname.length -eq 5} | Set-ADUser <???>

我一直在寻找一种只追加到employeeID属性而不会覆盖当前值的方法。如果还有另一种方法可以实现这一点,我很想知道如何做到这一点。

powershell active-directory
2个回答
0
投票

因此,使用Set-ADUser,您可以将-replace与哈希表一起使用。因此,通过循环运行结果,在每个循环上为其EmployeeID设置哈希表=现有的加上任何新文本,并设置帐户以替换哈希表中的数据。像这样的东西:

Get-ADUser -Filter (<Filter>) |?{$_.SAMAccountName.Length -eq 5} | %{$HT = @{};$HT.add("EmployeeID", "$($_.EmployeeID)AdditionalText");Set-ADUser $_.SAMAccountName -Replace $HT}

0
投票

这将完成它,我测试它并完美地工作:只需用您想要的属性或属性替换信息:

Import-Module ActiveDirectory 
$j=Read-Host "Enter the samaccountname" 
$i = Get-ADUser $j -Properties info | %{ $_.info}  
Set-ADUser $j -Replace @{info="$($i) `r`n Account Disabled for O365 Cleanup"} 

资料来源:https://gallery.technet.microsoft.com/scriptcenter/Powershell-Append-Info-5f613638

© www.soinside.com 2019 - 2024. All rights reserved.