dynamic - Dynamically create a cmdlets/module in PowerShell -


this want achieve , can't find this.

i want create remote module proxy, module available on remote server.

i know how work remoting want creates cleaner script files.

to give example. if want execute mycmdlet module mymodule on remote computer this

$block={     # invoke cmdlet module named mycmdlet     mycmdlet -parameter1 -parameter2 }  invoke-command -computername "" -scriptblock $block 

but land

import-module mymoduleremote mycmdlet -computername "" -parameter1 -parameter2 

please noticed mymodule not installed on client machine.

i re-write module invoke-command wrapper each cmdlet not purpose. remot-ify mymodule creating proxy equal proxy per cmdlet , parameter. get-help should work @ least parameter composition.

i have couple of ideas i'm not sure if possible.

  1. create powershell module e.g. psremotify probe module on remote server , generate code.
    1. if chose write files file system should possible, if reflection on cmdlets.
    2. if don't want save files need in memory. can write cmdlet's body in memory? can generate string , import embedded cmdlet?
  2. create script 1.2.

my preference option 1.2. clean , without leaving traces on file system.

any ideas? has tried already?

conclusion after investigation , answer @persistent13:

powershell offer feature out of box. known implicit remoting. before @persistent13's answer took wrong part because think interesting share experience, i've blogged it. import , use module remote server

it sounds looking implicit remoting , simple set up.

please note i've taken instructions here.

to create implicit session would:

ps c:\> $foo = new-pssession -computername dc1 ps c:\> import-module -pssession $foo -name activedirectory ps c:\> get-aduser 

the above open powershell session on computer dc1, import activedirectory module on remote computer, , command run against remote computer while appears executed locally.

it possible prefix implicitly imported modules in case local module conflict remote one.

ps c:\> $foo = new-pssession -computername dc1 ps c:\> import-module -pssession $foo -name activedirectory -prefix dc1 ps c:\> get-dc1aduser 

the advantage of there no need remot-ify module , long present on remote computer , powershell remoting allowed.

however 1 caveat of method type of object returned change.

deserialized.microsoft.activedirectory.management.aduser when implicit remoting used.

microsoft.activedirectory.management.aduser when run locally.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -