I'm trying to create a central repository for our company's modules. What I've done so far:
Shared the module folder on the script server as read only
C:\Program Files\WindowsPowerShell\Modules
→ shared as\\SERVER1\PS Modules
Started a new PS session to the second server with
Enter-PSsession SERVER2
On
SERVER2
I ran the following code found on the MS website:Function Add-ModulePath { [CmdletBinding(SupportsShouldProcess=$True)] Param( [parameter(Mandatory=$true,Position=0)] [ValidateNotNullOrEmpty()] [String]$Path ) Process { if ($env:PSModulePath -like "*$Path*") { Write-Verbose "Add-ModulePath: Path '$Path' already present" } else { Write-Verbose "Add-ModulePath: Adding path '$Path' to the modules" #Save the current value in the $p variable. $p = [Environment]::GetEnvironmentVariable("PSModulePath") #Add the new path to the $p variable. Begin with a semi-colon separator. $p += ";$Path" #Add the paths in $p to the PSModulePath value. [Environment]::SetEnvironmentVariable("PSModulePath",$p) } } } Add-ModulePath -Path '\\SERVER1\PS Modules\' -Verbose
When I now try to do Get-Module -ListAvailable
within the remote session to SERVER2 it doesn't show me the modules from the network share, although the network share shows up in $env:PSModulePath
. SERVER2 is running PowerShell v2.0, but this doesn't matter I think. According to Microsoft I should "broadcast an environment message", but I don't know how to do this.
What we want to achieve is to have this module repo available to all servers in the park, so they all use the same modules when executing scripts.
When we try to load the module from the network share manually within the remote session, it says it can't be found. Although we can browse it perfectly fine from that machine:
[SERVER2]: PS C:\Documents and Settings\user\My Documents> Import-Module '\\SERVER1\PS Modules\Toolbox.General\Toolbox.General.psm1' -Verbose
Import-Module : The specified module '\\SERVER1\PS Modules\Toolbox.General\Toolbox.General.psm1' was not loaded because no valid module file was found in any module directory.
+ CategoryInfo : ResourceUnavailable: (\\SERVER1...ox.General.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
When loading the module from an RDP session on SERVER2 it does work. So this might be related to the double hop issue..
How is it possible to load modules from a network share within a remote session?
My question is very much related to this, but I refuse to copy the modules to all the servers. I would like to have them available from one central location.