最近我們公司搬遷到新的地址,公司所有 Microsoft 365 帳號下的地址也要進行更新,所以就寫了個 PowerShell 腳本來批次更新大家的地址資訊。
-
列出所有同仁的地址資訊
Get-AzureADUser | Sort UserPrincipalName | where { $_.UserType -eq 'Member' } | Select UserPrincipalName,DisplayName,PostalCode,Country,State,City,StreetAddress | Format-Table
-
取得一位同仁的地址資訊
$userPrincipalName="user@miniasp.com"
Get-AzureADUser | where { $_.UserPrincipalName -eq $userPrincipalName } | Select UserPrincipalName,DisplayName,PostalCode,Country,State,City,StreetAddress
-
更新所有同仁的地址資訊
$PostalCode = "10444"
$Country = "TW"
$State = "台灣"
$City = "台北市"
$StreetAddress = "中山北路一段82號7樓"
Get-AzureADUser | Sort UserPrincipalName | where { $_.UserType -eq 'Member' } | Set-AzureADUser -PostalCode $PostalCode -Country $Country -State $State -City $City -StreetAddress $StreetAddress
-
更新一位同仁的地址資訊
$userPrincipalName = "user@miniasp.com"
$PostalCode = "10444"
$Country = "TW"
$State = "台灣"
$City = "台北市"
$StreetAddress = "中山北路一段82號7樓"
Get-AzureADUser | where { $_.UserPrincipalName -eq $userPrincipalName } | Set-AzureADUser -PostalCode $PostalCode -Country $Country -State $State -City $City -StreetAddress $StreetAddress
相關連結