none
Share Modules on Domain

    Question

  • I currently have a logon script that copies the modules to the users  "Documents\WindowsPowerShell\Modules" folder. This works great if I am sitting at the users computer.

    When I try to do remote commands using invoke-command or Enter-PSsession I do not see what is in the users " Documents\WindowsPowerShell\Modules" folder. 

    So the modules from  "USER\Documents\WindowsPowerShell\Modules" do not load. It tries to load "Admin\Documents\WindowsPowerShell\Modules"

    If I could have the modules installed to "C:\Program Files\WindowsPowerShell\Modules" I believe that would work but I can not copy to the Program Files folder in Group Policy.

    I can edit the PSModulepath locally or through Group Policy but that does not help me when I run commands remotely. 

    The path does not change for me as an admin just for the user so when I run Enter-PsSession and check  $env:PSModulePath  I do not see the folder I setup on the C drive. If I sit in front of that computer and run  $env:PSModulePath then I will see "C\scripts"  and all my modules work locally. 

    How do others share Modules on a small scale? 

    Thursday, June 14, 2018 11:52 PM

All replies

  • Yes.  The variable is not set in a remote session.

    Try this

    import-module $env:USERPROFILE\documents\WindowsPowerShell\Modules\rds-manager\rds-manager.psm1


    \_(ツ)_/

    Friday, June 15, 2018 12:23 AM
    Moderator
  • Of course if the user actually has modules then then path will reflect this.  I have my documents folder redirected to a server and all modules are always available on any host I remote into.  If you don't redirect the documents folder than there is no way of knowing what is installed on any remote system under your account.


    \_(ツ)_/

    Friday, June 15, 2018 12:32 AM
    Moderator
  • Would I have to create the rds-manager.psm1 file? 

    For now I found a script that I can use when needed to copy the files and that should work until I find a better solution

    Friday, June 15, 2018 3:11 PM
  • It is just an example.  I suggest that you start by learning PowerShell.  Most of your issues are caused by basic PS knowledge.


    \_(ツ)_/

    Friday, June 15, 2018 3:15 PM
    Moderator
  • Well obviously that is what I am doing. 
    Friday, June 15, 2018 4:50 PM
  • Well obviously that is what I am doing. 

    The module path will be available in remote sessions if it is set up correctly.  When using a module with an explicit load by path specify the full pathname to the module file as I have shown in the example.

    Find a book or on PowerShell and review how PS uses modules. You can also search for blogs that explain this.

    The "PsModulePath" can be dynamically altered at runtime but will not be persistent.

    You can alter the system module path variable using Group Policy and it will apply to all users.


    \_(ツ)_/

    Friday, June 15, 2018 6:09 PM
    Moderator