我需要帮助PowerShell更改userPrincipalName中具有错误值的多个AD帐户。更改userPrincipalName中的值
几个用户在字符串中获得了多个@。那么,如何将CSV用于受影响的用户帐户并更改删除多余的@?
我需要帮助PowerShell更改userPrincipalName中具有错误值的多个AD帐户。更改userPrincipalName中的值
几个用户在字符串中获得了多个@。那么,如何将CSV用于受影响的用户帐户并更改删除多余的@?
您可以使用.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了解更多信息。
您是否有需要帮助的代码,或者您只是想知道如何更改字符串? StackOverflow不适用于代码请求。 – ShanayL
嗨,想知道如何更改字符串。我已经开始像这样收集用户:-) get-aduser -filter {userPrincipalName-like'* @@ *'} -Properties userPrincipalName |选择姓名,userPrincipalName 需要知道如何在每个受影响的accont上更改为one @ – ChristerR
使用该代码编辑您的问题,以便可以针对您的情况量身定制答案。 – ShanayL