I am receiving CmdletInvocationException was unhandled, Cannot invoke this function because the current host does not implement it.
when i replace the Export-Mailbox cmdlet with a get-command as a test I get no errors.
Here is my sample code. When i run sScript1, its runs just fine, when i run sScript2 thats when i get the error. When im on my testing machine i did the get-excommand and I couldnt find the export-mailbox cmdlet.
public void RunPowerShell()
{
Cursor.Current = Cursors.WaitCursor;
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
Runspace runSpace;
//create the runspace
runSpace = RunspaceFactory.CreateRunspace(rsConfig);
runSpace.Open();
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
Pipeline pipeLine = runSpace.CreatePipeline();
//Add-MailboxPermission -Identity " + FromEmailAccount.Text + " -User Administrator -AccessRights FullAccess
String sScript1 = "Add-MailboxPermission -Identity " + ToEmailAccount.Text + " -User Administrator -AccessRights FullAccess";
String sScript2 = "Export-Mailbox -Identity " + FromEmailAccount.Text + " -TargetMailbox " + ToEmailAccount.Text + " -TargetFolder " + ToEmailAccount.Text + " -Confirm:$false";
//pipeLine.Commands.AddScript(sScript1);
pipeLine.Commands.AddScript(sScript2);
Collection<PSObject> commandResults = pipeLine.Invoke();
//loop through the results of the command and load the SamAccountName into the list
foreach (PSObject results in commandResults)
{
//MessageBox.Show(results.ToString(), @"test");
}
pipeLine.Dispose();
runSpace.Close();
MessageBox.Show(@"complete", @"Done");
Cursor.Current = Cursors.Default;
}