Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法在c#程序中运行Skyline PowerShell脚本_C#_Powershell_Skype For Business - Fatal编程技术网

我无法在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 =

我正在尝试在C#上的程序中运行此Skyline脚本。 也有例外。 脚本在PowerShell命令行中运行良好

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

我已经创建了一个新项目,问题已经解决。似乎旧项目包含不正确的引用。我已创建新项目,问题已解决。似乎旧项目包含不正确的引用。