After Microsoft has disable the use of RPS (https://techcommunity.microsoft.com/t5/exchange-team-blog/deprecation-of-remote-powershell-in-exchange-online-re-enabling/ba-p/3779692) my code has broken.
Below is the C# code.
HttpClient Client = new HttpClient();
var tenantId = ((dynamic)JsonConvert.DeserializeObject(Client.GetAsync(ConnectionConst.wsManTokenIssuer + pSCredential.UserName.Split('@')[1] + "/v2.0/.well-known/openid-configuration").Result.Content.ReadAsStringAsync().Result)).authorization_endpoint.ToString().Split('/')[3];
PublicClientApplicationBuilder pcaBuilder = PublicClientApplicationBuilder.Create(ClientId);
pcaBuilder.WithTenantId(tenantId);
var tokenResult = pcaBuilder.Build().AcquireTokenByUsernamePassword(new[] { scope }, pSCredential.UserName, pSCredential.Password).ExecuteAsync().Result;
System.Security.SecureString secureStringToken = new System.Security.SecureString();
foreach (char c in ("bearer " + tokenResult.AccessToken))
{
secureStringToken.AppendChar(c);
}
PSCredential _shellCredential = new PSCredential(domainInfo.UserName, secureStringToken);();
String wsManURIConnectionString = "https://outlook.office365.com/powershell-liveid?DelegatedOrg=" + domainInfo.Domain + "&BasicAuthToOAuthConversion=true";
WSManConnectionInfo _wsManConnectionInfo = new WSManConnectionInfo(new Uri(wsManURIConnectionString), ConnectionConst.wsManShellURI, _shellCredential);
_wsManConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
_wsManConnectionInfo.MaximumConnectionRedirectionCount = 4;
Runspace _runspace = RunspaceFactory.CreateRunspace(_wsManConnectionInfo);
_runspace.Open();
At line Runspace _runspace = RunspaceFactory.CreateRunspace(_wsManConnectionInfo); I am getting 'System.Management.Automation.PSNotImplementedException' Exception.