Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling remote Cmdlets from C# Runspace
    primarykey
    data
    text
    <p>I'm trying to run a remote Powershell Cmdlet (one of Exchange 2010's cmdlets) from a remote machine without the Exchange cmdlets installed, using Powershell remoting (v2) in my C# code. I have something like this:</p> <pre><code>var connection = new WSManConnectionInfo("http://my.exchange.srv/PowerShell", "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials); var runspace = RunspaceFactory.CreateRunspace(connection); var ps = PowerShell.Create(); ps.Runspace = runspace; runspace.Open(); var results = ps.AddCommand("Enable-MailPublicFolder").AddArgument(folderId).Invoke(); </code></pre> <p>This returns a RemoteException: The term 'Enable-MailPublicFolder is not recognized' error. This is because the local machine isn't familiar with the Exchange Cmdlet.</p> <p>However, I have no idea how to import the Exchange module into my runspace. I've found various solutions, but all are partial. Some tell me to use a <code>RunspaceConfiguration</code> to add the Exchange 2010 snapin, but there are no overloads for <code>RunspaceFactory.CreateRunspace</code> that accept a <code>RunspaceConfiguration</code> and also allow me to pass a <code>WSManConnectionInfo</code> to connect to a remote host. Another solution is to call <code>AddScript</code> instead of <code>AddCommand</code>, which seems to not throw an exception, but also didn't seem to do anything without telling me why. I would rather work relatively strongly typed (with AddCommand) rather than pass random strings in.</p> <p>Is there another method that doesn't involve installing modules on the local machine? Or, barring that, how do I install the Exchange 2010 cmdlets locally?</p>
    singulars
    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.
    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