"`
Any additional paths added affect the current session only.
@@ -221,40 +221,40 @@ A dynamic module can be used to create a *closure*, a function with attached dat
following example:
```powershell
-function Get-NextID ([int]$startValue = 1) {
- $nextID = $startValue
+function Get-NextID ([int]$StartValue = 1) {
+ $nextID = $StartValue
{
- ($script:nextID++)
+ ($Script:nextID++)
}.GetNewClosure()
}
-$v1 = Get-NextID # get a scriptblock with $startValue of 0
+$v1 = Get-NextID # get a scriptblock with $StartValue of 0
& $v1 # invoke Get-NextID getting back 1
& $v1 # invoke Get-NextID getting back 2
-$v2 = Get-NextID 100 # get a scriptblock with $startValue of 100
+$v2 = Get-NextID 100 # get a scriptblock with $StartValue of 100
& $v2 # invoke Get-NextID getting back 100
& $v2 # invoke Get-NextID getting back 101
```
The intent here is that `Get-NextID` return the next ID in a sequence whose start value can be
-specified. However, multiple sequences must be supported, each with its own `$startValue` and
+specified. However, multiple sequences must be supported, each with its own `$StartValue` and
`$nextID` context. This is achieved by the call to the method `[scriptblock]::GetNewClosure`
([§4.3.7][§4.3.7]).
Each time a new closure is created by `GetNewClosure`, a new dynamic module is created, and the
variables in the caller's scope (in this case, the script block containing the increment) are copied
into this new module. To ensure that the nextId defined inside the parent function (but outside the
-script block) is incremented, the explicit script: scope prefix is needed.
+script block) is incremented, the explicit Script: scope prefix is needed.
Of course, the script block need not be a named function; for example:
```powershell
-$v3 = & { # get a scriptblock with $startValue of 200
- param ([int]$startValue = 1)
- $nextID = $startValue
+$v3 = & { # get a scriptblock with $StartValue of 200
+ param ([int]$StartValue = 1)
+ $nextID = $StartValue
{
- ($script:nextID++)
+ ($Script:nextID++)
}.GetNewClosure()
} 200
diff --git a/reference/docs-conceptual/lang-spec/chapter-12.md b/reference/docs-conceptual/lang-spec/chapter-12.md
index 0f04a14309c7..4fa7d8e02d6d 100644
--- a/reference/docs-conceptual/lang-spec/chapter-12.md
+++ b/reference/docs-conceptual/lang-spec/chapter-12.md
@@ -87,15 +87,15 @@ Consider a function call `Test1` that has the following param block, and which i
param (
[Parameter(Mandatory = $true)]
[Alias("CN")]
- [Alias("name", "system")]
+ [Alias("Name", "System")]
[string[]] $ComputerName
)
Test1 "Mars", "Saturn" # pass argument by position
Test1 -ComputerName "Mars", "Saturn" # pass argument by name
Test1 -CN "Mars", "Saturn" # pass argument using first alias
-Test1 -name "Mars", "Saturn" # pass argument using second alias
-Test1 -sys "Mars", "Saturn" # pass argument using third alias
+Test1 -Name "Mars", "Saturn" # pass argument using second alias
+Test1 -Sys "Mars", "Saturn" # pass argument using third alias
```
Consider a function call `Test2` that has the following param block, and which is called as shown:
@@ -112,7 +112,7 @@ Get-ChildItem "E:\*.txt" | Test2 -LiteralPath { $_ ; "`n`t";
Get-ChildItem "E:\*.txt" | Test2
```
-Cmdlet `Get-ChildItem` (alias `Dir`) adds to the object it returns a new **NoteProperty** of type
+Cmdlet `Get-ChildItem` (alias `dir`) adds to the object it returns a new **NoteProperty** of type
`string`, called **PSPath**.
### 12.3.2 The AllowEmptyCollection attribute
@@ -124,14 +124,14 @@ Consider a function call `Test` that has the following param block, and which is
```powershell
param (
- [parameter(Mandatory = $true)]
+ [Parameter(Mandatory = $true)]
[AllowEmptyCollection()]
[string[]] $ComputerName
)
-Test "Red", "Green" # $computerName has Length 2
-Test "Red" # $computerName has Length 1
-Test -comp @() # $computerName has Length 0
+Test "Red", "Green" # $ComputerName has Length 2
+Test "Red" # $ComputerName has Length 1
+Test -Comp @() # $ComputerName has Length 0
```
### 12.3.3 The AllowEmptyString attribute
@@ -143,14 +143,14 @@ Consider a function call `Test` that has the following param block, and which is
```powershell
param (
- [parameter(Mandatory = $true)]
+ [Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string] $ComputerName
)
-Test "Red" # $computerName is "Red"
+Test "Red" # $ComputerName is "Red"
Test "" # empty string is permitted
-Test -comp "" # empty string is permitted
+Test -Comp "" # empty string is permitted
```
### 12.3.4 The AllowNull attribute
@@ -162,14 +162,14 @@ Consider a function call Test that has the following param block, and which is c
```powershell
param (
- [parameter(Mandatory = $true)]
+ [Parameter(Mandatory = $true)]
[AllowNull()]
[int[]] $Values
)
Test 10, 20, 30 # $values has Length 3, values 10, 20, 30
Test 10, $null, 30 # $values has Length 3, values 10, 0, 30
-Test -val $null # $values has value $null
+Test -Val $null # $values has value $null
```
Note that the second case above does not need this attribute; there is already an implicit
@@ -362,8 +362,8 @@ ValueFromPipeline=$true)]
This argument specifies whether the parameter takes its value from a property of a pipeline object that has either the same name or the same alias as this parameter. A value of $true indicates that it does. A value of $false indicates that it does not.
Specify $true if the following conditions are true: the parameter accesses a property of the piped object, and the property has the same name as the parameter, or the property has the same alias as the parameter.
A parameter having ValueFromPipelineByPropertyName set to $true need not have a parameter in the same set with ValueFromPipeline set to $true.
-If a function has a parameter $ComputerName, and the piped object has a ComputerName property, the value of the ComputerName property is assigned to the $ComputerName parameter of the function:
-param ( [parameter(Mandatory = $true,
+
If a function has a parameter $ComputerName, and the piped object has a ComputerName property, the value of the ComputerName property is assigned to the $ComputerName parameter of the Function:
+param ( [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[string[]] $ComputerName )
Multiple parameters in a parameter set can define the ValueFromPipelineByPropertyName as $true. Although, a single input object cannot be bound to multiple parameters, different properties in that input object may be bound to different parameters.
@@ -387,13 +387,13 @@ Get-Date | Process-Date
ValueFromRemainingArguments (named) |
Type: bool; Default value: $false
This argument specifies whether the parameter accepts all of the remaining arguments that are not bound to the parameters of the function. A value of $true indicates that it does. A value of $false indicates that it does not.
-The following example shows a parameter $others that accepts all the remaining arguments of the input object that is passed to the function Test:
-param ( [parameter(Mandatory = $true)][int] $p1,
-[parameter(Mandatory = $true)][int] $p2,
-[parameter(ValueFromRemainingArguments = $true)]
-[string[]] $others )
-Test 10 20 # $others has Length 0
-Test 10 20 30 40 # $others has Length 2, value 30,40 |
+The following example shows a parameter $Others that accepts all the remaining arguments of the input object that is passed to the function Test:
+param ( [Parameter(Mandatory = $true)][int] $p1,
+[Parameter(Mandatory = $true)][int] $p2,
+[Parameter(ValueFromRemainingArguments = $true)]
+[string[]] $Others )
+Test 10 20 # $Others has Length 0
+Test 10 20 30 40 # $Others has Length 2, value 30,40