Skip to content

macOS に PowerShell をインストールする

PowerShell から Entra ID (旧 Azure Active Directory) を操作するには AzureAD PowerShell モジュールを利用していました。 ですが、2024 年 4 月ごろに 重要なお知らせ: Azure AD PowerShell および MSOnline PowerShell モジュールの廃止 で以下のようにアナウンスされている通り、このモジュールは非推奨になっています。

2021 年に、Microsoft Entra の PowerShell 提供元として、今後は Microsoft Graph PowerShell SDK に投資すること、また Azure AD および MSOnline PowerShell モジュールからの 移行計画について発表 いたしました。2023 年には、Azure AD と MSOnline PowerShell モジュールの非推奨化を 2024 年 3 月 30 日に行うと 発表 しました。その後、Microsoft Graph PowerShell SDK に不足していた機能の解消が大幅に進み、2024 年 3 月 30 日をもって、これらの PowerShell モジュールは非推奨となりました:

また、Microsoft Graph PowerShell を使用して Microsoft 365 に接続する にも以下の記載があります。

Azure Active Directory (AzureAD) PowerShell モジュールは非推奨となり、Microsoft Graph PowerShell SDK に置き換えられます。 Microsoft Graph PowerShell SDK を使用して、すべての Microsoft Graph API にアクセスできます。 詳細については、「Microsoft Graph PowerShell SDK の使用を開始する」 を参照してください。

Microsoft Graph PowerShell のインストールと Microsoft Graph PowerShell へのアップグレードの方法については、「Microsoft Graph PowerShell SDK のインストール」と「 Azure AD PowerShell から Microsoft Graph PowerShell へのアップグレード」も参照してください。

このように、今後は Microsoft Graph PowerShell の利用が推奨されているようです。 今回は macOS 上に PowerShell をインストールし、Graph を利用出来るようにする手順をメモしておきます。

検証環境

対象 バージョン
macOS Sequoia 15.4.1
PowerShell 7.5.1

PowerShell のインストール

PowerShell は Homebrew でインストール出来ます。

brew install powershell

現時点ではバージョン 7.5.1 がインストールされました。

% brew info powershell
==> powershell: 7.5.1
https://github.com/PowerShell/PowerShell
Installed
/opt/homebrew/Caskroom/powershell/7.5.1 (68MB)
  Installed using the formulae.brew.sh API on 2025-05-01 at 23:27:20
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/p/powershell.rb
==> Name
PowerShell
==> Description
Command-line shell and scripting language
==> Artifacts
powershell-7.5.1-osx-arm64.pkg (Pkg)
==> Caveats
To use Homebrew in PowerShell, run the following in a PowerShell session:
  New-Item -Path (Split-Path -Parent -Path $PROFILE.CurrentUserAllHosts) -ItemType Directory -Force
  Add-Content -Path $PROFILE.CurrentUserAllHosts -Value '$(/opt/homebrew/bin/brew shellenv) | Invoke-Expression'

==> Analytics
install: 45,184 (30 days), 108,994 (90 days), 261,646 (365 days)

Graph モジュールのインストール

PowerShell を起動するには pwsh を実行します。

% pwsh
PowerShell 7.5.1
PS /Users/USERNAME>

PowerShell が起動したら Graph モジュールをインストールします。 以下を実行します。

Install-Module -Name "Microsoft.Graph" -Repository PSGallery -Force

今回はバージョン 2.27.0 がインストールされました。

> Get-InstalledModule -Name "Microsoft.Graph"

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
2.27.0               Microsoft.Graph                     PSGallery            Microsoft Graph PowerShell module

Azure テナントに接続する

Azure テナントに接続するには Connect-MgGraph を実行します。 「12345678-1234-1234-1234-1234567890AB というテナントへ読み / 書き権限で接続する」場合は以下のように実行します。

Connect-MgGraph -TenantId 12345678-1234-1234-1234-1234567890AB -Scopes "Application.ReadWrite.All"

参考