WindowsPSModulePath.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<#
.SYNOPSIS
 
Appends the existing Windows PowerShell PSModulePath to existing PSModulePath
 
.DESCRIPTION
 
If the current PSModulePath does not contain the Windows PowerShell PSModulePath, it will
be appended to the end.
 
.INPUTS
 
None.
 
.OUTPUTS
 
None.
 
.EXAMPLE
 
C:\PS> Add-WindowsPSModulePath
C:\PS> Import-Module Hyper-V
 
.EXAMPLE
 
C:\PS> Add-WindowsPSModulePath
C:\PS> Get-Module -ListAvailable
#>


function Add-WindowsPSModulePath
{

    if (! $IsWindows)
    {
        throw "This cmdlet is only supported on Windows"
    }

    $WindowsPSModulePath = [System.Environment]::GetEnvironmentVariable("psmodulepath", [System.EnvironmentVariableTarget]::Machine)
    if (-not ($env:PSModulePath).Contains($WindowsPSModulePath))
    {
        $env:PSModulePath += ";${env:userprofile}\Documents\WindowsPowerShell\Modules;${env:programfiles}\WindowsPowerShell\Modules;${WindowsPSModulePath}"
    }

}