Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10635 - Define script files as script blocks #10638

Merged
merged 2 commits into from
Nov 15, 2023
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
@@ -1,7 +1,7 @@
---
description: Describes variables that store state information for PowerShell. These variables are created and maintained by PowerShell.
Locale: en-US
ms.date: 10/26/2023
ms.date: 11/15/2023
no-loc: [Reset, Current, Background, Blink, Bold, Foreground, Formatting, Hidden, Italic, Reset, Reverse, Underline]
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
Expand Down Expand Up @@ -231,8 +231,8 @@ display or change the properties of the host, such as `$Host.version` or
### $input

Contains an enumerator that enumerates all input that's passed to a function.
The `$input` variable is available only to functions and script blocks (which
are unnamed functions).
The `$input` variable is available only to functions, script blocks (which
are unnamed functions), and script files (which are saved script blocks).

- In a function without a `begin`, `process`, or `end` block, the `$input`
variable enumerates the collection of all input to the function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Defines what a script block is and explains how to use script blocks in the PowerShell programming language.
Locale: en-US
ms.date: 11/29/2022
ms.date: 11/15/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_script_blocks?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Script Blocks
Expand All @@ -15,9 +15,11 @@ the PowerShell programming language.

## Long description

In the PowerShell programming language, a script block is a
collection of statements or expressions that can be used as a single unit.
A script block can accept arguments and return values.
In the PowerShell programming language, a script block is a collection of
statements or expressions that can be used as a single unit. The collection of
statements can be enclosed in braces (`{}`), defined as a function, or saved in
a script file. You can also pass a script block to a A script block can accept
arguments and return values.

Syntactically, a script block is a statement list in braces, as shown in
the following syntax:
Expand All @@ -30,27 +32,27 @@ A script block returns the output of all the commands in the script block,
either as a single object or as an array.

You can also specify a return value using the `return` keyword. The `return`
keyword does not affect or suppress other output returned from your script
keyword doesn't affect or suppress other output returned from your script
block. However, the `return` keyword exits the script block at that line. For
more information, see [about_Return](about_Return.md).
more information, see [about_Return][04].

Like functions, a script block can include parameters. Use the Param
keyword to assign named parameters, as shown in the following syntax:

```
{
Param([type]$Parameter1 [,[type]$Parameter2])
<statement list>
Param([type]$Parameter1 [,[type]$Parameter2])
<statement list>
}
```

> [!NOTE]
> In a script block, unlike a function, you cannot specify parameters outside
> In a script block, unlike a function, you can't specify parameters outside
> the braces.

Like functions, script blocks can include the `DynamicParam`, `Begin`,
`Process`, and `End` keywords. For more information, see [about_Functions](about_Functions.md)
and [about_Functions_Advanced](about_Functions_Advanced.md).
`Process`, and `End` keywords. For more information, see [about_Functions][02]
and [about_Functions_Advanced][01].

## Using Script Blocks

Expand Down Expand Up @@ -92,7 +94,7 @@ create a parameters `$p1` and `$p2`. The string "First" is bound to the
first parameter (`$p1`) and "Second" is bound to (`$p2`).

For more information about the behavior of **ArgumentList**, see
[about_Splatting](about_Splatting.md#splatting-with-arrays).
[about_Splatting][05].

You can use variables to store and execute script blocks. The example below
stores a script block in a variable and passes it to `Invoke-Command`.
Expand Down Expand Up @@ -143,7 +145,7 @@ PS> $b
2
```

For more information about the call operator, see [about_Operators](about_Operators.md).
For more information about the call operator, see [about_Operators][03].

## Using delay-bind script blocks with parameters

Expand Down Expand Up @@ -171,7 +173,7 @@ Notes on delay-bind script blocks as parameters:

- You must explicitly specify any parameter names you use with delay-bind
script blocks.
- The parameter must not be untyped, and the parameter's type cannot be
- The parameter must not be untyped, and the parameter's type can't be
`[scriptblock]` or `[object]`.
- You receive an error if you use a delay-bind script block without providing
pipeline input.
Expand All @@ -195,6 +197,13 @@ Notes on delay-bind script blocks as parameters:

## See also

- [about_Functions](about_Functions.md)
- [about_Functions_Advanced](about_Functions_Advanced.md)
- [about_Operators](about_Operators.md)
- [about_Functions][02]
- [about_Functions_Advanced][01]
- [about_Operators][03]

<!-- link references -->
[01]: about_Functions_Advanced.md
[02]: about_Functions.md
[03]: about_Operators.md
[04]: about_Return.md
[05]: about_Splatting.md#splatting-with-arrays
27 changes: 16 additions & 11 deletions reference/5.1/PSReadLine/About/about_PSReadLine.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: PSReadLine provides an improved command-line editing experience in the PowerShell console.
Locale: en-US
ms.date: 10/11/2023
ms.date: 11/14/2023
online version: https://learn.microsoft.com/powershell/module/psreadline/about/about_psreadline?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about PSReadLine
Expand Down Expand Up @@ -47,8 +47,8 @@ Install-Module -Name PSReadLine -AllowClobber -Force
## Custom Key Bindings

PSReadLine supports custom key bindings using the `Set-PSReadLineKeyHandler`
cmdlet. Most custom key bindings call one of the
[bindable functions](about_PSReadLine_Functions.md), for example
cmdlet. Most custom key bindings call one of the [bindable functions][02], for
example

```powershell
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Expand Down Expand Up @@ -104,7 +104,7 @@ You can see many more examples in the file `SamplePSReadLineProfile.ps1`, which
is installed in the **PSReadLine** module folder.

Most key bindings use some helper functions for editing the command line. Those
APIs are documented in [about_PSReadLine_Functions](about_PSReadLine_Functions.md).
APIs are documented in [about_PSReadLine_Functions][02].

## Notes

Expand Down Expand Up @@ -164,7 +164,7 @@ Get-ResultFromTwo -Secret1 (Get-Secret -Name blah -AsPlainText) -Secret2 sdv87ys
If there are other commands you don't want written to the history files, you
can use the **AddToHistoryHandler** parameter of the `Set-PSReadLineOption`
cmdlet. For an example of how to use **AddToHistoryHandler**, see Example 7 of
[Set-PSReadLineOption](/powershell/module/psreadline/set-psreadlineoption#example-7-use-historyhandler-to-filter-commands-added-to-history).
[Set-PSReadLineOption][01].

#### PSReadLine 2.3.4 improves the filtering of sensitive data

Expand Down Expand Up @@ -208,14 +208,13 @@ There have been many updates to PSReadLine since the version that ships in
Windows PowerShell 5.1.

- Current release is PSReadLine 2.3.4
- PowerShell 7.4-preview ships with PSReadLine 2.2.6
- PowerShell 7.4 ships with PSReadLine 2.3.4
- PowerShell 7.3 ships with PSReadLine 2.2.6
- PowerShell 7.2 ships with PSReadLine 2.1.0
- PowerShell 7.0.11 shipped with PSReadLine 2.0.4
- PowerShell 5.1 ships with PSReadLine 2.0.0

For a full list of changes, see the PSReadLine
[ChangeLog](https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/Changes.txt).
For a full list of changes, see the PSReadLine [ChangeLog][04].

- **PSReadLine 2.3.4**

Expand Down Expand Up @@ -286,11 +285,17 @@ enhancements:

### Feedback & contributing to PSReadLine

[PSReadLine on GitHub](https://github.com/PowerShell/PSReadLine)
[PSReadLine on GitHub][03]

Feel free to submit a pull request or submit feedback on the GitHub page.

## See Also

- PSReadLine is heavily influenced by the GNU
[readline](https://tiswww.case.edu/php/chet/readline/rltop.html) library.
- PSReadLine is heavily influenced by the GNU [readline][05] library.

<!-- link references -->
[01]: /powershell/module/psreadline/set-psreadlineoption#example-7-use-historyhandler-to-filter-commands-added-to-history
[02]: about_PSReadLine_Functions.md
[03]: https://github.com/PowerShell/PSReadLine
[04]: https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/Changes.txt
[05]: https://tiswww.case.edu/php/chet/readline/rltop.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes variables that store state information for PowerShell. These variables are created and maintained by PowerShell.
Locale: en-US
ms.date: 10/26/2023
ms.date: 11/15/2023
no-loc: [Reset, Current, Background, Blink, Bold, Foreground, Formatting, Hidden, Italic, Reset, Reverse, Underline]
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
Expand Down Expand Up @@ -244,8 +244,8 @@ display or change the properties of the host, such as `$Host.version` or
### $input

Contains an enumerator that enumerates all input that's passed to a function.
The `$input` variable is available only to functions and script blocks (which
are unnamed functions).
The `$input` variable is available only to functions, script blocks (which
are unnamed functions), and script files (which are saved script blocks).

- In a function without a `begin`, `process`, or `end` block, the `$input`
variable enumerates the collection of all input to the function.
Expand Down
Loading