locked
Import-module problem while running a script in remote machine RRS feed

  • Question

  • I have written a script that will execute a script in the remote machine. The script in the remote machine imports other modules like 

    Import-Module -Name "..\lib\commonlib.psm1".

    Now when the script in the remote machine is invoked, there is any error 

    Import-Module : The specified module '..\lib\commonlib.psm1' was not loaded
    because no valid module file was found in any module directory(directory lib and commonlib.psm1 are present in the correct path)

    How can this issue be resolved?

    Below is the command to run the script in the remote machine.

    $job = "c:\scripts\test.ps1"
    $cmdRes = Invoke-Command -ComputerName $remoteMachineName  -ScriptBlock {& $args[0]} -ArgumentList $job -AsJob

    Thanks

    Jugari

    • Moved by Bill_Stewart Monday, December 30, 2013 8:29 PM Abandoned thread
    Thursday, September 19, 2013 5:25 AM

All replies

  • Type the following:

    HELP Import-Module -Full

    Read it very carefully.  YOU want to note how modules are found and installed.  It is not by path.

    A module must be installed into the modules folder(s).  There is one for the system and one for the user. Proper deployment of modules is critical.


    ¯\_(ツ)_/¯

    Thursday, September 19, 2013 5:44 AM
  • You can also import a remote module into a remote session.

    Import-Module MyModule -PSSession $session
    Invoke-Command -Session $session -FilePath c:\scripts\test.ps1 -ArgumentList $arglist

    The file is local and is sent to the remote session.


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, September 19, 2013 5:58 AM
    Thursday, September 19, 2013 5:50 AM
  • This command will tell you what modules are available for loading:

    Invoke-Command -Session $session -ScriptBlock {get-module -ListAvailable }


    ¯\_(ツ)_/¯

    Thursday, September 19, 2013 6:15 AM