PowerShell stores paths in PSModulePath to locate modules. While installing ISESteroids on my Surface Pro 3 (for writing code on the go), I noticed that the module’s Start-Steroids cmdlet failed to launch because a path to my user profile could not be found. Upon further investigation, I noticed my user path was completely missing from PSModulePath.
If you check $Env:PSModulePath, you should find these paths loaded:
$PSHome\Modules $Home\Documents\WindowsPowerShell\Modules $Env:ProgramFiles\WindowsPowerShell\Modules
Want to get even more into the weeds? Check the environmental variable based on the environment type: user, machine, and process.
[Environment]::GetEnvironmentVariable('PSModulePath','User').split(";") [Environment]::GetEnvironmentVariable('PSModulePath','Machine').split(";") [Environment]::GetEnvironmentVariable('PSModulePath','Process').split(";")
Because I have PowerCLI installed, there is an additional path from the ones I listed initially:
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules
But my $Home based path is missing. This is the friendly place to drop in per-user modules and profile data. I’ve talked about it a bit further in my ISE setup post. Microsoft has a short script that can fix this which I have pasted below. If you’re not missing the user path, replace your missing path with the one shown in line 4.
Save the current value in the $p variable. $p = Environment::GetEnvironmentVariable('PSModulePath','User') Add the new path to the $p variable. Begin with a semi-colon separator. $p += ";$Home\Documents\WindowsPowerShell\Modules" Add the paths in $p to the PSModulePath value.
Another look at the PSModulePath now shows my $Home (Chris) user path.
And now my custom modules, including ISESteroids, will launch because PowerShell knows where the module lives. Even Intellisense is now happy. 🙂