I am facing an issue while connecting to Azure through the power shell.
could you please help me to resolve the issue?
code is below, please tell me where I am making a mistake.
we are using .net 7.0 to execute power shell and connect to azure
using System.Collections.ObjectModel;
using System.Management.Automation.Runspaces;
using System.Management.Automation;
using System.Windows;
using Microsoft.PowerShell;
namespace ConsoleApppowershell
{
internal class ConsoleApppowershell
{
private static async Task Main(string[] args)
{
string _state = "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine Get-ExecutionPolicy";
InitialSessionState iss = InitialSessionState.CreateDefault();
//iss.ImportPSModule(new string[] { "AzureAD" });
iss.ExecutionPolicy = ExecutionPolicy.Unrestricted;
iss.ExecutionPolicy = (ExecutionPolicy)ExecutionPolicyScope.CurrentUser;
iss.ThrowOnRunspaceOpenError = false;
Runspace runspace = RunspaceFactory.CreateRunspace(iss);
PowerShell ps = PowerShell.Create(runspace);
runspace.Open();
ps.AddScript(_state).Invoke();
//await ps.AddScript("Get-ExecutionPolicy").InvokeAsync();
await ps.AddParameter("-ExecutionPolicy", "Unrestricted").InvokeAsync();
//await ps.AddScript("Install-Module -Name AzureAD -Force").InvokeAsync();
await ps.AddScript("Import-Module -Name AzureAD -UseWindowsPowerShell").InvokeAsync();
//PowerShell ps = PowerShell.Create(runspace);
ps.AddCommand("Connect-AzureAD");
ps.AddParameters(new Dictionary<string,[![enter image description here][1]][1]object>
{
["ApplicationId "] = " ",
["CertificateThumbprint"] = " ",
["TenantId"] = " "
});
Collection<PSObject> connectionResult = ps.Invoke();
ps.Commands.Clear();
ps.AddCommand("Get-AzureADGroup");
ps.AddParameter("Filter", "DisplayName eq 'O365_ENTERPRISE_E5_DEVELOPER'");
Collection<PSObject> results = ps.Invoke();
if (!ps.HadErrors)
{
foreach (PSObject result in results)
{
Console.WriteLine(result.ToString());
}
}
else
{
foreach (ErrorRecord error in ps.Streams.Error)
{
Console.WriteLine(error.ToString());
}
}
}
}
}

HttpClientclass