2017-10-13 195 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