Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning a powershell command in C# errors with, "Cannot invoke this function because the current host does not implement it"
    primarykey
    data
    text
    <p>I have an application that I use to run Exchange Powershell commands inside C# code like below. This is an example of the relevant lines I use to run the powershell command.</p> <pre><code> RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; //load Exchange shell rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException); Runspace runSpace = RunspaceFactory.CreateRunspace(rsConfig); //open runspace runSpace.Open(); //setup pipeline Pipeline pipeLine = runSpace.CreatePipeline(); String sScript = "get-mailbox -identity 'rj'"; //add script to pipeline pipeLine.Commands.AddScript(sScript); //run the script pipeLine.Invoke(); pipeLine.Dispose(); </code></pre> <p>This code works perfect in all cases until now. the script I am trying to run instead of the one above is to set the RetentionPolicy for a mailbox. The script I am trying to run looks like this:</p> <p>Set-Mailbox -Identity 'rj' -RetentionPolicy 'Main Campus Retention Policy'</p> <p>When I run this in powershell itself it works perfectly but when I try to run it using the code below I get the error, "Cannot invoke this function because the current host does not implement it."</p> <p>From this error, it almost seems like the command that runs in C# cannot run the RetentionPolicy command but that doesn't make much sense. I have Googled this and tried everything suggested but no luck. </p> <p>If anyone knows why this is happening, it would be very helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload