EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Powershell Module Path

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » Powershell Module Path

Powershell Module Path

Introduction to Powershell Module Path

The locations of the modules that are currently installed on the system are stored in the PSModulePath environment variable. There are two important ways of expanding the PowerShell cmdlets; they are Modules and Snapins. Both are packages of cmdlets and functions. Snapins were the first ones to be developed, and they were introduced with PowerShell version 1, whereas modules were introduced in PowerShell version 2. Snapins are being deprecated. Snapins are defined in assemblies, whereas modules are defined in assemblies or PowerShell scripts. Both snapins and modules are nothing but a package of cmdlets, functions, variables, and workflows. The registered snapins can find out by using the “Get-PSSnapin-registered” cmdlet. The list of available modules installed can find out by using the “Get-Module –ListAvailable” cmdlet. This article will cover Powershell Module Path in detail.

 List of Modules available at Directory: C:\Program Files\WindowsPowerShell\Modules

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

ModuleType Version Name
Script 1.0.1 Microsoft.PowerShell.Operation.Validation
    Binary 1.0.0.1 PackageManagement
    Script 3.4.0 Pester
    Script 1.0.0.1 PowerShellGet
    Script 1.2 PSReadline

List of Modules available at Directory Directory:C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version Name
  Manifest 1.0.0.0 AppBackgroundTask
  Manifest 2.0.0.0 AppLocker
  Manifest 1.0.0.0 AppvClient
  Manifest 2.0.0.0 Appx
    Script 1.0.0.0 AssignedAccess
  Manifest 1.0.0.0 BitLocker
  Manifest 2.0.0.0 BitsTransfer
  Manifest 1.0.0.0 BranchCache
  Manifest 1.0.0.0 CimCmdlets
  Manifest 1 ConfigCI
  Manifest 1 Defender
  Manifest 1.0.0.0 DeliveryOptimization
  Manifest 1.0.0.0 DirectAccessClientComponents
    Script 3 Dism
  Manifest 1.0.0.0 DnsClient
  Manifest 1.0.0.0 EventTracingManagement
  Manifest 2.0.0.0 International
  Manifest 1.0.0.0 iSCSI
    Script 1.0.0.0 ISE

 To get only the modules that are available in the current session, the cmdlet “Get-Module -All” is used. Any module can be imported into a session with the help of the Import-Module cmdlet.

Modules in the current session:

ModuleType Version Name                                        
    Script 1.0.0.0 ISE
    Binary 3.0.0.0 Microsoft.PowerShell.Commands.Management.dll
    Binary 3.0.0.0 Microsoft.PowerShell.Commands.Utility.dll
  Manifest 3.1.0.0 Microsoft.PowerShell.Management
    Script 0 Microsoft.PowerShell.Utility
  Manifest 3.1.0.0 Microsoft.PowerShell.Utility

Example:

Import-Module -Name PSDiagnostics

The verbose parameter can be used to know about the cmdlets and functions available in the module while the module is being imported.

To remove the module from the session, the below cmdlet can be used

Remove-Module-Name PSDiagnostics. The verbose parameter can be used here also.

PSModulePath:

The PSModulePath is an environment variable stores the address of the modules that are installed on the system. When the user is not aware of the path of the module or doesn’t specify, PowerShell uses this variable to locate them. To view the modules that are stored, execute the following cmdlet.

Popular Course in this category
Sale
Shell Scripting Training (4 Courses, 1 Project)4 Online Courses | 1 Hands-on Project | 18+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,751 ratings)
Course Price

View Course

Related Courses
All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)

Syntax:

$env:PSModulePath

Output:

Powershell Module Path output 1

The default value of the $env:PSModulePath is one of the following values

  • $HOME\Documents\PowerShell\Modules;
  • $PSHOME\Modules or $HOME\Documents\WindowsPowerShell\Modules;
  • $PSHOME\Modules

Working with PSModulePath

A temporary new path or location can be added to the PSModulePath as follows.

$env:PSModulePath = $env:PSModulePath + ";c:\windows\test"

A new variable to the registry can be added by using the environment variable editor.

To add a new variable using the script, the SetEnvironmentVariable method of the Environment class must be used.

$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\vignesh\test", "Machine")

To remove path or location from the PSModulePath, the replace parameter can be used.

$env:PSModulePath -replace ";c:\windows\test".

The above cmdlet will remove c:\windows\test from modulepath.

Enabling Automatic Import of Modules:

By default, the modules that are available in the PSModulePath are only imported in a session. To import modules from other locations, the Import-Module cmdlet must be used. $PSModuleAutoloadingPreference is the parameter that determines whether modules are to be automatically imported or not. Its acceptable values are All, ModuleQualified, and None.

All: It is the default value. Modules are imported for first-time use.

ModuleQualified: Only if the user specifies a module, then it is imported.

None: Modules are not automatically imported. E.g. $PSModuleAutoloadingPreference = ‘none’

Examples:

To add a new location of a module to PSModulePath.

Input :                                                                                                   

Function Add-ToPSModulePathEg {
[CmdletBinding()] Param(
[Parameter(Mandatory=$true)][String]$ModulePath
)
Write-Host "Add a path tutorial"
if (!($env:PSModulePath.split(";") -contains $ModulePath)){
$Current = $env:PSModulePath
[Environment]::SetEnvironmentVariable("PSModulePath",$Current + ";" + $ModulePath, "Machine")
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")
Write-Host "Path Added"
}else{
Write-Host "$ModulePath is already available in psMOdulePath $env:psModulePath"
}
}

Steps on how to run the script:

The above script is a function. So parameters need to be passed to it.

First, run the script.

In the output pane, type Add-ToPSModulePathEg – ModulePath “Path to be added here.”

See the below output screen for reference

Output:

Powershell Module Path output 2

In the above output, if you see when the first time the script is run. The path, if it is not there already in the ModulePath, will be added, and Add a path tutorial will be printed along with the path added. If the script is run for the same path again, then the second output, “Test4 is already available,” is printed.

To remove a path from PSModulePath:

Input:

function Remove-FromPSModulePathEg{
[CmdletBinding()] Param(
[Parameter(Mandatory=$true)][String]$ModulePath
)
Write-Host "Removing a path from PSModulePath Variable"
if ($env:PSModulePath.split(";") -contains $ModulePath){
$NewValue = (($env:PSModulePath).Split(";") | ? { $_ -ne $ModulePath }) -join ";"
[Environment]::SetEnvironmentVariable("PSModulePath", $NewValue, "Machine")
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")
write-Host "$ModulePath removed. Restart the prompt for the changes to take effect."
}else{
write-Host "$ModulePath is not present in $env:psModulePath"
}
}

Steps on how to run the script:

The above script is a function. So parameters need to be passed to it.

First, run the script.

In the output pane, type FromPSModulePathEg – ModulePath “Path to be deleted here.”

See the below output screen for reference

Output:

output 3

In the above output, first, the above-added path is removed. Next, removing a path from the output is produced. Finally, the second time the script is run for the removed path, the path that is not present is produced.

Adding Multiple Locations to the PSModulePath Simultaneously

Input:

Write-Host "Welcome to adding multiple paths to the PSModulePath Environment Variable"
#storing the paths to be added in an array
$address=@("C:\Vignesh\test","C:\Vignesh\Tickets","C:\Vignesh\Patching","C:\Vignesh\Training Screenshots" )
foreach($add in $address)
{
Write-Host "Adding the path" $add "to the PSModulePath Variable"
$env:PSModulePath = $env:PSModulePath +";$add"
Write-Host "Path added"
Write-Host "Current value of PSModulePath is "$env:PSModulePath
}

Output:

output 4

Removing Multiple Paths from the PSModulePath Simultaneously:

Input:

Write-Host "Welcome to deleting multiple paths from the PSModulePath Environment Variable"
Write-Host "Current Value in PSModulePath is" $env:PSModulePath
#storing the paths to be removed from the location
$address=@("C:\Vignesh\test","C:\Vignesh\Tickets","C:\Vignesh\Patching","C:\Vignesh\Training Screenshots" )
foreach($add in $address)
{
if ($env:PSModulePath.split(";") -contains $add){
Write-Host "Removing the path" $add
$NewValue = (($env:PSModulePath).Split(";") | ? { $_ -ne $add }) -join ";"
[Environment]::SetEnvironmentVariable("PSModulePath", $NewValue, "Machine")
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")
write-Host "$add removed"
}
}

Output:

output 5

Conclusion – Powershell Module Path

Thus, the article covered in detail the PSModulePath environment variable. It also explained the difference between the module and snapin. Some key points to be noted are when auto-loading of the module is enabled; it should be taken care that the first position has the required module. In the case of multiple versions for the same module, PowerShell, by default, uses the latest version of the module. It also demonstrated examples of how to add and remove to a PSModulePath variable. To learn in-depth about the cmdlet, creating sample programs, and having fun working around them is advisable.

Recommended Articles

This is a guide to Powershell Module Path. Here we discuss the PSModulePath environment variable and detail about the PSModulePath environment variable. It also explained. You may also look at the following articles to learn more –

  1. PowerShell null
  2. PowerShell New Line
  3. PowerShell ZIP
  4. PowerShell Location

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Shell Scripting Course Learn More