我需要幫助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