Last active
October 5, 2022 13:09
-
-
Save Stephanevg/b255a77da774e0ef042c614f8be154e5 to your computer and use it in GitHub Desktop.
functions to add / remove paths to the $psmodulePath environment variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-FromPSModulePath{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true)][String]$Path="C:\admin\modules" | |
) | |
if ($env:PSModulePath.split(";") -contains $Path){ | |
$NewValue = (($env:PSModulePath).Split(";") | ? { $_ -ne $Path }) -join ";" | |
[Environment]::SetEnvironmentVariable("PSModulePath", $NewValue, "Machine") | |
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine") | |
write-verbose "$Path removed. Restart the prompt for the changes to take effect." | |
}else{ | |
write-verbose "$Path is not present in $env:psModulePath" | |
} | |
} | |
Function Add-TooPSModulePath { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true)][String]$Path | |
) | |
if (!($env:PSModulePath.split(";") -contains $Path)){ | |
$Current = $env:PSModulePath | |
[Environment]::SetEnvironmentVariable("PSModulePath",$Current + ";" + $Path, "Machine") | |
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine") | |
}else{ | |
write-verbose "$Path is already present in psMOdulePath $env:psModulePath" | |
} | |
} | |
Function Set-PSModulePathDefaults{ | |
[cmdletbinding()] | |
Param() | |
[Environment]::SetEnvironmentVariable("PSModulePath","","Machine") | |
$env:PSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath","Machine") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment