Updates from: 01/06/2022 02:24:15
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About Psmodulepath (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_PSModulePath.md
--- description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources. Locale: en-US Previously updated : 09/16/2021 Last updated : 01/05/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSModulePath
to `HKCU:\`.
$key = (Get-Item 'HKCU:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true) $path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames') $path += ';C:\Program Files\Fabrikam\Modules' # or '%ProgramFiles%\Fabrikam\Modules'
-$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString))
+$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
``` ## See also
Microsoft.PowerShell.Utility Register Engineevent (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Utility/Register-EngineEvent.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/24/2021 Last updated : 01/04/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Register-EngineEvent
exited under the control of PowerShell. The event is not fired when the host app
window is closed. The engine is considered to be idle if it is not running a pipeline. The **OnIdle** event is fired
-when PowerShell has been idle for 400 milliseconds (ms).
+when PowerShell has been idle for 300 milliseconds (ms).
+
+> [!NOTE]
+> When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+> 300ms). The event could be signaled while the user is in the middle of editing a command line, for
+> example, the user is reading help to decide which parameter to use. Beginning in PSReadLine
+> 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there is a `ReadKey()`
+> timeout and the current editing buffer is empty.
## Related links
Microsoft.PowerShell.Core About Psmodulepath (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_PSModulePath.md
--- description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources. Locale: en-US Previously updated : 09/16/2021 Last updated : 01/05/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSModulePath
to `HKCU:\`.
$key = (Get-Item 'HKCU:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true) $path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames') $path += ';C:\Program Files\Fabrikam\Modules' # or '%ProgramFiles%\Fabrikam\Modules'
-$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString))
+$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
``` - ## See also - [about_Modules](about_Modules.md)
Microsoft.PowerShell.Utility Register Engineevent (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Utility/Register-EngineEvent.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/24/2021 Last updated : 01/04/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Register-EngineEvent
exited under the control of PowerShell. The event is not fired when the host app
window is closed. The engine is considered to be idle if it is not running a pipeline. The **OnIdle** event is fired
-when PowerShell has been idle for 400 milliseconds (ms).
+when PowerShell has been idle for 300 milliseconds (ms).
+
+> [!NOTE]
+> When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+> 300ms). The event could be signaled while the user is in the middle of editing a command line, for
+> example, the user is reading help to decide which parameter to use. Beginning in PSReadLine
+> 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there is a `ReadKey()`
+> timeout and the current editing buffer is empty.
## Related links
Microsoft.PowerShell.Core About Psmodulepath (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_PSModulePath.md
--- description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources. Locale: en-US Previously updated : 09/16/2021 Last updated : 01/05/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSModulePath
to `HKCU:\`.
$key = (Get-Item 'HKCU:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true) $path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames') $path += ';C:\Program Files\Fabrikam\Modules' # or '%ProgramFiles%\Fabrikam\Modules'
-$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString))
+$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
``` - ## See also - [about_Modules](about_Modules.md)
Microsoft.PowerShell.Utility Register Engineevent (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Utility/Register-EngineEvent.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/24/2021 Last updated : 01/04/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Register-EngineEvent
exited under the control of PowerShell. The event is not fired when the host app
window is closed. The engine is considered to be idle if it is not running a pipeline. The **OnIdle** event is fired
-when PowerShell has been idle for 400 milliseconds (ms).
+when PowerShell has been idle for 300 milliseconds (ms).
+
+> [!NOTE]
+> When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+> 300ms). The event could be signaled while the user is in the middle of editing a command line, for
+> example, the user is reading help to decide which parameter to use. Beginning in PSReadLine
+> 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there is a `ReadKey()`
+> timeout and the current editing buffer is empty.
## Related links
Microsoft.PowerShell.Core About Psmodulepath (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_PSModulePath.md
--- description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources. Locale: en-US Previously updated : 09/16/2021 Last updated : 01/05/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSModulePath
to `HKCU:\`.
$key = (Get-Item 'HKCU:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true) $path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames') $path += ';C:\Program Files\Fabrikam\Modules' # or '%ProgramFiles%\Fabrikam\Modules'
-$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString))
+$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
``` - ## See also - [about_Modules](about_Modules.md)
Microsoft.PowerShell.Utility Register Engineevent (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Utility/Register-EngineEvent.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/24/2021 Last updated : 01/04/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Register-EngineEvent
exited under the control of PowerShell. The event is not fired when the host app
window is closed. The engine is considered to be idle if it is not running a pipeline. The **OnIdle** event is fired
-when PowerShell has been idle for 400 milliseconds (ms).
+when PowerShell has been idle for 300 milliseconds (ms).
+
+> [!NOTE]
+> When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+> 300ms). The event could be signaled while the user is in the middle of editing a command line, for
+> example, the user is reading help to decide which parameter to use. Beginning in PSReadLine
+> 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there is a `ReadKey()`
+> timeout and the current editing buffer is empty.
## Related links
Microsoft.PowerShell.Core About Psmodulepath (7.3) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.3/Microsoft.PowerShell.Core/About/about_PSModulePath.md
--- description: The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources. Locale: en-US Previously updated : 09/16/2021 Last updated : 01/05/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSModulePath?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about PSModulePath
to `HKCU:\`.
$key = (Get-Item 'HKCU:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true) $path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames') $path += ';C:\Program Files\Fabrikam\Modules' # or '%ProgramFiles%\Fabrikam\Modules'
-$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString))
+$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
``` - ## See also - [about_Modules](about_Modules.md)
Microsoft.PowerShell.Utility Register Engineevent (7.3) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.3/Microsoft.PowerShell.Utility/Register-EngineEvent.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/24/2021 Last updated : 01/04/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Register-EngineEvent
exited under the control of PowerShell. The event is not fired when the host app
window is closed. The engine is considered to be idle if it is not running a pipeline. The **OnIdle** event is fired
-when PowerShell has been idle for 400 milliseconds (ms).
+when PowerShell has been idle for 300 milliseconds (ms).
+
+> [!NOTE]
+> When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+> 300ms). The event could be signaled while the user is in the middle of editing a command line, for
+> example, the user is reading help to decide which parameter to use. Beginning in PSReadLine
+> 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there is a `ReadKey()`
+> timeout and the current editing buffer is empty.
## Related links
PSReadLine About Psreadline (7.3) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.3/PSReadLine/About/about_PSReadLine.md
Invoke-WebRequest -Token xxx # Expr-value as argument to '-Token'.
Get-ResultFromTwo -Secret1 (Get-Secret -Name blah -AsPlainText) -Secret2 sdv87ysdfayf798hfasd8f7ha # '-Secret2' has expr-value argument. ```
+### Behavior of the OnIdle event
+
+When PSReadLine is in use, the **OnIdle** event is fired when `ReadKey()` times out (no typing in
+300ms). The event could be signaled while the user is in the middle of editing a command line, for
+example, the user is reading help to decide which parameter to use.
+
+Beginning in PSReadLine 2.2.0-beta4, **OnIdle** behavior changed to signal the event only if there
+is a `ReadKey()` timeout and the current editing buffer is empty.
+ ### Feedback & Contributing To PSReadLine [PSReadLine on GitHub](https://github.com/PowerShell/PSReadLine)
dev-cross-plat Script Authoring Considerations https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dev-cross-plat/performance/script-authoring-considerations.md
--- description: Scripting for Performance in PowerShell Previously updated : 11/11/2021 Last updated : 01/05/2022 Title: PowerShell scripting performance considerations ---
often leveraging the pipeline, and dropping down into .NET only when necessary.
> of a PowerShell script. Script authors are advised to use idiomatic PowerShell unless performance > dictates otherwise.
-## Suppressing Output
+## Suppressing output
There are many ways to avoid writing objects to the pipeline:
probably not noticeable for most scripts. However, calling `Out-Null` in a large
significantly slower, even in PowerShell 7.x. ```powershell
-PS> $d = Get-Date; Measure-Command { for($i=0; $i -lt 1mb; $i++) { $null=$d } }| Select-Object TotalSeconds
+$d = Get-Date
+Measure-Command { for($i=0; $i -lt 1mb; $i++) { $null=$d } } |
+ Select-Object TotalSeconds
TotalSeconds ------------ 1.0549325
-PS> $d = Get-Date; Measure-Command { for($i=0; $i -lt 1mb; $i++) { $d | Out-Null } }| Select-Object TotalSeconds
+$d = Get-Date
+Measure-Command { for($i=0; $i -lt 1mb; $i++) { $d | Out-Null } } |
+ Select-Object TotalSeconds
TotalSeconds ------------
This technique performs roughly as well as piping to `Out-Null` and should be av
sensitive script. The extra overhead in this example comes from the creation of and invoking a script block that was previously inline script.
-## Array Addition
+## Array addition
Generating a list of items is often done using an array with the addition operator:
$results += Do-SomethingElse
$results ```
-This can be very inefficent because arrays are immutable. Each addition to the array actually
+This can be very inefficient because arrays are immutable. Each addition to the array actually
creates a new array big enough to hold all elements of both the left and right operands, then copies the elements of both operands into the new array. For small collections, this overhead may not matter. For large collections, this can definitely be an issue.
In this example, PowerShell creates an `ArrayList` to hold the results written t
inside the array expression. Just before assigning to `$results`, PowerShell converts the `ArrayList` to an `object[]`.
-## Processing Large Files
+## String addition
+
+Like arrays, strings are immutable. Each addition to the string actually creates a new string big
+enough to hold the contents of both the left and right operands, then copies the elements of both
+operands into the new string. For small strings, this overhead may not matter. For large strings,
+this can definitely be an issue.
+
+```powershell
+$string = ''
+Measure-Command {
+ foreach( $i in 1..10000)
+ {
+ $string += "Iteration $i`n"
+ }
+ $string
+ } | Select-Object TotalMilliseconds
+
+TotalMilliseconds
+-----------------
+ 641.8168
+```
+
+There are a couple of alternatives. You can use the `-join` operator to concatenate strings.
+
+```powershell
+Measure-Command {
+ $string = @(
+ foreach ($i in 1..10000) { "Iteration $i" }
+ ) -join "`n"
+ $string
+ } | Select-Object TotalMilliseconds
+
+TotalMilliseconds
+-----------------
+ 22.7069
+```
+
+In this example, using the `-join` operator is nearly 30-times faster than string addition.
+
+You can also use the .NET **StringBuilder** class.
+
+```powershell
+$sb = [System.Text.StringBuilder]::new()
+Measure-Command {
+ foreach( $i in 1..10000)
+ {
+ [void]$sb.Append("Iteration $i`n")
+ }
+ $sb.ToString()
+ } | Select-Object TotalMilliseconds
+
+TotalMilliseconds
+-----------------
+ 13.4671
+```
+
+In this example, using the **StringBuilder** is nearly 50-times faster than string addition.
+
+## Processing large files
The idiomatic way to process a file in PowerShell might look something like:
windows-powershell New Updated Cmdlets https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/windows-powershell/wmf/whats-new/new-updated-cmdlets.md
--- description: Windows PowerShell 5.1 includes many new or updated cmdlets. Previously updated : 06/12/2017 Last updated : 01/05/2022 Title: New and updated cmdlets --- # New and updated cmdlets
The Item cmdlet and a few related cmdlets have been extended to support symbolic
### Symbolic link files In this example, we create a new symbolic link file named MySymLinkFile.txt in C:\Temp which links
-to $pshome\profile.ps1. All three examples produce the same result.
+to $pshome\profile.ps1. These examples produce the same result.
```powershell New-Item -ItemType SymbolicLink -Path C:\Temp -Name MySymLinkFile.txt -Value $pshome\profile.ps1 New-Item -ItemType SymbolicLink -Path C:\Temp\MySymLinkFile.txt -Value $pshome\profile.ps1
-New-Item -ItemType SymbolicLink -Name C:\Temp\MySymLinkFile.txt -Value $pshome\profile.ps1
``` ### Symbolic link directories In this example, we create a new symbolic link directory named MySymLinkDir in C:\Temp which links
-to the $pshome folder. All three examples produce the same result.
+to the $pshome folder. These examples produce the same result.
```powershell New-Item -ItemType SymbolicLink -Path C:\Temp -Name MySymLinkDir -Value $pshome New-Item -ItemType SymbolicLink -Path C:\Temp\MySymLinkDir -Value $pshome
-New-Item -ItemType SymbolicLink -Name C:\Temp\MySymLinkDir -Value $pshome
``` ### Hard links