Updates from: 07/22/2021 03:12:51
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About For (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_For.md
---
-description: Describes a language command you can use to run statements based on a conditional test.
+description: Describes a language command you can use to run statements based on a conditional test.
keywords: powershell,cmdlet Locale: en-US Previously updated : 3/4/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_for?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about For
The `For` statement (also known as a `For` loop) is a language construct you
can use to create a loop that runs commands in a command block while a specified condition evaluates to `$true`.
-A typical use of the `For` loop is to iterate an array of values and to
-operate on a subset of these values. In most cases, if you want to iterate
-all the values in an array, consider using a `Foreach` statement.
+A typical use of the `For` loop is to iterate an array of values and to operate
+on a subset of these values. In most cases, if you want to iterate all the
+values in an array, consider using a `Foreach` statement.
### Syntax
The **Init** placeholder represents one or more commands that are run before
the loop begins. You typically use the **Init** portion of the statement to create and initialize a variable with a starting value.
-This variable will then be the basis for the condition to be tested in the
-next portion of the `For` statement.
+This variable will then be the basis for the condition to be tested in the next
+portion of the `For` statement.
The **Condition** placeholder represents the portion of the `For` statement that resolves to a `$true` or `$false` **Boolean** value. PowerShell evaluates the condition each time the `For` loop runs. If the statement is `$true`, the commands in the command block run, and the statement is evaluated again. If the
-condition is still `$true`, the commands in the **Statement list** run again. The loop
-is repeated until the condition becomes `$false`.
+condition is still `$true`, the commands in the **Statement list** run again.
+The loop is repeated until the condition becomes `$false`.
-The **Repeat** placeholder represents one or more commands, separated
-by commas, that are executed each time the loop repeats. Typically, this is
-used to modify a variable that is tested inside the **Condition** part
-of the statement.
+The **Repeat** placeholder represents one or more commands, separated by
+commas, that are executed each time the loop repeats. Typically, this is used
+to modify a variable that is tested inside the **Condition** part of the
+statement.
-The **Statement list** placeholder represents a set of one or more
-commands that are run each time the loop is entered or repeated. The
-contents of the **Statement list** are surrounded by braces.
+The **Statement list** placeholder represents a set of one or more commands
+that are run each time the loop is entered or repeated. The contents of the
+**Statement list** are surrounded by braces.
### Support for multiple operations
The following syntaxes are supported for multiple assignment operations in the
```powershell # Comma separated assignment expressions.
-for (($i = 0), ($j = 0); $i -lt 10; $i++)
+for (($i = 0), ($j = 0); $i -lt 10; $i++, $j++)
{ "`$i:$i" "`$j:$j"
For more information, see [about_Logical_Operators](about_Logical_Operators.md).
### Examples At a minimum, a `For` statement requires the parenthesis surrounding the
-**Init**, **Condition**, and **Repeat** part of the statement
-and a command surrounded by braces in the **Statement list** part of
-the statement.
+**Init**, **Condition**, and **Repeat** part of the statement and a command
+surrounded by braces in the **Statement list** part of the statement.
Note that the upcoming examples intentionally show code outside the `For` statement. In later examples, code is integrated into the `For` statement.
for (;;)
} ```
-You can add additional commands to the statement list so that the value of
-`$i` is incremented by 1 each time the loop is run, as the following example
-shows.
+You can add additional commands to the statement list so that the value of `$i`
+is incremented by 1 each time the loop is run, as the following example shows.
```powershell for (;;)
Until you break out of the command by pressing CTRL+C, this statement will
continually display the value of the `$i` variable as it is incremented by 1 each time the loop is run.
-Rather than change the value of the variable in the statement list part of
-the `For` statement, you can use the **Repeat** portion of the `For`
-statement instead, as follows.
+Rather than change the value of the variable in the statement list part of the
+`For` statement, you can use the **Repeat** portion of the `For` statement
+instead, as follows.
```powershell $i=1
for (;;$i++)
This statement will still repeat indefinitely until you break out of the command by pressing CTRL+C.
-You can terminate the `For` loop using a *condition*. You can place a condition
-using the **Condition** portion of the `For` statement. The `For`
+You can terminate the `For` loop using a **condition**. You can place a
+condition using the **Condition** portion of the `For` statement. The `For`
loop terminates when the condition evaluates to `$false`. In the following example, the `For` loop runs while the value of `$i` is less
for(;$i -le 10;$i++)
} ```
-Instead of creating and initializing the variable outside the `For`
-statement, you can perform this task inside the `For` loop by using the
-**Init** portion of the `For` statement.
+Instead of creating and initializing the variable outside the `For` statement,
+you can perform this task inside the `For` loop by using the **Init** portion
+of the `For` statement.
```powershell for($i=1; $i -le 10; $i++){Write-Host $i} ```
-You can use carriage returns instead of semicolons to delimit the
-**Init**, **Condition**, and **Repeat** portions of the `For`
-statement. The following example shows a `For` that uses this alternative
-syntax.
+You can use carriage returns instead of semicolons to delimit the **Init**,
+**Condition**, and **Repeat** portions of the `For` statement. The following
+example shows a `For` that uses this alternative syntax.
```powershell for ($i = 0
for ($i = 0
``` This alternative form of the `For` statement works in PowerShell script files
-and at the PowerShell command prompt. However, it is easier to use
-the `For` statement syntax with semicolons when you enter interactive
-commands at the command prompt.
+and at the PowerShell command prompt. However, it is easier to use the `For`
+statement syntax with semicolons when you enter interactive commands at the
+command prompt.
The `For` loop is more flexible than the `Foreach` loop because it allows you to increment values in an array or collection by using patterns. In the
-following example, the `$i` variable is incremented by 2 in the
-**Repeat** portion of the `For` statement.
+following example, the `$i` variable is incremented by 2 in the **Repeat**
+portion of the `For` statement.
```powershell for ($i = 0; $i -le 20; $i += 2)
Microsoft.PowerShell.Core About For (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_For.md
description: Describes a language command you can use to run statements based on a conditional test. keywords: powershell,cmdlet Locale: en-US Previously updated : 3/4/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_for?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about For
The `For` statement (also known as a `For` loop) is a language construct you
can use to create a loop that runs commands in a command block while a specified condition evaluates to `$true`.
-A typical use of the `For` loop is to iterate an array of values and to
-operate on a subset of these values. In most cases, if you want to iterate
-all the values in an array, consider using a `Foreach` statement.
+A typical use of the `For` loop is to iterate an array of values and to operate
+on a subset of these values. In most cases, if you want to iterate all the
+values in an array, consider using a `Foreach` statement.
### Syntax
The **Init** placeholder represents one or more commands that are run before
the loop begins. You typically use the **Init** portion of the statement to create and initialize a variable with a starting value.
-This variable will then be the basis for the condition to be tested in the
-next portion of the `For` statement.
+This variable will then be the basis for the condition to be tested in the next
+portion of the `For` statement.
The **Condition** placeholder represents the portion of the `For` statement that resolves to a `$true` or `$false` **Boolean** value. PowerShell evaluates the condition each time the `For` loop runs. If the statement is `$true`, the commands in the command block run, and the statement is evaluated again. If the
-condition is still `$true`, the commands in the **Statement list** run again. The loop
-is repeated until the condition becomes `$false`.
+condition is still `$true`, the commands in the **Statement list** run again.
+The loop is repeated until the condition becomes `$false`.
-The **Repeat** placeholder represents one or more commands, separated
-by commas, that are executed each time the loop repeats. Typically, this is
-used to modify a variable that is tested inside the **Condition** part
-of the statement.
+The **Repeat** placeholder represents one or more commands, separated by
+commas, that are executed each time the loop repeats. Typically, this is used
+to modify a variable that is tested inside the **Condition** part of the
+statement.
-The **Statement list** placeholder represents a set of one or more
-commands that are run each time the loop is entered or repeated. The
-contents of the **Statement list** are surrounded by braces.
+The **Statement list** placeholder represents a set of one or more commands
+that are run each time the loop is entered or repeated. The contents of the
+**Statement list** are surrounded by braces.
### Support for multiple operations
The following syntaxes are supported for multiple assignment operations in the
```powershell # Comma separated assignment expressions.
-for (($i = 0), ($j = 0); $i -lt 10; $i++)
+for (($i = 0), ($j = 0); $i -lt 10; $i++, $j++)
{ "`$i:$i" "`$j:$j"
For more information, see [about_Logical_Operators](about_Logical_Operators.md).
### Examples At a minimum, a `For` statement requires the parenthesis surrounding the
-**Init**, **Condition**, and **Repeat** part of the statement
-and a command surrounded by braces in the **Statement list** part of
-the statement.
+**Init**, **Condition**, and **Repeat** part of the statement and a command
+surrounded by braces in the **Statement list** part of the statement.
Note that the upcoming examples intentionally show code outside the `For` statement. In later examples, code is integrated into the `For` statement.
for (;;)
} ```
-You can add additional commands to the statement list so that the value of
-`$i` is incremented by 1 each time the loop is run, as the following example
-shows.
+You can add additional commands to the statement list so that the value of `$i`
+is incremented by 1 each time the loop is run, as the following example shows.
```powershell for (;;)
Until you break out of the command by pressing CTRL+C, this statement will
continually display the value of the `$i` variable as it is incremented by 1 each time the loop is run.
-Rather than change the value of the variable in the statement list part of
-the `For` statement, you can use the **Repeat** portion of the `For`
-statement instead, as follows.
+Rather than change the value of the variable in the statement list part of the
+`For` statement, you can use the **Repeat** portion of the `For` statement
+instead, as follows.
```powershell $i=1
for (;;$i++)
This statement will still repeat indefinitely until you break out of the command by pressing CTRL+C.
-You can terminate the `For` loop using a *condition*. You can place a condition
-using the **Condition** portion of the `For` statement. The `For`
+You can terminate the `For` loop using a **condition**. You can place a
+condition using the **Condition** portion of the `For` statement. The `For`
loop terminates when the condition evaluates to `$false`. In the following example, the `For` loop runs while the value of `$i` is less
for(;$i -le 10;$i++)
} ```
-Instead of creating and initializing the variable outside the `For`
-statement, you can perform this task inside the `For` loop by using the
-**Init** portion of the `For` statement.
+Instead of creating and initializing the variable outside the `For` statement,
+you can perform this task inside the `For` loop by using the **Init** portion
+of the `For` statement.
```powershell for($i=1; $i -le 10; $i++){Write-Host $i} ```
-You can use carriage returns instead of semicolons to delimit the
-**Init**, **Condition**, and **Repeat** portions of the `For`
-statement. The following example shows a `For` that uses this alternative
-syntax.
+You can use carriage returns instead of semicolons to delimit the **Init**,
+**Condition**, and **Repeat** portions of the `For` statement. The following
+example shows a `For` that uses this alternative syntax.
```powershell for ($i = 0
for ($i = 0
``` This alternative form of the `For` statement works in PowerShell script files
-and at the PowerShell command prompt. However, it is easier to use
-the `For` statement syntax with semicolons when you enter interactive
-commands at the command prompt.
+and at the PowerShell command prompt. However, it is easier to use the `For`
+statement syntax with semicolons when you enter interactive commands at the
+command prompt.
The `For` loop is more flexible than the `Foreach` loop because it allows you to increment values in an array or collection by using patterns. In the
-following example, the `$i` variable is incremented by 2 in the
-**Repeat** portion of the `For` statement.
+following example, the `$i` variable is incremented by 2 in the **Repeat**
+portion of the `For` statement.
```powershell for ($i = 0; $i -le 20; $i += 2)
Microsoft.PowerShell.Utility Test Json (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Utility/Test-Json.md
--- external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/19/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/test-json?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Test-Json
Accept wildcard characters: False
### CommonParameters
-This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction,
--InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and--WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
+This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
+-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
+-WarningAction, and -WarningVariable. For more information, see
+[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
You can pipe a JSON string to `Test-Json`.
## NOTES
-The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+The `Test-Json` cmdlet is implemented by using the
+[NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+
+Since PowerShell 6, PowerShell uses the Newtonsoft.Json assemblies for all JSON functions.
+Newtonsoft's implementation includes several extensions to the JSON standard, such as support for
+comments and use of single quotes. For a full list of features, see the Newtonsoft documentation at
+[https://www.newtonsoft.com/json](https://www.newtonsoft.com/json).
## RELATED LINKS
Microsoft.PowerShell.Core About For (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_For.md
description: Describes a language command you can use to run statements based on a conditional test. keywords: powershell,cmdlet Locale: en-US Previously updated : 3/4/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_for?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about For
The `For` statement (also known as a `For` loop) is a language construct you
can use to create a loop that runs commands in a command block while a specified condition evaluates to `$true`.
-A typical use of the `For` loop is to iterate an array of values and to
-operate on a subset of these values. In most cases, if you want to iterate
-all the values in an array, consider using a `Foreach` statement.
+A typical use of the `For` loop is to iterate an array of values and to operate
+on a subset of these values. In most cases, if you want to iterate all the
+values in an array, consider using a `Foreach` statement.
### Syntax
The **Init** placeholder represents one or more commands that are run before
the loop begins. You typically use the **Init** portion of the statement to create and initialize a variable with a starting value.
-This variable will then be the basis for the condition to be tested in the
-next portion of the `For` statement.
+This variable will then be the basis for the condition to be tested in the next
+portion of the `For` statement.
The **Condition** placeholder represents the portion of the `For` statement that resolves to a `$true` or `$false` **Boolean** value. PowerShell evaluates the condition each time the `For` loop runs. If the statement is `$true`, the commands in the command block run, and the statement is evaluated again. If the
-condition is still `$true`, the commands in the **Statement list** run again. The loop
-is repeated until the condition becomes `$false`.
+condition is still `$true`, the commands in the **Statement list** run again.
+The loop is repeated until the condition becomes `$false`.
-The **Repeat** placeholder represents one or more commands, separated
-by commas, that are executed each time the loop repeats. Typically, this is
-used to modify a variable that is tested inside the **Condition** part
-of the statement.
+The **Repeat** placeholder represents one or more commands, separated by
+commas, that are executed each time the loop repeats. Typically, this is used
+to modify a variable that is tested inside the **Condition** part of the
+statement.
-The **Statement list** placeholder represents a set of one or more
-commands that are run each time the loop is entered or repeated. The
-contents of the **Statement list** are surrounded by braces.
+The **Statement list** placeholder represents a set of one or more commands
+that are run each time the loop is entered or repeated. The contents of the
+**Statement list** are surrounded by braces.
### Support for multiple operations
The following syntaxes are supported for multiple assignment operations in the
```powershell # Comma separated assignment expressions.
-for (($i = 0), ($j = 0); $i -lt 10; $i++)
+for (($i = 0), ($j = 0); $i -lt 10; $i++, $j++)
{ "`$i:$i" "`$j:$j"
For more information, see [about_Logical_Operators](about_Logical_Operators.md).
### Examples At a minimum, a `For` statement requires the parenthesis surrounding the
-**Init**, **Condition**, and **Repeat** part of the statement
-and a command surrounded by braces in the **Statement list** part of
-the statement.
+**Init**, **Condition**, and **Repeat** part of the statement and a command
+surrounded by braces in the **Statement list** part of the statement.
Note that the upcoming examples intentionally show code outside the `For` statement. In later examples, code is integrated into the `For` statement.
for (;;)
} ```
-You can add additional commands to the statement list so that the value of
-`$i` is incremented by 1 each time the loop is run, as the following example
-shows.
+You can add additional commands to the statement list so that the value of `$i`
+is incremented by 1 each time the loop is run, as the following example shows.
```powershell for (;;)
Until you break out of the command by pressing CTRL+C, this statement will
continually display the value of the `$i` variable as it is incremented by 1 each time the loop is run.
-Rather than change the value of the variable in the statement list part of
-the `For` statement, you can use the **Repeat** portion of the `For`
-statement instead, as follows.
+Rather than change the value of the variable in the statement list part of the
+`For` statement, you can use the **Repeat** portion of the `For` statement
+instead, as follows.
```powershell $i=1
for (;;$i++)
This statement will still repeat indefinitely until you break out of the command by pressing CTRL+C.
-You can terminate the `For` loop using a *condition*. You can place a condition
-using the **Condition** portion of the `For` statement. The `For`
+You can terminate the `For` loop using a **condition**. You can place a
+condition using the **Condition** portion of the `For` statement. The `For`
loop terminates when the condition evaluates to `$false`. In the following example, the `For` loop runs while the value of `$i` is less
for(;$i -le 10;$i++)
} ```
-Instead of creating and initializing the variable outside the `For`
-statement, you can perform this task inside the `For` loop by using the
-**Init** portion of the `For` statement.
+Instead of creating and initializing the variable outside the `For` statement,
+you can perform this task inside the `For` loop by using the **Init** portion
+of the `For` statement.
```powershell for($i=1; $i -le 10; $i++){Write-Host $i} ```
-You can use carriage returns instead of semicolons to delimit the
-**Init**, **Condition**, and **Repeat** portions of the `For`
-statement. The following example shows a `For` that uses this alternative
-syntax.
+You can use carriage returns instead of semicolons to delimit the **Init**,
+**Condition**, and **Repeat** portions of the `For` statement. The following
+example shows a `For` that uses this alternative syntax.
```powershell for ($i = 0
for ($i = 0
``` This alternative form of the `For` statement works in PowerShell script files
-and at the PowerShell command prompt. However, it is easier to use
-the `For` statement syntax with semicolons when you enter interactive
-commands at the command prompt.
+and at the PowerShell command prompt. However, it is easier to use the `For`
+statement syntax with semicolons when you enter interactive commands at the
+command prompt.
The `For` loop is more flexible than the `Foreach` loop because it allows you to increment values in an array or collection by using patterns. In the
-following example, the `$i` variable is incremented by 2 in the
-**Repeat** portion of the `For` statement.
+following example, the `$i` variable is incremented by 2 in the **Repeat**
+portion of the `For` statement.
```powershell for ($i = 0; $i -le 20; $i += 2)
for ($i = 0; $i -lt 10; $i++) { Write-Host $i }
[about_Comparison_Operators](about_Comparison_Operators.md) [about_Foreach](about_Foreach.md)-
Microsoft.PowerShell.Utility Test Json (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Utility/Test-Json.md
--- external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/19/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/test-json?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Test-Json
Accept wildcard characters: False
### CommonParameters
-This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction,
--InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and--WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
+This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
+-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
+-WarningAction, and -WarningVariable. For more information, see
+[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
You can pipe a JSON string to `Test-Json`.
## NOTES
-The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+The `Test-Json` cmdlet is implemented by using the
+[NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+
+Since PowerShell 6, PowerShell uses the Newtonsoft.Json assemblies for all JSON functions.
+Newtonsoft's implementation includes several extensions to the JSON standard, such as support for
+comments and use of single quotes. For a full list of features, see the Newtonsoft documentation at
+[https://www.newtonsoft.com/json](https://www.newtonsoft.com/json).
## RELATED LINKS
Microsoft.PowerShell.Core About For (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_For.md
--- description: Describes a language command you can use to run statements based on a conditional test. Locale: en-US Previously updated : 03/04/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_for?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about For
The `For` statement (also known as a `For` loop) is a language construct you
can use to create a loop that runs commands in a command block while a specified condition evaluates to `$true`.
-A typical use of the `For` loop is to iterate an array of values and to
-operate on a subset of these values. In most cases, if you want to iterate
-all the values in an array, consider using a `Foreach` statement.
+A typical use of the `For` loop is to iterate an array of values and to operate
+on a subset of these values. In most cases, if you want to iterate all the
+values in an array, consider using a `Foreach` statement.
### Syntax
The **Init** placeholder represents one or more commands that are run before
the loop begins. You typically use the **Init** portion of the statement to create and initialize a variable with a starting value.
-This variable will then be the basis for the condition to be tested in the
-next portion of the `For` statement.
+This variable will then be the basis for the condition to be tested in the next
+portion of the `For` statement.
The **Condition** placeholder represents the portion of the `For` statement that resolves to a `$true` or `$false` **Boolean** value. PowerShell evaluates the condition each time the `For` loop runs. If the statement is `$true`, the commands in the command block run, and the statement is evaluated again. If the
-condition is still `$true`, the commands in the **Statement list** run again. The loop
-is repeated until the condition becomes `$false`.
+condition is still `$true`, the commands in the **Statement list** run again.
+The loop is repeated until the condition becomes `$false`.
-The **Repeat** placeholder represents one or more commands, separated
-by commas, that are executed each time the loop repeats. Typically, this is
-used to modify a variable that is tested inside the **Condition** part
-of the statement.
+The **Repeat** placeholder represents one or more commands, separated by
+commas, that are executed each time the loop repeats. Typically, this is used
+to modify a variable that is tested inside the **Condition** part of the
+statement.
-The **Statement list** placeholder represents a set of one or more
-commands that are run each time the loop is entered or repeated. The
-contents of the **Statement list** are surrounded by braces.
+The **Statement list** placeholder represents a set of one or more commands
+that are run each time the loop is entered or repeated. The contents of the
+**Statement list** are surrounded by braces.
### Support for multiple operations
The following syntaxes are supported for multiple assignment operations in the
```powershell # Comma separated assignment expressions.
-for (($i = 0), ($j = 0); $i -lt 10; $i++)
+for (($i = 0), ($j = 0); $i -lt 10; $i++, $j++)
{ "`$i:$i" "`$j:$j"
For more information, see [about_Logical_Operators](about_Logical_Operators.md).
### Examples At a minimum, a `For` statement requires the parenthesis surrounding the
-**Init**, **Condition**, and **Repeat** part of the statement
-and a command surrounded by braces in the **Statement list** part of
-the statement.
+**Init**, **Condition**, and **Repeat** part of the statement and a command
+surrounded by braces in the **Statement list** part of the statement.
Note that the upcoming examples intentionally show code outside the `For` statement. In later examples, code is integrated into the `For` statement.
for (;;)
} ```
-You can add additional commands to the statement list so that the value of
-`$i` is incremented by 1 each time the loop is run, as the following example
-shows.
+You can add additional commands to the statement list so that the value of `$i`
+is incremented by 1 each time the loop is run, as the following example shows.
```powershell for (;;)
Until you break out of the command by pressing CTRL+C, this statement will
continually display the value of the `$i` variable as it is incremented by 1 each time the loop is run.
-Rather than change the value of the variable in the statement list part of
-the `For` statement, you can use the **Repeat** portion of the `For`
-statement instead, as follows.
+Rather than change the value of the variable in the statement list part of the
+`For` statement, you can use the **Repeat** portion of the `For` statement
+instead, as follows.
```powershell $i=1
for (;;$i++)
This statement will still repeat indefinitely until you break out of the command by pressing CTRL+C.
-You can terminate the `For` loop using a *condition*. You can place a condition
-using the **Condition** portion of the `For` statement. The `For`
+You can terminate the `For` loop using a **condition**. You can place a
+condition using the **Condition** portion of the `For` statement. The `For`
loop terminates when the condition evaluates to `$false`. In the following example, the `For` loop runs while the value of `$i` is less
for(;$i -le 10;$i++)
} ```
-Instead of creating and initializing the variable outside the `For`
-statement, you can perform this task inside the `For` loop by using the
-**Init** portion of the `For` statement.
+Instead of creating and initializing the variable outside the `For` statement,
+you can perform this task inside the `For` loop by using the **Init** portion
+of the `For` statement.
```powershell for($i=1; $i -le 10; $i++){Write-Host $i} ```
-You can use carriage returns instead of semicolons to delimit the
-**Init**, **Condition**, and **Repeat** portions of the `For`
-statement. The following example shows a `For` that uses this alternative
-syntax.
+You can use carriage returns instead of semicolons to delimit the **Init**,
+**Condition**, and **Repeat** portions of the `For` statement. The following
+example shows a `For` that uses this alternative syntax.
```powershell for ($i = 0
for ($i = 0
``` This alternative form of the `For` statement works in PowerShell script files
-and at the PowerShell command prompt. However, it is easier to use
-the `For` statement syntax with semicolons when you enter interactive
-commands at the command prompt.
+and at the PowerShell command prompt. However, it is easier to use the `For`
+statement syntax with semicolons when you enter interactive commands at the
+command prompt.
The `For` loop is more flexible than the `Foreach` loop because it allows you to increment values in an array or collection by using patterns. In the
-following example, the `$i` variable is incremented by 2 in the
-**Repeat** portion of the `For` statement.
+following example, the `$i` variable is incremented by 2 in the **Repeat**
+portion of the `For` statement.
```powershell for ($i = 0; $i -le 20; $i += 2)
for ($i = 0; $i -lt 10; $i++) { Write-Host $i }
[about_Comparison_Operators](about_Comparison_Operators.md) [about_Foreach](about_Foreach.md)-
Microsoft.PowerShell.Utility Test Json (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Utility/Test-Json.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 09/19/2019 Last updated : 07/21/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/test-json?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Test-Json
Accept wildcard characters: False
### CommonParameters
-This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction,
--InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and--WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
+This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
+-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
+-WarningAction, and -WarningVariable. For more information, see
+[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
You can pipe a JSON string to `Test-Json`.
## NOTES
-The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+The `Test-Json` cmdlet is implemented by using the
+[NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
+
+Since PowerShell 6, PowerShell uses the Newtonsoft.Json assemblies for all JSON functions.
+Newtonsoft's implementation includes several extensions to the JSON standard, such as support for
+comments and use of single quotes. For a full list of features, see the Newtonsoft documentation at
+[https://www.newtonsoft.com/json](https://www.newtonsoft.com/json).
## RELATED LINKS
community Powershell Style Guide https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/community/contributing/powershell-style-guide.md
Warning block
location If you need to link to a specific version of a document, then you need to add the
- `&preserve_view=true` parameter to the query string. For example:
- `?view=powershell-5.1&preserve_view=true`
+ `&preserve-view=true` parameter to the query string. For example:
+ `?view=powershell-5.1&preserve-view=true`
- A **file link** is used to link from one reference article to another, or from one conceptual article to another. If you need to link to a reference article for a specific version of
whats-new Differences From Windows Powershell https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/differences-from-windows-powershell.md
--- Last updated 02/03/2020 Title: Differences between Windows PowerShell 5.1 and PowerShell (core) 7.x
+ Title: Differences between Windows PowerShell 5.1 and PowerShell 7.x
description: This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based on .NET Core. ---
-# Differences between Windows PowerShell 5.1 and PowerShell (core) 7.x
+# Differences between Windows PowerShell 5.1 and PowerShell 7.x
Windows PowerShell 5.1 is built on top of the .NET Framework v4.5. With the release of PowerShell 6.0, PowerShell became an open source project built on .NET Core 2.0. PowerShell 7.0 is built on
Windows PowerShell 5.1 is built on top of the .NET Framework v4.5. With the rele
from the .NET Framework to .NET Core allowed PowerShell to become a cross-platform solution. PowerShell runs on Windows, macOS, and Linux.
-There is little difference in the PowerShell language between Windows PowerShell and PowerShell
-(core). The differences are seen in the availability and behavior of PowerShell cmdlets between
-Windows and non-Windows platforms and the changes that stem from the differences between the .NET
-Framework and .NET Core.
+There are few differences in the PowerShell language between Windows PowerShell and PowerShell. The
+differences are most notable in the availability and behavior of PowerShell cmdlets between Windows
+and non-Windows platforms and the changes that stem from the differences between the .NET Framework
+and .NET Core.
This article summarizes the significant differences and breaking changes between Windows PowerShell and the current version of PowerShell. This summary does not include new features or cmdlets that
article is to present the current state of PowerShell and how that is different
PowerShell. For a detailed discussion of changes between versions and the addition of new features, see the **What's New** articles for each version.
+- [What's new in PowerShell 7.x](What-s-New-in-PowerShell-71.md)
+- [What's new in PowerShell 6.x](/previous-versions/powershell/scripting/whats-new/what-s-new-in-powershell-core-62?view=powershell-6&preserve-view=true)
+ ## .NET Framework vs .NET Core PowerShell on Linux and macOS uses .NET Core, which is a subset of the full .NET Framework on
For more information see:
[!INCLUDE [Product terminology](../../includes/product-terms.md)]
-## Modules not shipped for PowerShell (core)
+## Modules no longer shipped with PowerShell
For various compatibility reasons, the following modules are no longer included in PowerShell.
For various compatibility reasons, the following modules are no longer included
[Windows Workflow Foundation (WF)][workflow-foundation] that enables the creation of robust runbooks for long-running or parallelized tasks.
-Due to the lack of support for Windows Workflow Foundation in .NET Core, we are not supporting
-PowerShell Workflow in PowerShell (core).
+Due to the lack of support for Windows Workflow Foundation in .NET Core, we removed PowerShell
+Workflow from PowerShell.
In the future, we would like to enable native parallelism/concurrency in the PowerShell language without the need for PowerShell Workflow.
its own state (like persisting it to a file).
## Cmdlets removed from PowerShell
-For the modules that are included in PowerShell (core), the following cmdlets were removed from
-PowerShell for various compatibility reasons or the use of unsupported APIs.
+For the modules that are included in PowerShell, the following cmdlets were removed from PowerShell
+for various compatibility reasons or the use of unsupported APIs.
CimCmdlets
PSDesiredStateConfiguration
### WMI v1 cmdlets
-The following WMI v1 cmdlets were removed from PowerShell (core):
+The following WMI v1 cmdlets were removed from PowerShell:
- `Register-WmiEvent` - `Set-WmiInstance`
These cmdlets had very limited usage. The decision was made to discontinue suppo
### `*-EventLog` cmdlets
-Due to the use of unsupported APIs, the `*-EventLog` has been removed from PowerShell (core). until
-a better solution is found. `Get-WinEvent` and `New-WinEvent` are available to get and create events
-on Windows.
+Due to the use of unsupported APIs, the `*-EventLog` cmdlets have been removed from PowerShell.
+`Get-WinEvent` and `New-WinEvent` are available to get and create events on Windows.
### Cmdlets that use the Windows Presentation Framework (WPF)
in the PowerShell Team blog.
### Renamed `powershell.exe` to `pwsh.exe`
-The binary name for PowerShell (core) has been changed from `powershell(.exe)` to `pwsh(.exe)`. This
-change provides a deterministic way for users to run PowerShell (core) on machines to support
-side-by-side Windows PowerShell and PowerShell (core) installations. `pwsh` is also much shorter and
-easier to type.
+The binary name for PowerShell has been changed from `powershell(.exe)` to `pwsh(.exe)`. This
+change provides a deterministic way for users to run PowerShell on machines and support
+side-by-side installations of Windows PowerShell and PowerShell.
Additional changes to `pwsh(.exe)` from `powershell.exe`:
Additional changes to `pwsh(.exe)` from `powershell.exe`:
on non-Windows platforms. It also means that you can run commands like `pwsh foo.ps1` or `pwsh fooScript` without specifying `-File`. However, this change requires that you explicitly specify `-c` or `-Command` when trying to run commands like `pwsh.exe -Command Get-Command`.-- PowerShell (core) accepts the `-i` (or `-Interactive`) switch to indicate an interactive shell.
+- `pwsh` accepts the `-i` (or `-Interactive`) switch to indicate an interactive shell.
This allows PowerShell to be used as a default shell on Unix platforms. - Removed parameters `-ImportSystemModules` and `-PSConsoleFile` from `pwsh.exe`. - Changed `pwsh -version` and built-in help for `pwsh.exe` to align with other native tools.
as short hand to match `-inputformat`, which now needs to be `-in`.
adoption in the PowerShell community. Due to the complexity of supporting snap-ins and their lack of usage in the community, we no longer
-support custom snap-ins in PowerShell (core).
+support custom snap-ins in PowerShell.
[snapin]: /powershell/module/microsoft.powershell.core/about/about_pssnapins
class M {
### Check `system32` for compatible built-in modules on Windows In the Windows 10 1809 update and Windows Server 2019, we updated a number of built-in PowerShell
-modules to mark them as compatible with PowerShell (core).
+modules to mark them as compatible with PowerShell.
When PowerShell starts up, it automatically includes `$windir\System32` as part of the `PSModulePath` environment variable. However, it only exposes modules to `Get-Module` and
PowerShell Remoting (PSRP) using WinRM on Unix platforms requires NTLM/Negotiate
HTTPS. PSRP on macOS only supports Basic Auth over HTTPS. Kerberos-based authentication is not supported for non-Windows platforms.
-PowerShell (core) also supports PowerShell Remoting (PSRP) over SSH on all platforms (Windows, macOS,
-and Linux). For more information, see
+PowerShell also supports PowerShell Remoting (PSRP) over SSH on all platforms (Windows, macOS, and
+Linux). For more information, see
[SSH remoting in PowerShell](/powershell/scripting/learn/remoting/SSH-Remoting-in-PowerShell-Core).
-### PowerShell Direct for Containers tries to use PowerShell (core) first
+### PowerShell Direct for Containers tries to use `pwsh` first
[PowerShell Direct](/virtualization/hyper-v-on-windows/user-guide/powershell-direct) is a feature of PowerShell and Hyper-V that allows you to connect to a Hyper-V VM or Container without network
string:
## Telemetry can only be disabled with an environment variable
-PowerShell (core) sends basic telemetry data to Microsoft when it is launched. The data includes the
-OS name, OS version, and PowerShell version. This data allows us to better understand the
-environments where PowerShell is used and enables us to prioritize new features and fixes.
+PowerShell sends basic telemetry data to Microsoft when it is launched. The data includes the OS
+name, OS version, and PowerShell version. This data allows us to better understand the environments
+where PowerShell is used and enables us to prioritize new features and fixes.
To opt-out of this telemetry, set the environment variable `POWERSHELL_TELEMETRY_OPTOUT` to `true`, `yes`, or `1`. We no longer support deletion of the file
whats-new Unix Support https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/unix-support.md
--- Last updated 02/03/2020 Title: PowerShell differences on non-Windows platforms
-description: This article summarizes the differences between PowerShell (core) on Windows and PowerShell on non-Windows platforms.
+description: This article summarizes the differences between PowerShell on Windows and PowerShell on non-Windows platforms.
--- # PowerShell differences on non-Windows platforms
PowerShell Remoting (PSRP) using WinRM on Unix platforms requires NTLM/Negotiate
HTTPS. PSRP on macOS only supports Basic Auth over HTTPS. Kerberos-based authentication is not supported.
-PowerShell (core) also supports PowerShell Remoting (PSRP) over SSH on all platforms (Windows, macOS,
-and Linux). For more information, see
+PowerShell supports PowerShell Remoting (PSRP) over SSH on all platforms (Windows, macOS, and
+Linux). For more information, see
[SSH remoting in PowerShell](/powershell/scripting/learn/remoting/SSH-Remoting-in-PowerShell-Core). ## Just-Enough-Administration (JEA) Support
ones over time.
For a comprehensive list of modules and cmdlets and the platforms they support, see [Release history of modules and cmdlets](cmdlet-versions.md).
-## Modules not shipped for PowerShell (core)
+## Modules no longer shipped with PowerShell
For various compatibility reasons, the following modules are no longer included in PowerShell.
includes Product Terms https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/includes/product-terms.md
general, the concepts apply to all versions of PowerShell, unless the article ca
version. - **PowerShell** - This is the default name we use for the product. When we use this name in the
- documentation we are talking about the product in general, or the specifically identified version.
+ documentation we are talking about the current version of PowerShell. Differences between
+ PowerShell and Windows PowerShell are noted by noting the specific version.
- **Windows PowerShell** - PowerShell built on .NET Framework. Windows PowerShell ships only on
- Windows and requires the complete Framework. It is possible to run both PowerShell (core) and
- Windows PowerShell on the same Windows computer.
-- **PowerShell (core)** - PowerShell built on .NET Core. Usage of the term _core_ is limited to
- cases where it's necessary to differentiate it from Windows PowerShell.
+ Windows and requires the complete Framework. It is possible to run both PowerShell and Windows
+ PowerShell on the same Windows computer.