1

我有以下命令连接到 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(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");

我该如何解决这个问题?

4

0 回答 0