﻿# 如何批次修改 Microsoft 365 所有成員的聯絡地址

最近我們公司搬遷到新的地址，公司所有 Microsoft 365 帳號下的地址也要進行更新，所以就寫了個 PowerShell 腳本來批次更新大家的地址資訊。

1.  列出所有同仁的地址資訊
    
    ```powershell
    Get-AzureADUser | Sort UserPrincipalName | where { $_.UserType -eq 'Member' } | Select UserPrincipalName,DisplayName,PostalCode,Country,State,City,StreetAddress | Format-Table
    ```
    
2.  取得一位同仁的地址資訊
    
    ```powershell
    $userPrincipalName="user@miniasp.com"
    Get-AzureADUser | where { $_.UserPrincipalName -eq $userPrincipalName } | Select UserPrincipalName,DisplayName,PostalCode,Country,State,City,StreetAddress
    ```
    
3.  更新所有同仁的地址資訊
    
    ```powershell
    $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
    ```
    
4.  更新一位同仁的地址資訊
    
    ```powershell
    $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
    ```
    

### 相關連結

-   [Configure Microsoft 365 user account properties with PowerShell](https://learn.microsoft.com/en-us/microsoft-365/enterprise/configure-user-account-properties-with-microsoft-365-powershell?view=o365-worldwide&WT.mc_id=DT-MVP-4015686)
