Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up hacking this to work. What I did was create a local session, import modules into that session and used import-pssession to import modules from the created local session into the remote session. This is slow. If anyone has a better way of doing this, or if someone knows how to get an instance of the base session I'd love to hear from you!</p> <p>Remoting.psm1</p> <pre><code>function Export-ModuleToSession { Param( [ValidateNotNull()] $session, [ValidateNotNull()] $modules ) $computername = $env:computername $modulesToImport = get-module -name $modules invoke-command -session $session -argumentlist @($computername, $modulesToImport) -scriptblock { Param( $computername, $modules ) write-host ("Creating Temp Session On: " + $computername) $localSession = New-psSession -computername $computername $modules | foreach-object { if($_.ModuleType -ne "Binary") { $path = $_.path } else { $path = join-path (split-path $_.Path) ("{0}.psd1" -f $_.name) } invoke-command -session $localSession -argumentList $path -scriptblock { Param( $path ) $initializeDefaultBTSDrive = $false set-executionpolicy unrestricted write-host ("Importing Module To Temp Session: " + $path) import-module $path } } $initializeDefaultBTSDrive = $false $modules | foreach-object { write-host ("Exporting Module: " + $_.name) import-psSession -session $localSession -Module $_.name | out-null } } } </code></pre> <p>MyModule.psm1</p> <pre><code>function MyCmdlet {} </code></pre> <p>RemotingTest.ps1</p> <pre><code>import-module .\remoting.psm1 import-module .\MyModule.psm1 try { $remoteSession = New-PsSession -computerName "RemoteComputer" Export-ModuleToSession -session $remoteSession -modules "MyModule" Invoke-Command -session $remoteSession -scriptblock { MyCmdlet } -verbose -ea Stop } finally { Remove-PsSession $remoteSession -ea Continue Remove-Module "Remoting" -ea Continue Remove-Module "MyModule" -ea Continue } </code></pre>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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