# Office 365 管理系列：關閉使用者密碼複雜度的方法

最近輔導一家大型機構導入 Office 365 雲端辦公平台，我幫他們批次建立了一千多個 Exchange Online 帳號，不過客戶提供的帳號清單中包含了每個人都不一樣的預設密碼。不過我在測試自己寫的自動化建立帳號程式時(PowerShell)，有發現到 Office 365 拒絕了我的密碼變更需求，原因是密碼沒有符合複雜度要求，導致雖然可以建立帳號，但卻無法重設為客戶想要的密碼，本篇文章主要說明如何暫時關閉密碼複雜度要求，並且在建立預設密碼後再啟用原本的使用者密碼複雜度要求，並要求使用者首次登入必須修改密碼。  
  
\>>> [試用 Office 365 的申請連結](https://portal.microsoftonline.com/partner/partnersignup.aspx?type=Trial&id=2b8299c9-2eea-4557-9042-cdf104d31dda&msppid=811392) <<<  

首先，修改密碼的 PowerShell 命令為：

```
Set-MsolUserPassword -UserPrincipalName test@miniasp.com -NewPassword SimplePW123
```

但若密碼太過簡單，就會出現以下錯誤訊息：

Set-MsolUserPassword : You must choose a strong password that **contains 9 to 16 characters**, **a combination of letters**, and **at least one number or symbol**. Choose another password and try again.

[![](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/cd013b74e5726b851a76-image_thumb_153.png)](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/219ac35b5493737f3072-image_1924.png)

如果要暫時解除使用者的密碼複雜度要求，可以執行以下 PowerShell 命令完成：

```
Set-MsolUser -UserPrincipalName test@miniasp.com -StrongPasswordRequired $False
```

而當我設定密碼後，會再將此設定調回來，確保使用者自行密碼重設時，可以設定一組夠強的密碼。

```
Set-MsolUser -UserPrincipalName test@miniasp.com -StrongPasswordRequired $True
```

重整一下客戶需求：

-   客戶提供帳號清單，包含預設密碼
-   建立帳號時，須設定使用者可用預設密碼登入
-   使用者首次登入必須被要求變更預設密碼
-   使用者變更密碼時必須強迫套用 Office 365 預設的密碼複雜度要求

最後，完成一位使用者的 PowerShell 指令碼如下：

```
Set-MsolUser -UserPrincipalName a@a.com -StrongPasswordRequired $False
Set-MsolUserPassword -UserPrincipalName a@a.com -NewPassword 123 -ForceChangePassword $True
Set-MsolUser -UserPrincipalName a@a.com -StrongPasswordRequired $True
```

\>>> [試用 Office 365 的申請連結](https://portal.microsoftonline.com/partner/partnersignup.aspx?type=Trial&id=2b8299c9-2eea-4557-9042-cdf104d31dda&msppid=811392) <<<  
如果你也有 Office 365 導入建置、教育訓練或客製化程式開發等需求，歡迎來信或留言，我會請負責 Office 365 的同仁與你聯繫，謝謝。  

**相關連結**

-   [Office 365 的 Windows PowerShell Cmdlet](http://onlinehelp.microsoft.com/zh-tw/office365-enterprises/hh125002.aspx)
-   [PowerShell Cmdlet 在 Exchange Online 中可用的參考](https://learn.microsoft.com/en-us/powershell/module/exchangepowershell/)
-   [Managing Passwords with PowerShell | Vorsite Company Blog](https://web.archive.org/web/20150710110550/http://vorsite.com:80/blog/2012/07/managing-passwords-with-powershell/)
-   [Create Your Own PowerShell Functions](http://windowsitpro.com/windows/create-your-own-powershell-functions)
-   [Windows PowerShell Tips](http://technet.microsoft.com/en-us/library/hh848797.aspx)
