【Office365】PowershellでExchange Onlineに接続する方法

Office365
スポンサーリンク


PowerShellのコマンドを使ってExchange Onlineに接続する方法を紹介します。

スポンサーリンク

PowerShellの起動

「Windows PowerShell ISE」を管理者として実行します。

検索で「Powershell」と入力すると、「Windows PowerShell ISE」が候補に出てくるの右クリックします。
「管理者として実行」をクリックしてPowerShellを起動します。

Exchange Onlineに接続

PowerShellで次のコマンドを入力します。

Set-ExecutionPolicy RemoteSigned

初めてPowerShellを実行する時のみのコマンドです。2回目以降は不要です。
「実行ポリシーの変更」を確認されるので「はい」もしくは「すべて続行」をクリックします。

$UserCredential = Get-Credential

資格情報を確認されるので、Office365の管理者権限のあるアカウントとパスワードを入力します。

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

Import-PSSession $Session -AllowClobber

これでExchange Onlineへの接続が完了です。

切断する時は次のコマンドを入力します。

Remove-PSSession $Session

その他の接続

MSOnline Moduleを使用するためのAzure AD接続方法
MSOnline Moduleを使用するためのAzure ADへの接続についてはこちらをご覧ください。

【Office365】PowershellでMSOnline Moduleを使うためにAzure Active Directory(Azure AD)に接続する方法
MSOnline Moduleを利用する場合にはAzure ADへの接続が必要です。 MSOnline ModuleはGet-MsolUserやGet-MsolGroupなどのようにコマンドに「Msol」を含んでいます。 Pow...