Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ title: about_PSModulePath

## Short description

This article describes the purpose and usage of the `$env:PSModulePath`
This article describes the purpose and usage of the `$Env:PSModulePath`
environment variable.

## Long description

The `$env:PSModulePath` environment variable contains a list of folder
The `$Env:PSModulePath` environment variable contains a list of folder
locations. PowerShell recursively searches each folder for module (`.psd1` or
`.psm1`) files.

By default, the effective locations assigned to `$env:PSModulePath` are:
By default, the effective locations assigned to `$Env:PSModulePath` are:

- Modules installed in the **CurrentUser** scope are stored in
`$HOME\Documents\WindowsPowerShell\Modules`.
- Modules installed in the **AllUsers** scope are stored in
`$env:ProgramFiles\WindowsPowerShell\Modules`.
`$Env:ProgramFiles\WindowsPowerShell\Modules`.
- Modules that ship with Windows PowerShell stored in `$PSHOME\Modules`, which
is `$env:SystemRoot\System32\WindowsPowerShell\1.0\Modules`.
is `$Env:SystemRoot\System32\WindowsPowerShell\1.0\Modules`.

## PowerShell PSModulePath construction

The value of `$env:PSModulePath` is constructed each time PowerShell starts.
The value of `$Env:PSModulePath` is constructed each time PowerShell starts.
The value varies by version of PowerShell and how you launched it.

### Windows PowerShell startup
Expand All @@ -48,8 +48,8 @@ startup:
the `$PSHOME` location

The **CurrentUser** module path is prefixed only if the User scope
`$env:PSModulePath` doesn't exist. Otherwise, the User scope
`$env:PSModulePath` is used as defined.
`$Env:PSModulePath` doesn't exist. Otherwise, the User scope
`$Env:PSModulePath` is used as defined.

## Module search behavior

Expand Down Expand Up @@ -78,7 +78,7 @@ locations. However, you might need to change the value of the `PSModulePath`
environment variable.

For example, to temporarily add the `C:\Program Files\Fabrikam\Modules`
directory to `$env:PSModulePath` for the current session, type:
directory to `$Env:PSModulePath` for the current session, type:

```powershell
$Env:PSModulePath = $Env:PSModulePath+";C:\Program Files\Fabrikam\Modules"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ the here-string, all quotation marks are interpreted literally. For example:

```powershell
@"
For help, type "get-help"
For help, type "Get-Help"
"@
```

The output of this command is:

```Output
For help, type "get-help"
For help, type "Get-Help"
```

Using a here-string can simplify using a string in a command. For example:
Expand Down Expand Up @@ -347,7 +347,7 @@ Here-strings are typically used to assign multiple lines to a variable. For
example, the following here-string assigns a page of XML to the $page variable.

```powershell
$page = [XML] @"
$page = [xml] @"
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10"
xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10"
xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Get-Item /not-here 2>&1 >> log.txt

$ErrorActionPreference = 'Stop'
$ErrorActionPreference >> log.txt
Try {
try {
Get-Item /not-here 2>&1 >> log.txt
}
catch {
Expand Down Expand Up @@ -181,7 +181,7 @@ Can't find path 'C:\not-here' because it doesn't exist.
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): H
Get-Item: C:\temp\test.ps1:23
Line |
23 | get-item /not-here 2>&1 >> log.txt
23 | Get-Item /not-here 2>&1 >> log.txt
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The running command stopped because the user selected the Stop option.
```
Expand All @@ -194,7 +194,7 @@ Continue

Get-Item: C:\temp\test.ps1:3
Line |
3 | get-item /not-here 2>&1 >> log.txt
3 | Get-Item /not-here 2>&1 >> log.txt
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path 'C:\not-here' because it does not exist.

Expand Down Expand Up @@ -252,7 +252,7 @@ redirection operators as well. Put the following command near the top of your
script to set `Out-File:Width` for the whole script:

```powershell
$PSDefaultParameterValues['out-file:width'] = 2000
$PSDefaultParameterValues['Out-File:Width'] = 2000
```

Increasing the output width will increase memory consumption when logging
Expand All @@ -264,7 +264,7 @@ you will need to pipe the output through `Format-Table -AutoSize` before
outputting to file.

```powershell
$PSDefaultParameterValues['out-file:width'] = 2000
$PSDefaultParameterValues['Out-File:Width'] = 2000
Get-Service | Format-Table -AutoSize > services.log
```

Expand Down
18 changes: 9 additions & 9 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ to it. In PowerShell, integers are value types so they're passed by value.
Therefore, the value of `$var` is unchanged outside the scope of the function.

```powershell
Function Test($data)
Function Test($Data)
{
$data = 3
$Data = 3
}

$var = 10
Test -data $var
Test -Data $var
$var
```

Expand All @@ -54,13 +54,13 @@ When passing a variable _by reference_, the function can change the data and
that change persists after the function executes.

```powershell
Function Test($data)
Function Test($Data)
{
$data.Test = "New Text"
$Data.Test = "New Text"
}

$var = @{}
Test -data $var
Test -Data $var
$var
```

Expand All @@ -84,8 +84,8 @@ access your data.

```powershell
function Test {
param([ref]$data)
$data.Value = 3
param([ref]$Data)
$Data.Value = 3
}
```

Expand All @@ -97,7 +97,7 @@ your variable as a reference.

```powershell
$var = 10
Test -data ([ref]$var)
Test -Data ([ref]$var)
$var
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ContosoCompany registry key.

```powershell
$path = "HKLM:\SOFTWARE\ContosoCompany"
New-ItemProperty -Path $path -Name Test -Type DWORD -Value 1
New-ItemProperty -Path $path -Name Test -Type DWord -Value 1
```

> [!NOTE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ input strings.
There's a static method of the regex class that can escape text for you.

```powershell
[regex]::escape('3.\d{2,}')
[regex]::Escape('3.\d{2,}')
```

```Output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ in the same PSSession that uses the `$p` variable. The following command counts
the number of processes saved in `$p`.

```powershell
Invoke-Command -Session $s -ScriptBlock {$p.count}
Invoke-Command -Session $s -ScriptBlock {$p.Count}
```

## How to run a remote command on multiple computers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ all of the operations occur on the remote computer, not the local computer.
results of the job in the PsLog.txt file on the Server01 computer.

```powershell
Server01\C:> Receive-Job $job > c:\logs\PsLog.txt
Server01\C:> Receive-Job $job > C:\logs\PsLog.txt
```

1. To end the interactive session, use the `Exit-PSSession` cmdlet. The command
Expand All @@ -164,7 +164,7 @@ all of the operations occur on the remote computer, not the local computer.
```powershell
$s = New-PSSession -ComputerName Server01
Invoke-Command -Session $s -ScriptBlock {
Get-Content c:\logs\pslog.txt}
Get-Content C:\logs\pslog.txt}
```

### Start a remote job that returns the results to the local computer (AsJob)
Expand All @@ -189,16 +189,16 @@ requirements for remoting.
assign a display name to the job.

```powershell
Invoke-Command -Computername Server01 -ScriptBlock {
Get-EventLog system} -AsJob
Invoke-Command -ComputerName Server01 -ScriptBlock {
Get-EventLog System} -AsJob
```

The results of the command resemble the following sample output.

```Output
SessionId Name State HasMoreData Location Command
--------- ---- ----- ----------- -------- -------
1 Job1 Running True Server01 Get-EventLog system
1 Job1 Running True Server01 Get-EventLog System
```

When the **AsJob** parameter is used, `Invoke-Command` returns the same type
Expand Down Expand Up @@ -228,7 +228,7 @@ requirements for remoting.
```Output
SessionId Name State HasMoreData Location Command
--------- ---- ----- ----------- -------- -------
1 Job1 Completed True Server01 Get-EventLog system
1 Job1 Completed True Server01 Get-EventLog System
```

1. To get the results of the job, use the `Receive-Job` cmdlet. Because the job
Expand Down Expand Up @@ -279,15 +279,15 @@ commands remotely to manage a local job on the remote computer.

```powershell
Invoke-Command -Session $s -ScriptBlock {
Start-Job -ScriptBlock {Get-EventLog system}}
Start-Job -ScriptBlock {Get-EventLog System}}
```

The results resemble the following sample output.

```Output
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
2 Job2 Running True Localhost Get-EventLog system
2 Job2 Running True Localhost Get-EventLog System
```

When you run a `Start-Job` command remotely, `Invoke-Command` returns the
Expand Down Expand Up @@ -318,7 +318,7 @@ commands remotely to manage a local job on the remote computer.
```Output
SessionId Name State HasMoreData Location Command
--------- ---- ----- ----------- -------- -------
2 Job2 Completed True LocalHost Get-EventLog system
2 Job2 Completed True LocalHost Get-EventLog System
```

1. To get the results of the job, use the `Invoke-Command` cmdlet to run a
Expand All @@ -342,7 +342,7 @@ commands remotely to manage a local job on the remote computer.

```powershell
Invoke-Command -Session $s -Command {
Receive-Job -SessionId 2 > c:\logs\pslog.txt
Receive-Job -SessionId 2 > C:\logs\pslog.txt
}
```

Expand All @@ -363,7 +363,7 @@ objects generated after the disconnect are returned when re-connected.

```powershell
# Create remote session on local machine
PS> $session = New-PSSession -cn localhost
PS> $session = New-PSSession -Cn localhost

# Start remote job
PS> $job = Invoke-Command -Session $session -ScriptBlock { 1..60 | % { sleep 1; "Output $_" } } -AsJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Administrator privileges are required for the following remoting operations:
known as a "loopback" scenario.
- Managing session configurations on the local computer.
- Viewing and changing WS-Management settings on the local computer. These are
the settings in the LocalHost node of the WSMAN: drive.
the settings in the LocalHost node of the WSMan: drive.

You must start PowerShell with the **Run as administrator** option even if you
are a member of the **Administrators** group on the local computer.
Expand Down
Loading