#Office365的租户常常会有购买了新的域名的状况,即便公司内部有多个域名,每一个帐户能使用的登陆域名也只有一个,因此常常会须要更改域名的状况,能够调用PowerShell的replace()方法来实现一个简易的脚本。
#Office365 tenants often buy a new domain name. Even if there are multiple domain names in the company, each account can use only one login domain name. Therefore, it is often necessary to change the domain name. You can call PowerShell's replace( ) Method to implement a simple script.dom
#Script starts Connect-msolservice #$OldDomain, $NewDomainm, $Users needs to be changed #$OldDomain, $NewDomainm, $Users 三个变量须要自定义更改 $OldDomain = "gesinfotek.com" $NewDomain = "geservs.com" $users = get-content "C:/users.txt" Foreach($user in $users) { $NewUPN = ($user.userprincipalname).replace($OldDomain,$NewDomain) write-host ("Working on User: " + $user.userprincipalname) -fore Green Set-msoluserprincipalname -userprincipalname $user.userprincipalname -newuserprincipalname $NewUPN Get-msoluser -userprincipalname $user.NewUPN |select userprincipalname }