AzureAutomationのPowerShellスクリプトで起きているエラー2件について

岩瀬 玲奈 0 評価のポイント
2025-07-23T08:56:26.1366667+00:00

現状PowerShellスクリプトでID/PWでユーザー認証をしている部分を、
アプリトークンでの認証方式に切り替える必要があり改修作業をしております。

当該スクリプトは AzureAutomationのRunbook上で稼働させるPowerShellスクリプトであり、ExchangeDLP・OneDriveDLP・SharePointDLPのそれぞれログを取得するスクリプトなのですが、
現在2件のエラーに直面しているため、解決のため手助けいただければと思います。

1件目は、「Connect-IPPSSession」を実行するため

$tenantId = "テナントID" 
$clientId = "クライアント(アプリケーション)ID" 
$clientSecret = "クライアントシークレット" 
$tokenUrl = https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token 
$body = @{ 
client_id = $clientId 
client_secret = $clientSecret 
scope = https://outlook.office365.com/.default 
grant_type = "client_credentials" 
} 
$response = Invoke-RestMethod -Uri $tokenUrl -Method Post -Body $body 
$accessToken = $response.access_token 
Connect-IPPSSession -AccessToken $accessToken -Organization "ドメイン名" -Verbos

上記のコードを実行しているのですが、

System.Management.Automation.RuntimeException: Unable to find type [Microsoft.Exchange.Management.AdminApiProvider.Utility]. at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos) at System.Management.Automation.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'Organization'. at System.Management.Automation.CmdletParameterBinderController.VerifyArgumentsProcessed(ParameterBindingException originalBindingException) at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments) at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments) at System.Management.Automation.CommandProcessor.BindCommandLineParameters() at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues) at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues) at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream) at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) --- End of stack trace from previous location --- at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

といったエラーメッセージが表示されます。
おそらくMicrosoft.Exchange.Management.AdminApiProvider.Utilityが見つからないようなエラーかと思うのですが、
実際ExchangeOnlineManagementのモジュールをギャラリーからインストールしております。(ランタイムVer7.2・3.8.0)
モジュールの問題かと思ったのですが解決しないため、ご相談させていただきたく思います。

2件目は、サービスプリンシパル (アプリケーション) を使用して、「Export-ActivityExplorerData」コマンドレットを使用する際に、当該アプリにはExchange.ManageAsApp を割り当て、Connect-IPPSSessionで接続し、「Export-ActivityExplorerData」コマンドレットでデータの取得が可能と考えているのですが、

Export-ActivityExplorerData: The term 'Export-ActivityExplorerData' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

といったエラーが表示されます。こちらのエラー要因についてご教示いただきたいです。

また、1件目のエラーが発生し、Runbook環境の問題かモジュールの問題かを切り分けるためにローカルで試した結果、 2件目のエラーが出たため、
1件目のエラーはRunbook上で実行して出たエラー、2件目はローカルで実行して出たエラーになります。

よろしくお願いいたします。

ビジネス向け Windows | Windows Server | ユーザー エクスペリエンス | PowerShell
{count} 件の投票

お客様の回答

質問作成者は回答に "承認済み"、モデレーターは "おすすめ" とマークできます。これにより、ユーザーは作成者の問題が回答によって解決したことを把握できます。