Skip to content

Commit 6ea9b33

Browse files
🌟 [Feature]: Add Add-PSModulePath function to modify PSModulePath environment variable
1 parent aaed998 commit 6ea9b33

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎scripts/Helpers/Helpers.psm1‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,3 +1078,33 @@ filter Format-Hashtable {
10781078

10791079
return $lines -join [Environment]::NewLine
10801080
}
1081+
1082+
function Add-PSModulePath {
1083+
<#
1084+
.SYNOPSIS
1085+
Adds a path to the PSModulePath environment variable.
1086+
1087+
.DESCRIPTION
1088+
Adds a path to the PSModulePath environment variable.
1089+
For Linux and macOS, the path delimiter is ':' and for Windows it is ';'.
1090+
1091+
.EXAMPLE
1092+
Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules'
1093+
1094+
Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable.
1095+
#>
1096+
[CmdletBinding()]
1097+
param(
1098+
# Path to the folder where the module source code is located.
1099+
[Parameter(Mandatory)]
1100+
[string] $Path
1101+
)
1102+
$PSModulePathSeparator = [System.IO.Path]::PathSeparator
1103+
1104+
$env:PSModulePath += "$PSModulePathSeparator$Path"
1105+
1106+
Write-Verbose 'PSModulePath:'
1107+
$env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object {
1108+
Write-Verbose " - [$_]"
1109+
}
1110+
}

0 commit comments

Comments
 (0)