2015年8月31日 星期一

Office365、Exchange Online帳號管理常用指令

因為工作關係,大約半年要來更新一次,每次要設定前都已經忘的差不多了,所以還是寫起來吧,如果只是更改1、2個帳號就到網頁的後台去更改就好了,大量才用會到。

Office365指令


基本指令


連線
Connect-MsolService


查詢


取得目前有的授權方案
Get-MsolAccountSku

取得未授權的帳號
Get-MsolUser -UnlicensedUsersOnly

匯出「某個授權」的所有帳號並存成檔案
Get-MsolUser -All | Where-Object {$_.Licenses.AccountSkuID -eq "xxx:EXCHANGESTANDARD_ALUMNI" } |  Select-Object UserPrincipalName,DisplayName, Licenses | Export-Csv C:\路徑\檔名.csv  -NoTypeInformation -Encoding "unicode"


設定

*紅字部分就是你要修改的地方

使用csv檔案大量修改(csv的「欄位名稱」請用英文命名,當指令要用到「欄位名稱」時請在前面加上「$_.)
Import-Csv csv的檔案路徑 | ForEach-Object { 下面的指令 }

例如:解除密碼複雜度(帳號的欄位名稱命名為UPN)
Import-Csv C:\TEST.CSV | ForEach-Object { Set-MsolUser -UserPrincipalName $_.UPN -StrongPasswordRequired $False }


指定服務位置
Set-MsolUser -UsageLocation TW

取消某個帳號「xxx方案」的授權
Set-MsolUserLicense  -UserPrincipalName 帳號 -RemoveLicenses xxx:STANDARDWOFFPACK_STUDENT

給予某個帳號「xxx方案」的授權
Set-MsolUserLicense  -UserPrincipalName 帳號 -AddLicenses xxx:EXCHANGESTANDARD_ALUMNI

變更的話就是取消跟給予寫在一起
Set-MsolUserLicense  -UserPrincipalName 帳號 -RemoveLicenses xxx:STANDARDWOFFPACK_STUDENT  -AddLicenses xxx:EXCHANGESTANDARD_ALUMNI

授權「xxx方案」給未授權的帳號
Get-MsolUser -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses xxx:STANDARDWOFFPACK_STUDENT

解除密碼複雜度($False是解除,$True是啟用)
Set-MsolUser -UserPrincipalName 帳號 -StrongPasswordRequired $False

修改某個帳號的密碼(如果你的密碼太簡單就要先解除密碼複雜度),並讓使用者第一次登入時不需再更改密碼($True是要改密碼 $False是不用改)
Set-MsolUserPassword -UserPrincipalName 帳號 -NewPassword 密碼 -ForceChangePassword $False


Exchange Online指令

基本指令


工作電腦第一次連線時,用管理者權限執行程式並輸入
Set-ExecutionPolicy RemoteSigned

連線(3個指令分開打)
$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

離線
Remove-PSSession $Session

查詢


查詢使用者信箱所有屬性
Get-Mailbox -Identity 帳號 | Get-Member | Out-GridView


設定

讓信箱不顯示在通訊錄中
get-mailbox -Identity 帳號 | set-mailbox -hiddenfromaddresslistsenabled $True

設定使用者信箱-[自訂屬性1]為你要的值
Set-Mailbox -Identity 帳號 -CustomAttribute1 你要的值





熱門文章