社畜の所業

社畜の所業

Microsoft365の機能について解説をしていきたいと思います。このブログの情報をご活用いただければ幸いです。たまに他の情報も取り入れていきたいと思います。

※このサイトはPR記事を含みます。

【Microsoft365参考書】基本認証廃止後にPowershellで基本認証でExchangeOnlineに接続した場合のエラーについて

基本認証接続コマンド

$UserCredential = Get-Credential 

 

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

 

Import-PSSession $Session -AllowClobber 

 

エラー

New-PSSession : [outlook.office365.com] リモート サーバー outlook.office365.com への接続に失敗し、次のエラー メッセージが返されました: アクセスが拒否されました。 

 

 

 

 

2022  10  1 日に Exchange Online の基本認証が廃止されており、順次、テナントで基本認証の無効化がおこなわております。 

  

Exchange Online の基本認証が無効化された状態で、Powershell にて、基本認証で Exchange Online に接続した場合、上記のように "アクセスが拒否されました”とエラーが発生することを確認しました。

  

そのため、"アクセスが拒否されました”とエラーが発生した場合は、基本認証で接続していないか確認し、以下の手順にて、V2 モジュールのインストール、および、先進認証で Exchange Online に接続してください。

 

   

 

事前準備 : Windows PowerShell の接続 

本手順 1  5 は、PowerShell を実行する端末にて初回のみ実施いたします。 

  

 1. PowerShell の実行ポリシーを変更する 

  1. スタートメニューのWindows PowerShell を右クリックし、[管理者として実行から開きます。 

  

[構文] 

Set-ExecutionPolicy RemoteSigned 

  

[実行ポリシーの変更を求められますので、[Y] と入力して [Enter] キーを押下します。 

※ 上記は、コンピューターで一度だけ構成すれば、接続ごとに行う必要はありません。 

  

以下のコマンドレットを実行し、表示結果が [RemoteSigned] であるか確認します。 

  

Get-ExecutionPolicy 

  

2. TLS 1.2 の通信設定を許可する 

※ 下記のコマンドは 1 行となります。 

  

[構文] 

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 

  

その後、以下のコマンドを再度実行し、表示結果に Tls12 が含まれることを確認します。 

[Net.ServicePointManager]::SecurityProtocol 

  

<実行結果表示例> 

Tls12 

  

3. NuGet / PowerShellGet の更新を行う 

[構文] 

Install-PackageProvider -Name NuGet -Force 

  

Install-Module -Name PowerShellGet -Force 

  

4. Exchange Online V2 モジュールのインストールを行う 

[構文] 

Install-Module -Name ExchangeOnlineManagement 

  

 "インストールしますか?のメッセージが表示されましたら 

"y" 

をご入力いただき、"enter" キーを押下願います。 

  

5. Exchange Online V2 モジュールの読み込みを行う 

[構文] 

Import-Module ExchangeOnlineManagement 

 

 

 

6. V2 モジュールで Exchange Online PowerShell に接続する 

[構文] 

Connect-ExchangeOnline -UserPrincipalName <管理者メールアドレス> -ShowProgress $True 

  

[実行例] 

Connect-ExchangeOnline -UserPrincipalName Admin01@contoso.com -ShowProgress $True 

  

 ID や パスワードの入力を求める表示が出た場合には、管理者のサインイン ID と パスワードのご入力をお願いいたします。 

  

接続が行われると、以下の警告が表示された後にコマンドを実行が実行できる状態となります。 

  

--- 警告文章抜粋 --- 

---------------------------------------------------------------------------------------- 

This V3 EXO PowerShell module contains new REST API backed Exchange Online cmdlets which doesn't require WinRM for Client-Server communication. You can now run these cmdlets after turning off WinRM Basic Auth in your client machine thus making it more secure. 

  

Unlike the EXO* prefixed cmdlets, the cmdlets in this module support full functional parity with the RPS (V1) cmdlets. 

  

V3 cmdlets in the downloaded module are resilient to transient failures, handling retries and throttling errors inherently. 

  

However, REST backed EOP and SCC cmdlets are not available yet. To use those, you will need to enable WinRM Basic Auth. 

  

For more information check https://aka.ms/exov3-module 

---------------------------------------------------------------------------------------- 

 

learn.microsoft.com