The `PSModulePath
` environmental variable contains a list of paths where the PowerShell modules are stored. You can use the -Split
operator to split the variable path into a list of strings, separated by semicolons.
$env:PSModulePath -split ';'
The output of the above PowerShell script returns a list of strings which are the paths to the default PowerShell module directories.
PS C:\> $env:PSModulePath -split ';'
C:\Users\administrator\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
c:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\
C:\Program Files (x86)\Microsoft SQL Server\150\Tools\PowerShell\Modules\
C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell
PowerShell modules are stored in different directories such as
- C:\Users\administrator\Documents\ – stores the modules when you installed the module with the scope -CurrentUser.
- C:\Program Files\ – stores the modules when AllUsers scope is provided.
- C:\WINDOWS\system32\ – this path is the default path for the module.
You can also add custom module directories to the PSModulePath environmental variable. This can be helpful if you want to install modules in a different location.
For example, if you have installed a module in the C:\PSModules
directory, you can add that directory to the PSModulePath
environmental variable by running the following command.
$env:PSModulePath += ';C:\PSModules'
Cool Tip: How to list installed modules in PowerShell!
Conclusion
I hope the above article on how to get module path in PowerShell using the PSModulePath
environmental variable is helpful to you.
You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.