トップ回答者
PowerShell 埋め込んだC#のアセンブリ参照について

質問
-
PowerShellにC#の埋め込みを行い、C#からAzureADからアクセストークンを取得する処理を作成しようとしています。
アクセストークンの取得に"Microsoft.IdentityModel.Clients.ActiveDirectory"を参照する必要があるのですが、
埋め込んだC#では"Microsoft.IdentityModel.Clients.ActiveDirectory"が参照できずコンパイルエラーが発生いたします。
作成したスクリプトとエラー内容は以下のようになっています。
$src = @' using System; using System.Threading.Tasks; using Microsoft.IdentityModel.Clients.ActiveDirectory; public static class TokenClass { public static async Task<string> GetAccessToken(string clientid, string username, string password) { AuthenticationContext authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/common"); AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync( "https://graph.microsoft.com/", clientid, new UserPasswordCredential(username, password) ); return authenticationResult.AccessToken; } } '@ Add-Type -TypeDefinition $src -Language CSharp [TokenClass]::GetAccessToken("clientid", "username", "password") > $null
エラー内容
型または名前空間名 'IdentityModel' は名前空間 'Microsoft' に存在しません。アセンブリ参照が不足しています。
getAccessToken.ps1:23 文字:1
+ Add-Type -TypeDefinition $src -Language CSharp
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type]、Excepti
on
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommandアセンブリをロードする"[reflection.assembly]::LoadWithPartialName("Microsoft.IdentityModel.Clients.ActiveDirectory")"を実行しましたがC#ではアセンブリをロードできていないようです。
埋め込んだC#に"Microsoft.IdentityModel.Clients.ActiveDirectory"を参照させる方法はありますでしょうか?