GPO PSModulePath

I am trying to add a line to the $env:psmodulepath for every technicians workstation in my workplace so they have access to the custom modules. I have a script with one line that I have tested on my local workstation and works without issue. All technicians have access to this S: drive:

$env:PSModulePath = $env:PSModulePath + “;S:\TechPro\TPModules\TPUserMod”

I created the GPO “Set-TPPSModulePath” within User Configuration -> Scripts -> Login -> PowershellScripts Tab -> Browsed to my script on the domain controller -> Selected “Run Windows PowerShell scripts last”

I pushed policy on the Domain Controller and my local workstation.

When I run GPresults /R, I see that the policy was applied to my workstation, however running $env:psmodulepath, I do not see the new path.
<p style=“text-align: left;”>PS C:\Users\bclanton\Google Drive\Code> $env:PSModulePath.split(’;’)
C:\Program Files\WindowsPowerShell\Modules
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization</em>
C:\Program Files\Microsoft DaRT\v10\Modules</em>
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell</p>
Even when I UNC to this location and run it, it will not add the path when I launch it from the share on the domain controller.

I do not want to wipe what is already existing on this system variable, but just append it with a path to our server.

Is it possible to do this with this method?











Rather than troubleshoot GPOs, there’s a much simpler method for distributing internal modules. Powershell MVP Kevin Marquette describes the super simple process to get started here - including a simple UNC share:

The link you reference still leaves the issue of adding the path of the module to the $env:psmodulepath, doesn’t it? This is the part from your link that I would want to automate without having to touch each machine.


Publishing updated modules

If you want to update a module that you have published, make sure you update the version number in your module manifest. I personally try to use semantic versioning.

You also need to make sure you place this in the $env:PSModulePath and don’t have any other conflicting installs of your module.

Gotcha - have you tried using the [environment] class? This script would add “C:\Program Files\MyPath\Modules” to the machine env variable. For user, specify “User” instead of “Machine”

$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Program Files\MyPath\Modules", "Machine")

Hi Brian,

Another alternative to using the environment class.

$env:PSModulePath += ‘;C:\Program Files\myPath\Modules’


If you look at my original post, this was the issue I was having with applying this via GPO.


$env:PSModulePath = $env:PSModulePath + “;S:\TechPro\TPModules\TPUserMod”

I can maybe create a script with Nathanial’s suggestion and invoke this script to all machines in the domain.


$CurrentValue = [Environment]::GetEnvironmentVariable(“PSModulePath”, “Machine”)
[Environment]::SetEnvironmentVariable(“PSModulePath”, $CurrentValue + “;C:\Program Files\MyPath\Modules”, “Machine”)


Sorry Brian, my mistake. If Nathaniel’s suggestion does not work, you can try adding -ExecutionPolicy Bypass to the script parameter field in the GPO. Although not required, and should run it bypass, setting this will force it.