Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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# 用于从C连接到Exchange的PowerShell命令#_C#_Powershell_Exchange Server - Fatal编程技术网

C# 用于从C连接到Exchange的PowerShell命令#

C# 用于从C连接到Exchange的PowerShell命令#,c#,powershell,exchange-server,C#,Powershell,Exchange Server,我使用以下命令连接到Exchange PowerShell。我使用C#连接,但是最后一行Import PSSession$Session使站点崩溃并将我带到调试器 $password = ConvertTo-SecureString -AsPlainText -Force mypassword;$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist me@mail.net,$pa

我使用以下命令连接到Exchange PowerShell。我使用C#连接,但是最后一行Import PSSession$Session使站点崩溃并将我带到调试器

$password = ConvertTo-SecureString -AsPlainText -Force mypassword;$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist me@mail.net,$password;$LiveCred = Get-Credential -Credential $mycred;$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlookurlforpowershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection; Import-PSSession $Session
这是我的C#代码:

private void initconnection(字符串文本){
运行空间rs=GetRunspace();
Pipeline cmd=rs.CreatePipeline(文本);
收集结果=cmd.Invoke();
}
初始化连接("$password=converttosecurestring-AsPlainText-Force Maxipereyra15;$mycred=new object-typename System.Management.Automation.PSCredential-argumentlistcpereyra@crescentmortgage.net,$password;$LiveCred=Get-Credential-Credential$mycred;$Session=New-PSSession-ConfigurationName-Microsoft.Exchange-ConnectionUrihttps://ps.outlook.com/powershell/-Credential$LiveCred-Authentication Basic-AllowRedirection;Import-PSSession$Session”);

如何解决此问题?

您是说ps命令在命令窗口中工作,但不是通过c#?是否存在从c#调用powershell的resdon,而不是使用exchage API?还有哪个版本的exchange?muratgu如果在powershell中键入相同的命令,则正确。但是通过c#调用powershell,则不正确。Stuart ha即使未查看exchange api,它是否具有与powershell相同的命令?是否尝试单步执行代码并查看它生成的异常?cmcletinvocationexception是它引发的异常。加载格式数据文件时出错:Microsoft.powershell
private void initconnection(string text){

    Runspace rs = GetRunspace();
    Pipeline cmd = rs.CreatePipeline(text);
    Collection<PSObject> results = cmd.Invoke();
}

initconnection("$password = ConvertTo-SecureString -AsPlainText -Force Maxipereyra15;$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist cpereyra@crescentmortgage.net,$password;$LiveCred = Get-Credential -Credential $mycred;$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection; Import-PSSession $Session");