我需要PowerShell的帮助才能在userPrincipalName中使用错误的值更改多个AD帐户。
一些用户在字符串中获得了多个@。那么如何在受影响的用户帐户中使用CSV并更改删除额外的@?
答案 0 :(得分:0)
您可以使用.Replace
进行更改。
$string = "sometext@@@sometext"
$string.Replace("@@@", "@")
或
$string = ("sometext@@@sometext").Replace("@@@", "@")
要替换@
,无论字符串中有多少,您都可以使用Regex
$string = "sometext@@@sometext"
$symbolcount = ([regex]::Matches($string, "@")).count
if ($symbolcount -gt 1){
$symbols = ([regex]::Matches($string, "@")).Value -join ""
$string = $string.Replace($symbols,"@")
}
注意:仅当所有字符串中都包含@@@
时才会有效。
有关详细信息,请参阅this site。