Execute remote exchange powershell command with C# -
i can execute powershell command on remote machine, , can execute powershell exchange snapin commands, can't figure out how both. issue resides in runspacefactory.createrunspace()
method.
a wsmanconnectioninfo object lets me target remote host so:
wsmanconnectioninfo connectioninfo = new wsmanconnectioninfo( new uri(configurationmanager.appsettings["exchangeserveruri"]), "http://schemas.microsoft.com/powershell/microsoft.exchange", new pscredential(username, securestring));
and runspaceconfugation + pssnapininfo lets me target snapin so:
runspaceconfiguration rsconfig = runspaceconfiguration.create(); pssnapinexception snapinexception = null; pssnapininfo info = rsconfig.addpssnapin("microsoft.exchange.management.powershell.admin", out snapinexception);
but can feed 1 or other createrunspace(). runtime object returns has properties connectioninfo , runspaceconfiguration, they're both readonly. intentional design can't remotely execute code powershell snapins, or there way i'm missing?
one thing can define remoting endpoint (on remote machine) configures have desired pssnapin loaded e.g.:
register-pssessionconfiguration -name exadminshell -startupscript initscript.ps1
then connect endpoint.
another thought, not work if add add-pssnapin top of script you're going run on remote machine? keep in mind snapins bit-specific if connecting 32-bit endpoint snapin better 32-bit , registered. ditto 64-bit snapin.
Comments
Post a Comment