我如何在Powershell中更改自定义属性的子string?

我相信这是相当基本的,但我似乎无法把头围绕起来,在这一点上,对我来说手动操作几乎更为谨慎,但这似乎是一个很好的学习机会。

我在AD中创build了一个自定义属性。 用户都将其设置为通过第三方应用程序进行同步的电子邮件,与Active Directory无关。 我需要通过Powershell从[email protected]将所有这些域名更改为[email protected]。 这似乎很容易,但由于某种原因,我不能让Set-ADUser更改每个用户的属性,并取代原来的用户名。 我需要删除旧的域名的最后27个字符,连接当前的login名和新的域名,然后设置它。 这似乎很简单,但我仍然收到无效的论据,无论我如何在Powershell中尝试它。

到目前为止,我有这样的东西:

$Users = Get-ADUser -Filter "*" -SearchBase 'OU=test,DC=adDomain,DC=org' -Properties customattribute ForEach-Object { $fullAttribute = Get-ADUser $_{customattribute} $logon -replace "fullAttribute.{27}$" $newLogon = $logon + "newdomainname.com" Set-ADUser $_ -replace @{customattribute=$newLogon} } 

我一直试图采取阶段,但我不断遇到语法错误。

这应该让你开始。 没有@ Zordache要求的详细信息是很难testing的。

 $olddomain ="billybob.com" $newdomain = "newdomainname.com" $Users = Get-ADUser -Filter "*" -SearchBase 'OU=test,DC=adDomain,DC=org' -Properties customattribute ForEach-Object { $user = $_ $fullAttribute = ($user.customattribute).tostring() $newattr = $fullAttribute.replace $olddomain $newdomain $user.customattribute=$newattr Set-ADUser -instance $user }