我无法在c#程序中运行Skyline PowerShell脚本
我正在尝试在C#上的程序中运行此Skyline脚本。 也有例外。 脚本在PowerShell命令行中运行良好我无法在c#程序中运行Skyline PowerShell脚本,c#,powershell,skype-for-business,C#,Powershell,Skype For Business,我正在尝试在C#上的程序中运行此Skyline脚本。 也有例外。 脚本在PowerShell命令行中运行良好 using (var powerShellInstance = PowerShell.Create()) { powerShellInstance.Commands .AddCommand("Import-Module") .AddArgument("SkypeOnlineConnector"); var script =
using (var powerShellInstance = PowerShell.Create())
{
powerShellInstance.Commands
.AddCommand("Import-Module")
.AddArgument("SkypeOnlineConnector");
var script =
"$Username =\"username\"\n" +
"$Password =\"password\"\n" +
"$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force\n" +
"$cred = new-Object System.Management.Automation.PSCredential ($Username, $secpasswd)\n" +
"$CSSession = New-CsOnlineSession -Credential $cred\n" +
"Import-PSSession $CSSession -AllowClobber\n" +
"Get-CsOnlineUser";
powerShellInstance.AddScript(script);
powerShellInstance.Invoke();
}
此it结果异常:
Unhandled Exception: System.Management.Automation.CmdletInvocationException: Method not found: 'Microsoft.IdentityModel.
Clients.ActiveDirectory.AuthenticationResult Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.Acqui
reToken(System.String, System.String, System.Uri, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'. --->
System.MissingMethodException: Method not found: 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireToken(System.String, System.String, System.
Uri, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'.
at Microsoft.Rtc.Management.OnlineConnector.GetAccessToken.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper(TInput,TOutput)(PSDataCollection'1 input, PSDataCollectio
n'1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke(TInput,TOutput)(PSDataCollection'1 input, PSDataCollection'1 ou
tput, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at MSPControl.Providers.MicrosoftOnline.Tests.Console.Program.Main(String[] args) in Program.cs:line 22
我已经创建了一个新项目,问题已经解决。似乎旧项目包含不正确的引用。我已创建新项目,问题已解决。似乎旧项目包含不正确的引用。