Ric*_*ard 3 powershell powershell-2.0
PowerShell的新手,仍然试图获得逻辑.
我想过滤掉特定OU中活动目录中的samaccountname,它在字符串末尾也包含"adm"(phil_test_adm).当找到用户时,我想用"tst"代替"adm".到目前为止,我有下面的内容,我再次对这个逻辑感到困惑.
import-module activedirectory
$Path = 'OU=Example, OU=Users,DC=uk,DC=random,DC=com'
$users = Get-ADUser -filter 'SamAccountName -like "*adm"' -SearchBase $Path | select-object samaccountname, name
#foreach ($user in $users) 
#{
#Set-ADUser $user.samaccountname -Replace { 
#if $user.sammaccountname -eq "*adm"  }
正如你可以看到foreach开始我刚刚开始玩的地方.感谢您的任何帮助!
假设你的前几行正在努力检索正确的结果,这个foreach块应该工作:
foreach ($user in $users) 
{
    $newSamAccoutname = $user.SamAccountName.replace("adm","tst")
    Set-ADUser $user -Replace @{samaccountname=$newSamAccoutname} 
}
| 归档时间: | 
 | 
| 查看次数: | 22159 次 | 
| 最近记录: |