2017-10-13 42 views
-1

我需要帮助PowerShell更改userPrincipalName中具有错误值的多个AD帐户。更改userPrincipalName中的值

几个用户在字符串中获得了多个@。那么,如何将CSV用于受影响的用户帐户并更改删除多余的@?

+0

您是否有需要帮助的代码,或者您只是想知道如何更改字符串? StackOverflow不适用于代码请求。 – ShanayL

+0

嗨,想知道如何更改字符串。我已经开始像这样收集用户:-) get-aduser -filter {userPrincipalName-like'* @@ *'} -Properties userPrincipalName |选择姓名,userPrincipalName 需要知道如何在每个受影响的accont上更改为one @ – ChristerR

+0

使用该代码编辑您的问题,以便可以针对您的情况量身定制答案。 – ShanayL

回答

0

您可以使用.Replace来更改它。

$string = "[email protected]@@sometext" 
$string.Replace("@@@", "@") 

$string = ("[email protected]@@sometext").Replace("@@@", "@") 

要更换@不管多少是在字符串中,你可以在用户正则表达式

$string = "[email protected]@@sometext" 
$symbolcount = ([regex]::Matches($string, "@")).count 
if ($symbolcount -gt 1){ 
    $symbols = ([regex]::Matches($string, "@")).Value -join "" 
    $string = $string.Replace($symbols,"@") 
} 

注:此方法仅当所有的字符串都其中有@@@

查看this site了解更多信息。

+0

谢谢!我们得到了som用户,最高达到16 @ – ChristerR

+0

我编辑了答案来检测有多少'@'符号显示 – ShanayL

+0

谢谢ShanayL!这对我有帮助:-) – ChristerR