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 @@ -160,7 +160,7 @@ two cases for that meet this criteria.

```powershell
(Measure-Command {
1..1000 | ForEach { Start-ThreadJob { Write-Output "Hello $using:_" } } | Receive-Job -Wait
1..1000 | foreach { Start-ThreadJob { Write-Output "Hello $Using:_" } } | Receive-Job -Wait
}).TotalMilliseconds
36860.8226

Expand All @@ -170,13 +170,13 @@ two cases for that meet this criteria.
7.1975
```

The first example above shows a foreach loop that creates 1000 thread jobs to
The first example above shows a `foreach` loop that creates 1000 thread jobs to
do a simple string write. Due to job overhead, it takes over 36 seconds to
complete.

The second example runs the `ForEach` cmdlet to do the same 1000 operations.
This time, `ForEach-Object` runs sequentially, on a single thread, without any
job overhead. It completes in a mere 7 milliseconds.
The second example runs the `ForEach-Object` cmdlet to do the same 1000
operations. This time, `ForEach-Object` runs sequentially, on a single thread,
without any job overhead. It completes in a mere 7 milliseconds.

In the following example, up to 5000 entries are collected for 10 separate
system logs. Since the script involves reading a number of logs, it makes sense
Expand All @@ -201,9 +201,9 @@ The script completes in half the time when the jobs are run in parallel.

```powershell
Measure-Command {
$logs = $logNames | ForEach {
$logs = $logNames | foreach {
Start-ThreadJob {
Get-WinEvent -LogName $using:_ -MaxEvents 5000 2>$null
Get-WinEvent -LogName $Using:_ -MaxEvents 5000 2>$null
} -ThrottleLimit 10
} | Wait-Job | Receive-Job
}
Expand All @@ -218,29 +218,29 @@ $logs.Count
There are multiple ways to pass values into the thread-based jobs.

`Start-ThreadJob` can accept variables that are piped to the cmdlet, passed in
to the script block via the `$using` keyword, or passed in via the
to the script block via the `Using:` scope modifier, or passed in via the
**ArgumentList** parameter.

```powershell
$msg = "Hello"

$msg | Start-ThreadJob { $input | Write-Output } | Wait-Job | Receive-Job

Start-ThreadJob { Write-Output $using:msg } | Wait-Job | Receive-Job
Start-ThreadJob { Write-Output $Using:msg } | Wait-Job | Receive-Job

Start-ThreadJob { param ([string] $message) Write-Output $message } -ArgumentList @($msg) |
Start-ThreadJob { param ([string] $Message) Write-Output $Message } -ArgumentList @($msg) |
Wait-Job | Receive-Job
```

`ForEach-Object -Parallel` accepts piped in variables, and variables passed
directly to the script block via the `$using` keyword.
directly to the script block via the `Using:` scope modifier.

```powershell
$msg = "Hello"

$msg | ForEach-Object -Parallel { Write-Output $_ } -AsJob | Wait-Job | Receive-Job

1..1 | ForEach-Object -Parallel { Write-Output $using:msg } -AsJob | Wait-Job | Receive-Job
1..1 | ForEach-Object -Parallel { Write-Output $Using:msg } -AsJob | Wait-Job | Receive-Job
```

Since thread jobs run in the same process, any variable reference type passed
Expand All @@ -255,10 +255,10 @@ the process.

```powershell
$threadSafeDictionary = [System.Collections.Concurrent.ConcurrentDictionary[string,object]]::new()
$jobs = Get-Process | ForEach {
$jobs = Get-Process | foreach {
Start-ThreadJob {
$proc = $using:_
$dict = $using:threadSafeDictionary
$proc = $Using:_
$dict = $Using:threadSafeDictionary
$dict.TryAdd($proc.ProcessName, $proc)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ remoting and reflected into current PowerShell session. This is the same
transport method used for PowerShell jobs.

When a module is imported into the `WinPSCompatSession` session, implicit
remoting generates a proxy module in the user's `$env:Temp` directory and
remoting generates a proxy module in the user's `$Env:TEMP` directory and
imports this proxy module into current PowerShell session. The proxy module
allows PowerShell to detect that the module was loaded using Windows PowerShell
Compatibility functionality.
Expand Down Expand Up @@ -97,7 +97,7 @@ $ConfigJSON = ConvertTo-Json -InputObject @{
"Microsoft.PowerShell:ExecutionPolicy" = "RemoteSigned"
}
$ConfigJSON | Out-File -Force $ConfigPath
pwsh -settingsFile $ConfigPath
pwsh -SettingsFile $ConfigPath
```

For more the latest information about module compatibility, see the
Expand Down Expand Up @@ -148,7 +148,7 @@ The Windows PowerShell Compatibility functionality:

The Windows PowerShell Compatibility feature uses implicit remoting to make
Windows PowerShell 5.1 modules available in PowerShell 7. Implicit remoting
creates temporary files in the `$env:Temp` directory. Each proxied module is
creates temporary files in the `$Env:TEMP` directory. Each proxied module is
stored in a separate folder with the following naming convention:

- `remoteIpMoProxy_<ModuleName>_<ModuleVersion>_localhost_<SessionGuid>`.
Expand All @@ -163,6 +163,6 @@ from the session or close the session.

<!-- link references -->
[01]: about_Modules.md
[02]: about_Powershell_Config.md
[02]: about_PowerShell_Config.md
[03]: https://aka.ms/PSModuleCompat
[04]: xref:Microsoft.PowerShell.Core.Import-Module
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ disabled.

```powershell
Disable-PSRemoting -Force
powershell.exe -command 'Get-PSSessionConfiguration'
powershell.exe -Command 'Get-PSSessionConfiguration'
```

```Output
Expand Down Expand Up @@ -300,8 +300,8 @@ Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE Acce
```

```powershell
powershell.exe -command 'Disable-PSRemoting -Force'
powershell.exe -command 'Get-PSSessionConfiguration'
powershell.exe -Command 'Disable-PSRemoting -Force'
powershell.exe -Command 'Get-PSSessionConfiguration'
```

```Output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

## RELATED LINKS

[about_experimental_features](about/about_experimental_features.md)
[about_Experimental_Features](about/about_experimental_features.md)

[Disable-ExperimentalFeature](Disable-ExperimentalFeature.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ Set-Clipboard -Value "This is a test string" -AsOSC52
### Example 4: Set the default value of the **AsOSC52** parameter

You can detect if you are connected to a remote session over SSH by checking the value of the
`$env:SSH_CLIENT` or `$env:SSH_TTY` environment variables. If either of these variables are set,
`$Env:SSH_CLIENT` or `$Env:SSH_TTY` environment variables. If either of these variables are set,
then you are connected to a remote session over SSH. You can use this information to set the default
value of the **AsOSC52** parameter. Add one of the following lines to your PowerShell profile
script.

```powershell
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $env:SSH_CLIENT
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $env:SSH_TTY
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $Env:SSH_CLIENT
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $Env:SSH_TTY
```

For more information about `$PSDefaultParameterValues`, see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ specified in the command. For information about location stacks, see the [Notes]
### Example 5: Navigate location history using `+` or `-`

```
PS C:\> Set-Location -Path $env:SystemRoot
PS C:\> Set-Location -Path $Env:SystemRoot
PS C:\Windows> Set-Location -Path Cert:\
PS Cert:\> Set-Location -Path HKLM:\
PS HKLM:\>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ This command disables all breakpoints in the current console.

### Example 5: Disable a breakpoint in a runspace

In this example, a job is started and a breakpoint is set to break when the `Set-PSBreakPoint` is
run. The runspace is stored in a variable and passed to the `Get-PSBreakPoint` command with the
**Runspace** parameter. The output of `Get-PSBreakPoint` is piped to `Disable-PSBreakpoint` to
In this example, a job is started and a breakpoint is set to break when the `Set-PSBreakpoint` is
run. The runspace is stored in a variable and passed to the `Get-PSBreakpoint` command with the
**Runspace** parameter. The output of `Get-PSBreakpoint` is piped to `Disable-PSBreakpoint` to
disable the breakpoint in the runspace.

```powershell
Expand All @@ -110,7 +110,7 @@ Start-Job -ScriptBlock {

$runspace = Get-Runspace -Id 1

Get-PSBreakPoint -Runspace $runspace | Disable-Breakpoint -Runspace $runspace
Get-PSBreakpoint -Runspace $runspace | Disable-Breakpoint -Runspace $runspace
```

## PARAMETERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ This example is equivalent to running `Enable-PSBreakpoint -Id 3, 5`.
### Example 5: Enable a breakpoint in a runspace

In this example, a job is started with a breakpoint is set to break then disabled. The runspace is
stored in a variable and passed to the `Get-PSBreakPoint` command with the **Runspace** parameter.
The output of `Get-PSBreakPoint` is piped to `Enable-PSBreakpoint` to enable the breakpoint in the
stored in a variable and passed to the `Get-PSBreakpoint` command with the **Runspace** parameter.
The output of `Get-PSBreakpoint` is piped to `Enable-PSBreakpoint` to enable the breakpoint in the
runspace.

```powershell
Expand All @@ -131,7 +131,7 @@ Start-Job -ScriptBlock {

$runspace = Get-Runspace -Id 1

Get-PSBreakPoint -Runspace $runspace | Enable-Breakpoint -Runspace $runspace
Get-PSBreakpoint -Runspace $runspace | Enable-Breakpoint -Runspace $runspace
```

## PARAMETERS
Expand Down
8 changes: 4 additions & 4 deletions reference/7.4/Microsoft.PowerShell.Utility/Get-Error.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ In this example, `Get-Error` displays the details of the most recent error that
current session.

```powershell
Get-Childitem -path /NoRealDirectory
Get-ChildItem -Path /NoRealDirectory
Get-Error
```

Expand Down Expand Up @@ -86,11 +86,11 @@ InvocationInfo :
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 57
Line : Get-Childitem -path c:\NoRealDirectory
Line : Get-ChildItem -Path C:\NoRealDirectory
PositionMessage : At line:1 char:1
+ Get-Childitem -path c:\NoRealDirectory
+ Get-ChildItem -Path C:\NoRealDirectory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Get-Childitem
InvocationName : Get-ChildItem
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ $parms = @{
OutputSuffix = "`n}`n"
Separator = "`n"
}
$obj.PSObject.Properties | Join-String @parms
$obj.psobject.Properties | Join-String @parms
```

```Output
Expand Down
4 changes: 2 additions & 2 deletions reference/7.4/Microsoft.PowerShell.Utility/Remove-Alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ This example removes all aliases from the current PowerShell session, except for
other PowerShell sessions or new PowerShell sessions.

```powershell
Get-Alias | Where-Object { $_.Options -NE "Constant" } | Remove-Alias -Force
Get-Alias | Where-Object { $_.Options -ne "Constant" } | Remove-Alias -Force
```

`Get-Alias` gets all the aliases in the PowerShell session and sends the objects down the pipeline.
`Where-Object` uses a script block, and the automatic variable (`$_`) and **Options** property
represent the current pipeline object. The parameter **NE** (not equal), selects objects that don't
represent the current pipeline object. The `-ne` (not equal) operator selects objects that don't
have an **Options** value set to **Constant**. `Remove-Alias` uses the **Force** parameter to remove
aliases, including read-only aliases, from the PowerShell session. The **Force** parameter can't
remove **Constant** aliases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ It uses the `Get-PSBreakpoint` cmdlet to get the breakpoints. Then, it uses a pi

### Example 5: Remove a breakpoint in a runspace

In this example, a job is started and a breakpoint is set to break when the `Set-PSBreakPoint` is
run. The runspace is stored in a variable and passed to the `Get-PSBreakPoint` command with the
**Runspace** parameter. The output of `Get-PSBreakPoint` is piped to `Remove-PSBreakpoint` to
In this example, a job is started and a breakpoint is set to break when the `Set-PSBreakpoint` is
run. The runspace is stored in a variable and passed to the `Get-PSBreakpoint` command with the
**Runspace** parameter. The output of `Get-PSBreakpoint` is piped to `Remove-PSBreakpoint` to
remove the breakpoint in the runspace.

```powershell
Expand All @@ -100,7 +100,7 @@ Start-Job -ScriptBlock {

$runspace = Get-Runspace -Id 1

Get-PSBreakPoint -Runspace $runspace | Remove-Breakpoint -Runspace $runspace
Get-PSBreakpoint -Runspace $runspace | Remove-Breakpoint -Runspace $runspace
```

## PARAMETERS
Expand Down
2 changes: 1 addition & 1 deletion reference/7.4/ThreadJob/Start-ThreadJob.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ $jobs = @()

foreach ($file in $files) {
$jobs += Start-ThreadJob -Name $file.OutFile -ScriptBlock {
$params = $using:file
$params = $Using:file
Invoke-WebRequest @params
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ two cases for that meet this criteria.

```powershell
(Measure-Command {
1..1000 | ForEach { Start-ThreadJob { Write-Output "Hello $using:_" } } | Receive-Job -Wait
1..1000 | foreach { Start-ThreadJob { Write-Output "Hello $Using:_" } } | Receive-Job -Wait
}).TotalMilliseconds
36860.8226

Expand All @@ -170,13 +170,13 @@ two cases for that meet this criteria.
7.1975
```

The first example above shows a foreach loop that creates 1000 thread jobs to
The first example above shows a `foreach` loop that creates 1000 thread jobs to
do a simple string write. Due to job overhead, it takes over 36 seconds to
complete.

The second example runs the `ForEach` cmdlet to do the same 1000 operations.
This time, `ForEach-Object` runs sequentially, on a single thread, without any
job overhead. It completes in a mere 7 milliseconds.
The second example runs the `ForEach-Object` cmdlet to do the same 1000
operations. This time, `ForEach-Object` runs sequentially, on a single thread,
without any job overhead. It completes in a mere 7 milliseconds.

In the following example, up to 5000 entries are collected for 10 separate
system logs. Since the script involves reading a number of logs, it makes sense
Expand All @@ -201,9 +201,9 @@ The script completes in half the time when the jobs are run in parallel.

```powershell
Measure-Command {
$logs = $logNames | ForEach {
$logs = $logNames | foreach {
Start-ThreadJob {
Get-WinEvent -LogName $using:_ -MaxEvents 5000 2>$null
Get-WinEvent -LogName $Using:_ -MaxEvents 5000 2>$null
} -ThrottleLimit 10
} | Wait-Job | Receive-Job
}
Expand All @@ -218,29 +218,29 @@ $logs.Count
There are multiple ways to pass values into the thread-based jobs.

`Start-ThreadJob` can accept variables that are piped to the cmdlet, passed in
to the script block via the `$using` keyword, or passed in via the
to the script block via the `Using:` scope modifier, or passed in via the
**ArgumentList** parameter.

```powershell
$msg = "Hello"

$msg | Start-ThreadJob { $input | Write-Output } | Wait-Job | Receive-Job

Start-ThreadJob { Write-Output $using:msg } | Wait-Job | Receive-Job
Start-ThreadJob { Write-Output $Using:msg } | Wait-Job | Receive-Job

Start-ThreadJob { param ([string] $message) Write-Output $message } -ArgumentList @($msg) |
Start-ThreadJob { param ([string] $Message) Write-Output $Message } -ArgumentList @($msg) |
Wait-Job | Receive-Job
```

`ForEach-Object -Parallel` accepts piped in variables, and variables passed
directly to the script block via the `$using` keyword.
directly to the script block via the `Using:` scope modifier.

```powershell
$msg = "Hello"

$msg | ForEach-Object -Parallel { Write-Output $_ } -AsJob | Wait-Job | Receive-Job

1..1 | ForEach-Object -Parallel { Write-Output $using:msg } -AsJob | Wait-Job | Receive-Job
1..1 | ForEach-Object -Parallel { Write-Output $Using:msg } -AsJob | Wait-Job | Receive-Job
```

Since thread jobs run in the same process, any variable reference type passed
Expand All @@ -255,10 +255,10 @@ the process.

```powershell
$threadSafeDictionary = [System.Collections.Concurrent.ConcurrentDictionary[string,object]]::new()
$jobs = Get-Process | ForEach {
$jobs = Get-Process | foreach {
Start-ThreadJob {
$proc = $using:_
$dict = $using:threadSafeDictionary
$proc = $Using:_
$dict = $Using:threadSafeDictionary
$dict.TryAdd($proc.ProcessName, $proc)
}
}
Expand Down
Loading