Updates from: 06/11/2021 03:23:16
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/About.md
---
-description: About topics cover a ranges of concepts about PowerShell.
-Download Help Link: https://Please-enter-FwLink-manually
+description: About topics cover a ranges of concepts about PowerShell.
Help Version: 6.0
-keywords: powershell,cmdlet
Locale: en-US
-Module Guid: 00000000-0000-0000-0000-000000000000
-Module Name: About
Last updated 02/25/2019
-schema: 2.0.0
Title: About topics --- # About topics
Describes how to run remote commands in PowerShell.
### [about_Remote_Disconnected_Sessions](about_Remote_Disconnected_Sessions.md) Explains how to disconnect from and reconnect to a PSSession.
-### [about_Remote_FAQ](about_Remote_FAQ.md)
-Contains questions and answers about running remote commands in PowerShell.
- ### [about_Remote_Jobs](about_Remote_Jobs.md) Describes how to run background jobs on remote computers.
Microsoft.PowerShell.Core About Arrays (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md
to accept them.
### Where Allows to filter or select the elements of the array. The script must evaluate
-to anything different than: zero (0), empty string, `$false` or `$null` for
-the element to show after the `Where`
+to anything different than: zero (0), empty string, `$false` or `$null` for the
+element to show after the `Where`. For more information about boolean
+evaluation, see [about_Booleans](about_Booleans.md).
There is one definition for the `Where` method.
Microsoft.PowerShell.Core About Booleans (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Booleans.md
+---
+description: Describes how boolean expressions are evaluated.
+Locale: en-US
Last updated : 06/10/2021
+no-loc:
+schema: 2.0.0
+ Title: about Booleans
+---
+# about_Booleans
+
+PowerShell can implicitly treat any type as a **Boolean**. It is important to
+understand the rules that PowerShell uses to convert other types to **Boolean**
+values.
+
+## Converting from scalar types
+
+A scalar type is an atomic quantity that can hold only one value at a time. The
+following types evaluate to `$false`:
+
+- Empty strings like `''` or `""`
+- Null values like `$null`
+- Any numeric type with the value of `0`
+
+Examples:
+
+```powershell
+PS> $false -eq ''
+True
+PS> if ("") { $true } else { $false }
+False
+PS> if ($null) { $true } else { $false }
+False
+PS> if ([int]0) { $true } else { $false }
+False
+PS> if ([double]0.0) { $true } else { $false }
+False
+```
+
+The following types evaluate to `$true`:
+
+- Non-empty strings
+- Instances of any other non-collection type
+
+Examples:
+
+```powershell
+# a non-collection type
+PS> [bool]@{value = 0}
+True
+# non-empty strings
+PS> if ('hello') { $true } else { $false }
+True
+PS> [bool]'False'
+True
+```
+
+Note that this differs from _explicit string parsing_:
+
+```powershell
+PS> [bool]::Parse('false')
+False
+PS> [bool]::Parse('True')
+True
+PS> [bool]::Parse('Not True')
+MethodInvocationException: Exception calling "Parse" with "1" argument(s):
+"String 'Not True' was not recognized as a valid Boolean."
+```
+
+## Converting from collection types
+
+Arrays are the most common collection type in PowerShell. These rules apply to
+any collection-like types that implement the
+[IList](/dotnet/api/system.collections.ilist) interface.
+
+- Empty collections are always `$false`
+- The special null value indicating the absence of output from a command,
+ `[System.Management.Automation.Internal.AutomationNull]::Value` is always
+ `$false`.
+- Single-element collections evaluate to the **Boolean** value of their one and
+ only element.
+- Collections with more than 1 element are always `$true`.
+
+Examples:
+
+```powershell
+# Empty collections
+PS> [bool]@()
+False
+PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt')
+False
+# Single-element collections
+PS> $a = @(0)
+PS> [bool]$a
+False
+PS> $b = @(1)
+PS> [bool]$b
+True
+# Multi-element collections
+PS> $c = @(0,0)
+PS> [bool]$c
+True
+```
+
+## See also
+
+- [about_Arrays](about_Arrays.md#where)
Microsoft.PowerShell.Core About Comparison Operators (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Comparison_Operators.md
--- description: Describes the operators that compare values in PowerShell. Locale: en-US Previously updated : 03/15/2021 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Comparison Operators
$a -isnot $b.GetType() # Output: True
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) - [Foreach-Object](xref:Microsoft.PowerShell.Core.ForEach-Object) - [Where-Object](xref:Microsoft.PowerShell.Core.Where-Object)
+- [about_Booleans](about_Booleans.md)
[1]: /dotnet/api/system.icomparable [2]: /dotnet/api/system.iequatable-1
Microsoft.PowerShell.Core About Do (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Do.md
---
-description: Runs a statement list one or more times, subject to a While or Until condition.
-keywords: powershell,cmdlet
+description: Runs a statement list one or more times, subject to a While or Until condition.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_do?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Do ---- # about_Do ## SHORT DESCRIPTION-
-Runs a statement list one or more times, subject to a While or Until
+Runs a statement list one or more times, subject to a `While` or `Until`
condition. ## LONG DESCRIPTION
-The Do keyword works with the While keyword or the Until keyword to run the
-statements in a script block, subject to a condition. Unlike the related
-While loop, the script block in a Do loop always runs at least once.
+The `Do` keyword works with the `While` keyword or the `Until` keyword to run
+the statements in a script block, subject to a condition. Unlike the related
+`While` loop, the script block in a `Do` loop always runs at least once.
-A **Do-While** loop is a variety of the While loop. In a **Do-While** loop,
-the condition is evaluated after the script block has run. As in a While
-loop, the script block is repeated as long as the condition evaluates to
-true.
+A **Do-While** loop is a variety of the `While` loop. In a **Do-While** loop,
+the condition is evaluated after the script block has run. As in a While loop,
+the script block is repeated as long as the condition evaluates to true.
Like a **Do-While** loop, a **Do-Until** loop always runs at least once before the condition is evaluated. However, the script block runs only while the condition is false.
-The *Continue* and *Break* flow control keywords can be used in a
-**Do-While** loop or in a **Do-Until** loop.
+The `Continue` and `Break` flow control keywords can be used in a **Do-While**
+loop or in a **Do-Until** loop.
### Syntax
The following shows the syntax of the **Do-Until** statement:
do {<statement list>} until (<condition>) ```
-The statement list contains one or more statements that run each time the
-loop is entered or repeated.
+The statement list contains one or more statements that run each time the loop
+is entered or repeated.
-The condition portion of the statement resolves to true or false.
+The condition portion of the statement resolves to true or false. For more
+information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
### Example
-The following example of a Do statement counts the items in an array until
-it reaches an item with a value of 0.
+The following example of a `Do` statement counts the items in an array until it
+reaches an item with a value of 0.
```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } while ($x[$a] -ne 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } while ($x[$a] -ne 0)
+PS> $count
3 ```
-The following example uses the Until keyword. Notice that the not equal to
+The following example uses the `Until` keyword. Notice that the not equal to
operator (`-ne`) is replaced by the equal to operator (`-eq`). ```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } until ($x[$a] -eq 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } until ($x[$a] -eq 0)
+PS> $count
3 ```
while (++$a -lt 10)
## SEE ALSO
-[about_While](about_While.md)
-
-[about_Operators](about_Operators.md)
-
-[about_Assignment_Operators](about_Assignment_Operators.md)
-
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Break](about_Break.md)
-
-[about_Continue](about_Continue.md)
+- [about_While](about_While.md)
+- [about_Operators](about_Operators.md)
+- [about_Assignment_Operators](about_Assignment_Operators.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Break](about_Break.md)
+- [about_Continue](about_Continue.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About If (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_If.md
---
-description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
-keywords: powershell,cmdlet
+description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about If ---- # about_If ## SHORT DESCRIPTION
-Describes a language command you can use to run statement lists based on
-the results of one or more conditional tests.
+Describes a language command you can use to run statement lists based on the
+results of one or more conditional tests.
## LONG DESCRIPTION+ You can use the `If` statement to run code blocks if a specified conditional
-test evaluates to true. You can also specify one or more additional
-conditional tests to run if all the prior tests evaluate to false. Finally,
-you can specify an additional code block that is run if no other prior
-conditional test evaluates to true.
+test evaluates to true. You can also specify one or more additional conditional
+tests to run if all the prior tests evaluate to false. Finally, you can specify
+an additional code block that is run if no other prior conditional test
+evaluates to true.
### Syntax
if (<test1>)
{<statement list 3>}] ```
-When you run an `If` statement, PowerShell evaluates the `<test1>`
-conditional expression as true or false. If `<test1>` is true,
-`<statement list 1>` runs, and PowerShell exits the `If` statement. If
-`<test1>` is false, PowerShell evaluates the condition specified by the
-`<test2>` conditional statement.
+When you run an `If` statement, PowerShell evaluates the `<test1>` conditional
+expression as true or false. If `<test1>` is true, `<statement list 1>` runs,
+and PowerShell exits the `If` statement. If `<test1>` is false, PowerShell
+evaluates the condition specified by the `<test2>` conditional statement.
-If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the
-`If` statement. If both `<test1>` and `<test2>` evaluate to false, the
-`<statement list 3`> code block runs, and PowerShell exits the If
-statement.
+For more information about boolean evaluation, see
+[about_Booleans](about_Booleans.md).
-You can use multiple Elseif statements to chain a series of conditional
-tests. So, that each test is run only if all the previous tests are false.
-If you need to create an `If` statement that contains many Elseif statements,
+If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the `If`
+statement. If both `<test1>` and `<test2>` evaluate to false, the
+`<statement list 3`> code block runs, and PowerShell exits the If statement.
+
+You can use multiple `Elseif` statements to chain a series of conditional
+tests. So, that each test is run only if all the previous tests are false. If
+you need to create an `If` statement that contains many `Elseif` statements,
consider using a Switch statement instead. Examples:
if ($a -gt 2) {
} ```
-In this example, if the $a variable is greater than 2, the condition
-evaluates to true, and the statement list runs. However, if $a is less than
-or equal to 2 or is not an existing variable, the `If` statement does not
-display a message.
+In this example, if the $a variable is greater than 2, the condition evaluates
+to true, and the statement list runs. However, if $a is less than or equal to 2
+or is not an existing variable, the `If` statement does not display a message.
By adding an Else statement, a message is displayed when $a is less than or equal to 2. As the next example shows:
else {
} ```
-To further refine this example, you can use the Elseif statement to display
-a message when the value of $a is equal to 2. As the next example shows:
+To further refine this example, you can use the Elseif statement to display a
+message when the value of $a is equal to 2. As the next example shows:
```powershell if ($a -gt 2) {
else {
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Switch](about_Switch.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Switch](about_Switch.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About Remote (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Remote.md
---
-description: Describes how to run remote commands in Windows PowerShell.
-keywords: powershell,cmdlet
+description: Describes how to run remote commands in PowerShell.
Locale: en-US Last updated 01/03/2018 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Remote ---- # about_Remote ## SHORT DESCRIPTION-
-Describes how to run remote commands in Windows PowerShell.
+Describes how to run remote commands in PowerShell.
## LONG DESCRIPTION
topics that describe each cmdlet that is used in these commands. The topics
provide the details and explain how you can modify the commands to meet your needs.
-Note: To use Windows PowerShell remoting, the local and remote computers must
+Note: To use PowerShell remoting, the local and remote computers must
be configured for remoting. For more information, see [about_Remote_Requirements](about_Remote_Requirements.md).
For more information, see Enter-PSSession.
Several cmdlets have a ComputerName parameter that lets you get objects from remote computers.
-Because these cmdlets do not use WS-Management-based Windows PowerShell
+Because these cmdlets do not use WS-Management-based PowerShell
remoting, you can use the ComputerName parameter of these cmdlets on any
-computer that is running Windows PowerShell. The computers do not have to be
-configured for Windows PowerShell remoting, and the computers do not have to
+computer that is running PowerShell. The computers do not have to be
+configured for PowerShell remoting, and the computers do not have to
meet the system requirements for remoting. The following cmdlets have a ComputerName parameter:
remote computer where it terminates the remote command.
- For information about how remoting works, how to manage remote data, special configurations, security issues, and other frequently asked questions, see
- [about_Remote_FAQ](about_Remote_FAQ.md).
+ [PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml).
- For help in resolving remoting errors, see about_Remote_Troubleshooting. - For information about PSSessions and persistent connections, see [about_PSSessions](about_PSSessions.md). -- For information about Windows PowerShell background jobs, see [about_Jobs](about_Jobs.md).
+- For information about PowerShell background jobs, see [about_Jobs](about_Jobs.md).
## KEYWORDS
about_Remoting
[about_Remote_Requirements](about_Remote_Requirements.md)
-[about_Remote_FAQ](about_Remote_FAQ.md)
+[PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml)
[about_Remote_TroubleShooting](about_Remote_TroubleShooting.md)
Microsoft.PowerShell.Core About Remote FAQ (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Remote_FAQ.md
-description: Contains questions and answers about running remote commands in PowerShell.
-keywords: powershell,cmdlet
-Locale: en-US
Previously updated : 07/23/2020
-online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote_faq?view=powershell-5.1&WT.mc_id=ps-gethelp
-schema: 2.0.0
Title: about Remote FAQ
-# about_Remote_FAQ
-
-## Short description
-Contains questions and answers about running remote commands in PowerShell.
-
-## Long description
-
-When you work remotely, you type commands in PowerShell on one computer (known
-as the "local computer"), but the commands run on another computer (known as
-the "remote computer"). The experience of working remotely should be as much
-like working directly at the remote computer as possible.
-
-Note: To use PowerShell remoting, the remote computer must be configured for
-remoting. For more information, see
-[about_Remote_Requirements](about_Remote_Requirements.md).
-
-### Must both computers have PowerShell installed?
-
-Yes. To work remotely, the local and remote computers must have PowerShell, the
-Microsoft .NET Framework, and the Web Services for Management (WS-Management)
-protocol. Any files and other resources that are needed to execute a particular
-command must be on the remote computer.
-
-Computers running Windows PowerShell 3.0 and computers running Windows
-PowerShell 2.0 can connect to each other remotely and run remote commands.
-However, some features, such as the ability to disconnect from a session and
-reconnect to it, work only when both computers are running Windows PowerShell
-3.0.
-
-You must have permission to connect to the remote computer, permission to run
-PowerShell, and permission to access data stores (such as files and folders),
-and the registry on the remote computer.
-
-For more information, see [about_Remote_Requirements](about_Remote_Requirements.md).
-
-### How does remoting work?
-
-When you submit a remote command, the command is transmitted across the network
-to the PowerShell engine on the remote computer, and it runs in the PowerShell
-client on the remote computer. The command results are sent back to the local
-computer and appear in the PowerShell session on the local computer.
-
-To transmit the commands and receive the output, PowerShell uses the
-WS-Management protocol. For information about the WS-Management protocol, see
-[WS-Management Protocol](/windows/win32/winrm/ws-management-protocol) in the
-Windows documentation.
-
-Beginning in Windows PowerShell 3.0, remote sessions are stored on the remote
-computer. This enables you to disconnect from the session and reconnect from a
-different session or a different computer without interrupting the commands or
-losing state.
-
-### Is PowerShell remoting secure?
-
-When you connect to a remote computer, the system uses the username and
-password credentials on the local computer or the credentials that you supply
-in the command to log you in to the remote computer. The credentials and the
-rest of the transmission are encrypted.
-
-To add additional protection, you can configure the remote computer to use
-Secure Sockets Layer (SSL) instead of HTTP to listen for Windows Remote
-Management (WinRM) requests. Then, users can use the **UseSSL** parameter of
-the `Invoke-Command`, `New-PSSession`, and `Enter-PSSession` cmdlets when
-establishing a connection. This option uses the more secure HTTPS channel
-instead of HTTP.
-
-### Do all remote commands require PowerShell remoting?
-
-No. Several cmdlets have a **ComputerName** parameter that lets you get objects
-from the remote computer.
-
-These cmdlets do not use PowerShell remoting. So, you can use them on any
-computer that is running PowerShell, even if the computer is not configured for
-PowerShell remoting or if the computer does not meet the requirements for
-PowerShell remoting.
-
-These cmdlets include the following:
--- `Get-Process`-- `Get-Service`-- `Get-WinEvent`-- `Get-EventLog`-- `Test-Connection`-
-To find all the cmdlets with a **ComputerName** parameter, type:
-
-```powershell
-Get-Help * -Parameter ComputerName
-# or
-Get-Command -ParameterName ComputerName
-```
-
-To determine whether the **ComputerName** parameter of a particular cmdlet
-requires PowerShell remoting, see the parameter description. To display the
-parameter description, type:
-
-```powershell
-Get-Help <cmdlet-name> -Parameter ComputerName
-```
-
-For example:
-
-```powershell
-Get-Help Get-Process -Parameter ComputerName
-```
-
-For all other commands, use the `Invoke-Command` cmdlet.
-
-### How do I run a command on a remote computer?
-
-To run a command on a remote computer, use the `Invoke-Command` cmdlet.
-
-Enclose your command in braces (`{}`) to make it a script block. Use the
-**ScriptBlock** parameter of `Invoke-Command` to specify the command.
-
-You can use the **ComputerName** parameter of `Invoke-Command` to specify a
-remote computer. Or, you can create a persistent connection to a remote
-computer (a session) and then use the **Session** parameter of `Invoke-Command`
-to run the command in the session.
-
-For example, the following commands run a `Get-Process` command remotely.
-
-```powershell
-Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Process}
-
-# - OR -
-
-Invoke-Command -Session $s -ScriptBlock {Get-Process}
-```
-
-To interrupt a remote command, type <kbd>CTRL</kbd>+<kbd>C</kbd>. The
-interruption request is passed to the remote computer, where it terminates the
-remote command.
-
-For more information about remote commands, see about_Remote and the Help
-topics for the cmdlets that support remoting.
-
-### Can I just telnet into a remote computer?
-
-You can use the `Enter-PSSession` cmdlet to start an interactive session with a
-remote computer.
-
-At the PowerShell prompt, type:
-
-```powershell
-Enter-PSSession <ComputerName>
-```
-
-The command prompt changes to show that you are connected to the remote
-computer.
-
-```
-<ComputerName>\C:>
-```
-
-Now, the commands that you type run on the remote computer just as though you
-typed them directly on the remote computer.
-
-To end the interactive session, type:
-
-```powershell
-Exit-PSSession
-```
-
-An interactive session is a persistent session that uses the WS-Management
-protocol. It is not the same as using Telnet, but it provides a similar
-experience.
-
-For more information, see `Enter-PSSession`.
-
-### Can I create a persistent connection?
-
-Yes. You can run remote commands by specifying the name of the remote computer,
-its NetBIOS name, or its IP address. Or, you can run remote commands by
-specifying a PowerShell session (PSSession) that is connected to the remote
-computer.
-
-When you use the **ComputerName** parameter of `Invoke-Command` or
-`Enter-PSSession`, PowerShell establishes a temporary connection. PowerShell
-uses the connection to run only the current command, and then it closes the
-connection. This is a very efficient method for running a single command or
-several unrelated commands, even on many remote computers.
-
-When you use the `New-PSSession` cmdlet to create a PSSession, PowerShell
-establishes a persistent connection for the PSSession. Then, you can run
-multiple commands in the PSSession, including commands that share data.
-
-Typically, you create a PSSession to run a series of related commands that
-share data. Otherwise, the temporary connection created by the **ComputerName**
-parameter is sufficient for most commands.
-
-For more information about sessions, see about_PSSessions.
-
-### Can I run commands on more than one computer at a time?
-
-Yes. The **ComputerName** parameter of the `Invoke-Command` cmdlet accepts
-multiple computer names, and the **Session** parameter accepts multiple
-PSSessions.
-
-When you run an `Invoke-Command` command, PowerShell runs the commands on all
-of the specified computers or in all of the specified PSSessions.
-
-PowerShell can manage hundreds of concurrent remote connections. However, the
-number of remote commands that you can send might be limited by the resources
-of your computer and its capacity to establish and maintain multiple network
-connections.
-
-For more information, see the example in the `Invoke-Command` Help topic.
-
-### Where are my profiles?
-
-PowerShell profiles are not run automatically in remote sessions, so the
-commands that the profile adds are not present in the session. In addition, the
-`$profile` automatic variable is not populated in remote sessions.
-
-To run a profile in a session, use the `Invoke-Command` cmdlet.
-
-For example, the following command runs the CurrentUserCurrentHost profile
-from the local computer in the session in `$s`.
-
-```
-Invoke-Command -Session $s -FilePath $profile
-```
-
-The following command runs the CurrentUserCurrentHost profile from the remote
-computer in the session in `$s`. Because the `$profile` variable is not populated,
-the command uses the explicit path to the profile.
-
-```powershell
-Invoke-Command -Session $s {
- . "$home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
-}
-```
-
-After running this command, the commands that the profile adds to the session
-are available in `$s`.
-
-You can also use a startup script in a session configuration to run a profile
-in every remote session that uses the session configuration.
-
-For more information about PowerShell profiles, see about_Profiles.
-For more information about session configurations, see
-`Register-PSSessionConfiguration`.
-
-### How does throttling work on remote commands?
-
-To help you manage the resources on your local computer, PowerShell
-includes a per-command throttling feature that lets you limit the number of
-concurrent remote connections that are established for each command.
-
-The default is 32 concurrent connections, but you can use the **ThrottleLimit**
-parameter of the cmdlets to set a custom throttle limit for particular
-commands.
-
-When you use the throttling feature, remember that it is applied to each
-command, not to the entire session or to the computer. If you are running
-commands concurrently in several sessions or PSSessions, the number of
-concurrent connections is the sum of the concurrent connections in all the
-sessions.
-
-To find cmdlets with a **ThrottleLimit** parameter, type:
-
-```
-Get-Help * -Parameter ThrottleLimit
--or-
-Get-Command -ParameterName ThrottleLimit
-```
-
-### Is the output of remote commands different from local output?
-
-When you use PowerShell locally, you send and receive "live" .NET
-Framework objects; "live" objects are objects that are associated with actual
-programs or system components. When you invoke the methods or change the
-properties of live objects, the changes affect the actual program or
-component. And, when the properties of a program or component change, the
-properties of the object that represent them also change.
-
-However, because most live objects cannot be transmitted over the network,
-PowerShell "serializes" most of the objects sent in remote commands,
-that is, it converts each object into a series of XML (Constraint Language in
-XML [CLiXML]) data elements for transmission.
-
-When PowerShell receives a serialized object, it converts the XML into
-a deserialized object type. The deserialized object is an accurate record of
-the properties of the program or component at a previous time, but it is no
-longer "live", that is, it is no longer directly associated with the
-component. And, the methods are removed because they are no longer effective.
-
-Typically, you can use deserialized objects just as you would use live
-objects, but you must be aware of their limitations. Also, the objects that
-are returned by the `Invoke-Command` cmdlet have additional properties that help
-you to determine the origin of the command.
-
-Some object types, such as DirectoryInfo objects and GUIDs, are converted back
-into live objects when they are received. These objects do not need any
-special handling or formatting.
-
-For information about interpreting and formatting remote output, see
-[about_Remote_Output](about_Remote_Output.md).
-
-### Can I run background jobs remotely?
-
-Yes. A PowerShell background job is a PowerShell command that
-runs asynchronously without interacting with the session. When you start a
-background job, the command prompt returns immediately, and you can continue
-to work in the session while the job runs even if it runs for an extended
-period of time.
-
-You can start a background job even while other commands are running because
-background jobs always run asynchronously in a temporary session.
-
-You can run background jobs on a local or remote computer. By default, a
-background job runs on the local computer. However, you can use the **AsJob**
-parameter of the `Invoke-Command` cmdlet to run any remote command as a
-background job. And, you can use `Invoke-Command` to run a `Start-Job` command
-remotely.
-
-For more information about background jobs in PowerShell , see
-[about_Jobs(about_Jobs.md)] and [about_Remote_Jobs(about_Remote_Jobs.md)].
-
-### Can I run windows programs on a remote computer?
-
-You can use PowerShell remote commands to run Windows-based programs on remote
-computers. For example, you can run `Shutdown.exe` or `Ipconfig.exe` on a
-remote computer.
-
-However, you cannot use PowerShell commands to open the user interface
-for any program on a remote computer.
-
-When you start a Windows program on a remote computer, the command is not
-completed, and the PowerShell command prompt does not return, until the program
-is finished or until you press <kbd>CTRL</kbd>+<kbd>C</kbd> to interrupt the
-command. For example, if you run the `Ipconfig.exe` program on a remote
-computer, the command prompt does not return until `Ipconfig.exe` is completed.
-
-If you use remote commands to start a program that has a user interface, the
-program process starts, but the user interface does not appear. The PowerShell
-command is not completed, and the command prompt does not return until you stop
-the program process or until you press <kbd>CTRL</kbd>+<kbd>C</kbd>, which
-interrupts the command and stops the process.
-
-For example, if you use a PowerShell command to run `Notepad` on a
-remote computer, the Notepad process starts on the remote computer, but the
-Notepad user interface does not appear. To interrupt the command and restore
-the command prompt, press <kbd>CTRL</kbd>+<kbd>C</kbd>.
-
-### Can I limit the commands that users can run remotely on my computer?
-
-Yes. Every remote session must use one of the session configurations on the
-remote computer. You can manage the session configurations on your computer
-(and the permissions to those session configurations) to determine who can run
-commands remotely on your computer and which commands they can run.
-
-A session configuration configures the environment for the session. You can
-define the configuration by using an assembly that implements a new
-configuration class or by using a script that runs in the session. The
-configuration can determine the commands that are available in the session.
-And, the configuration can include settings that protect the computer, such as
-settings that limit the amount of data that the session can receive remotely
-in a single object or command. You can also specify a security descriptor that
-determines the permissions that are required to use the configuration.
-
-The `Enable-PSRemoting` cmdlet creates the default session configurations on
-your computer: Microsoft.PowerShell, Microsoft.PowerShell.Workflow, and
-Microsoft.PowerShell32 (64-bit operating systems only). `Enable-PSRemoting` sets
-the security descriptor for the configuration to allow only members of the
-Administrators group on your computer to use them.
-
-You can use the session configuration cmdlets to edit the default session
-configurations, to create new session configurations, and to change the
-security descriptors of all the session configurations.
-
-Beginning in Windows PowerShell 3.0, the `New-PSSessionConfigurationFile` cmdlet
-lets you create custom session configurations by using a text file. The file
-includes options for setting the language mode and for specifying the cmdlets
-and modules that are available in sessions that use the session configuration.
-
-When users use the `Invoke-Command`, `New-PSSession`, or `Enter-PSSession`
-cmdlets, they can use the **ConfigurationName** parameter to indicate the
-session configuration that is used for the session. And, they can change the
-default configuration that their sessions use by changing the value of the
-`$PSSessionConfigurationName` preference variable in the session.
-
-For more information about session configurations, see the Help for the
-session configuration cmdlets. To find the session configuration cmdlets,
-type:
-
-```powershell
-Get-Command *PSSessionConfiguration
-```
-
-### What are fan in and fan out configurations?
-
-The most common PowerShell remoting scenario involving multiple
-computers is the one-to-many configuration, in which one local computer (the
-administrator's computer) runs PowerShell commands on numerous remote
-computers. This is known as the "fan-out" scenario.
-
-However, in some enterprises, the configuration is many-to-one, where many
-client computers connect to a single remote computer that is running
-PowerShell, such as a file server or a kiosk. This is known as the "fan-in"
-configuration.
-
-PowerShell remoting supports both fan-out and fan-in configurations.
-
-For the fan-out configuration, PowerShell uses the Web Services for
-Management (WS-Management) protocol and the WinRM service that supports the
-Microsoft implementation of WS-Management. When a local computer connects to a
-remote computer, WS-Management establishes a connection and uses a plug-in for
-PowerShell to start the PowerShell host process
-(Wsmprovhost.exe) on the remote computer. The user can specify an alternate
-port, an alternate session configuration, and other features to customize the
-remote connection.
-
-To support the "fan-in" configuration, PowerShell uses internet Information
-Services (IIS) to host WS-Management, to load the PowerShell plug-in, and to
-start PowerShell. In this scenario, instead of starting each PowerShell session
-in a separate process, all PowerShell sessions run in the same host process.
-
-IIS hosting and fan-in remote management is not supported in Windows XP or in
-Windows Server 2003.
-
-In a fan-in configuration, the user can specify a connection URI and an HTTP
-endpoint, including the transport, computer name, port, and application name.
-IIS forwards all the requests with a specified application name to the
-application. The default is WS-Management, which can host PowerShell.
-
-You can also specify an authentication mechanism and prohibit or allow
-redirection from HTTP and HTTPS endpoints.
-
-### Can I test remoting on a single computer not in a domain?
-
-Yes. PowerShell remoting is available even when the local computer is
-not in a domain. You can use the remoting features to connect to sessions and
-to create sessions on the same computer. The features work the same as they do
-when you connect to a remote computer.
-
-To run remote commands on a computer in a workgroup, change the following
-Windows settings on the computer.
-
-Caution: These settings affect all users on the system and they can make the
-system more vulnerable to a malicious attack. Use caution when making these
-changes.
--- Windows Vista, Windows 7, Windows 8:-
- Create the following registry entry, and then set its value to 1:
- LocalAccountTokenFilterPolicy in
- ` HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System`
-
- You can use the following PowerShell command to add this entry:
-
- ```powershell
- $parameters = @{
- Path='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
- Name='LocalAccountTokenFilterPolicy'
- propertyType='DWord'
- Value=1
- }
- New-ItemProperty @parameters
- ```
--- Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows
- Server 2012 R2:
-
- No changes are needed because the default setting of the "Network Access:
- Sharing and security model for local accounts" policy is "Classic". Verify
- the setting in case it has changed.
-
-### Can I run remote commands on a computer in another domain?
-
-Yes. Typically, the commands run without error, although you might need to use
-the **Credential** parameter of the `Invoke-Command`, `New-PSSession`, or
-`Enter-PSSession` cmdlets to provide the credentials of a member of the
-Administrators group on the remote computer. This is sometimes required even
-when the current user is a member of the Administrators group on the local and
-remote computers.
-
-However, if the remote computer is not in a domain that the local computer
-trusts, the remote computer might not be able to authenticate the user's
-credentials.
-
-To enable authentication, use the following command to add the remote computer
-to the list of trusted hosts for the local computer in WinRM. Type the command
-at the PowerShell prompt.
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value <Remote-computer-name>
-```
-
-For example, to add the Server01 computer to the list of trusted hosts on the
-local computer, type the following command at the PowerShell prompt:
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value Server01
-```
--
-## See also
-
-[about_Remote](about_Remote.md)
-
-[about_Profiles](about_Profiles.md)
-
-[about_PSSessions](about_PSSessions.md)
-
-[about_Remote_Jobs](about_Remote_Jobs.md)
-
-[about_Remote_Variables](about_Remote_Variables.md)
-
-[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command)
-
-[New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)
Microsoft.PowerShell.Core About Switch (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Switch.md
---
-description: Explains how to use a switch to handle multiple `If` statements.
-keywords: powershell,cmdlet
+description: Explains how to use a switch to handle multiple `If` statements.
Locale: en-US Previously updated : 05/22/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Switch
switch -Regex ($target)
https://bing.com is a web address that uses https ```
-A Switch statement condition may be either:
+A `Switch` statement condition may be either:
- An expression whose value is compared to the input value - A script block which should return `$true` if a condition is met.
-The `$_` automatic variable contains the value passed to the switch statement
+The `$_` automatic variable contains the value passed to the `switch` statement
and is available for evaluation and use within the scope of the condition statements.
Microsoft.PowerShell.Core About While (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_While.md
---
-description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
-keywords: powershell,cmdlet
+description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_while?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about While ---- # about_While ## SHORT DESCRIPTION
-Describes a language statement that you can use to run a command block
-based on the results of a conditional test.
+Describes a language statement that you can use to run a command block based on
+the results of a conditional test.
## LONG DESCRIPTION
-The While statement (also known as a While loop) is a language construct
+
+The `While` statement (also known as a `While` loop) is a language construct
for creating a loop that runs commands in a command block as long as a
-conditional test evaluates to true. The While statement is easier to
+conditional test evaluates to true. The `While` statement is easier to
construct than a For statement because its syntax is less complicated. In
-addition, it is more flexible than the Foreach statement because you
-specify a conditional test in the While statement to control how many times
-the loop runs.
+addition, it is more flexible than the Foreach statement because you specify a
+conditional test in the `While` statement to control how many times the loop
+runs.
The following shows the While statement syntax:
The following shows the While statement syntax:
while (<condition>){<statement list>} ```
-When you run a While statement, PowerShell evaluates the `<condition>`
-section of the statement before entering the `<statement list>` section. The
-condition portion of the statement resolves to either true or false. As
-long as the condition remains true, PowerShell reruns the `<statement list>`
-section.
+When you run a While statement, PowerShell evaluates the `<condition>` section
+of the statement before entering the `<statement list>` section. The condition
+portion of the statement resolves to either true or false. As long as the
+condition remains true, PowerShell reruns the `<statement list>` section. For
+more information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
-The `<statement list>` section of the statement contains one or more
-commands that are run each time the loop is entered or repeated.
+The `<statement list>` section of the statement contains one or more commands
+that are run each time the loop is entered or repeated.
-For example, the following While statement displays the numbers 1 through 3
-if the $val variable has not been created or if the $val variable has been
+For example, the following While statement displays the numbers 1 through 3 if
+the `$val` variable has not been created or if the `$val` variable has been
created and initialized to 0. ```powershell
while($val -ne 3)
} ```
-In this example, the condition ($val is not equal to 3) is true while $val
-\= 0, 1, 2. Each time through the loop, $val is incremented by 1 using the
-\+\+ unary increment operator ($val\+\+). The last time through the loop,
-$val \= 3. When $val equals 3, the condition statement evaluates to false,
-and the loop exits.
+In this example, the condition (`$val` is not equal to 3) is true while `$val`
+is equal to 0, 1, and 2. Each time through the loop, `$val` is incremented by 1
+using the `++` unary increment operator. The last time through the loop `$val`
+is set to 3, the condition statement evaluates to false, and the loop exits.
To conveniently write this command at the PowerShell command prompt, you can enter it in the following way:
can enter it in the following way:
while($val -ne 3){$val++; Write-Host $val} ```
-Notice that the semicolon separates the first command that adds 1 to $val
-from the second command that writes the value of $val to the console.
+Notice that the semicolon separates the first command that adds 1 to `$val` from
+the second command that writes the value of `$val` to the console.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Do](about_Do.md)
-
-[about_Foreach](about_Foreach.md)
-
-[about_For](about_For.md)
-
-[about_Language_Keywords](about_Language_Keywords.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Do](about_Do.md)
+- [about_Foreach](about_Foreach.md)
+- [about_For](about_For.md)
+- [about_Language_Keywords](about_Language_Keywords.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core Where Object (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/Where-Object.md
--- external help file: System.Management.Automation.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Core Previously updated : 03/19/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Where-Object
Selects objects from a collection based on their property values.
### EqualSet (Default) ```
-Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] [-EQ] [<CommonParameters>]
+Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] [-EQ]
+ [<CommonParameters>]
``` ### ScriptBlockSet
The previous example is functionally equivalent to:
- `('hi', '', 'there') | Where-Object Length -GT 0` - `('hi', '', 'there') | Where-Object {$_.Length -gt 0}`
+For more information about how booleans are evaluated, see [about_Booleans](about/about_Booleans.md).
+ ## EXAMPLES ### Example 1: Get stopped services
for the command.
```powershell # Use Where-Object to get commands that have any value for the OutputType property of the command.
-# This omits commands that do not have an OutputType property and those that have an OutputType property, but no property value.
+# This omits commands that do not have an OutputType property and those that have an OutputType
+# property, but no property value.
Get-Command | where OutputType Get-Command | where {$_.OutputType} ``` ```powershell # Use Where-Object to get objects that are containers.
-# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all others.
+# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all
+# others.
Get-ChildItem | where PSIsContainer Get-ChildItem | where {$_.PSIsContainer} ``` ```powershell # Finally, use the Not operator (!) to get objects that are not containers.
-# This gets objects that do have the **PSIsContainer** property and those that have a value of $False for the **PSIsContainer** property.
+# This gets objects that do have the **PSIsContainer** property and those that have a value of
+# $False for the **PSIsContainer** property.
Get-ChildItem | where {!$_.PSIsContainer} # You cannot use the Not operator (!) in the comparison statement format of the command. Get-ChildItem | where PSIsContainer -eq $False
The example uses the script block command format. Logical operators, such as **A
valid only in script blocks. You cannot use them in the comparison statement format of a `Where-Object` command. -- For more information about PowerShell logical operators, see [about_Logical_Operators](./About/about_logical_operators.md).-- For more information about the Updatable Help feature, see [about_Updatable_Help](./About/about_Updatable_Help.md).
+- For more information about PowerShell logical operators, see
+ [about_Logical_Operators](./About/about_logical_operators.md).
+- For more information about the Updatable Help feature, see
+ [about_Updatable_Help](./About/about_Updatable_Help.md).
## PARAMETERS
You can read more about these new methods here [about_arrays](./About/about_Arra
[Sort-Object](../Microsoft.PowerShell.Utility/Sort-Object.md) [Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)+
+[about_Booleans](about/about_Booleans.md)
Microsoft.PowerShell.Core About (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/About.md
---
-description: About topics cover a ranges of concepts about PowerShell.
-Download Help Link: https://Please-enter-FwLink-manually
+description: About topics cover a ranges of concepts about PowerShell.
Help Version: 6.0
-keywords: powershell,cmdlet
Locale: en-US
-Module Guid: 00000000-0000-0000-0000-000000000000
-Module Name: About
Last updated 02/25/2019
-schema: 2.0.0
Title: About topics --- # About topics
Describes how to run remote commands in PowerShell.
### [about_Remote_Disconnected_Sessions](about_Remote_Disconnected_Sessions.md) Explains how to disconnect from and reconnect to a PSSession.
-### [about_Remote_FAQ](about_Remote_FAQ.md)
-Contains questions and answers about running remote commands in PowerShell.
- ### [about_Remote_Jobs](about_Remote_Jobs.md) Describes how to run background jobs on remote computers.
Microsoft.PowerShell.Core About Arrays (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Arrays.md
to accept them.
### Where Allows to filter or select the elements of the array. The script must evaluate
-to anything different than: zero (0), empty string, `$false` or `$null` for
-the element to show after the `Where`
+to anything different than: zero (0), empty string, `$false` or `$null` for the
+element to show after the `Where`. For more information about boolean
+evaluation, see [about_Booleans](about_Booleans.md).
There is one definition for the `Where` method.
Microsoft.PowerShell.Core About Booleans (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Booleans.md
+---
+description: Describes how boolean expressions are evaluated.
+Locale: en-US
Last updated : 06/10/2021
+no-loc:
+schema: 2.0.0
+ Title: about Booleans
+---
+# about_Booleans
+
+PowerShell can implicitly treat any type as a **Boolean**. It is important to
+understand the rules that PowerShell uses to convert other types to **Boolean**
+values.
+
+## Converting from scalar types
+
+A scalar type is an atomic quantity that can hold only one value at a time. The
+following types evaluate to `$false`:
+
+- Empty strings like `''` or `""`
+- Null values like `$null`
+- Any numeric type with the value of `0`
+
+Examples:
+
+```powershell
+PS> $false -eq ''
+True
+PS> if ("") { $true } else { $false }
+False
+PS> if ($null) { $true } else { $false }
+False
+PS> if ([int]0) { $true } else { $false }
+False
+PS> if ([double]0.0) { $true } else { $false }
+False
+```
+
+The following types evaluate to `$true`:
+
+- Non-empty strings
+- Instances of any other non-collection type
+
+Examples:
+
+```powershell
+# a non-collection type
+PS> [bool]@{value = 0}
+True
+# non-empty strings
+PS> if ('hello') { $true } else { $false }
+True
+PS> [bool]'False'
+True
+```
+
+Note that this differs from _explicit string parsing_:
+
+```powershell
+PS> [bool]::Parse('false')
+False
+PS> [bool]::Parse('True')
+True
+PS> [bool]::Parse('Not True')
+MethodInvocationException: Exception calling "Parse" with "1" argument(s):
+"String 'Not True' was not recognized as a valid Boolean."
+```
+
+## Converting from collection types
+
+Arrays are the most common collection type in PowerShell. These rules apply to
+any collection-like types that implement the
+[IList](/dotnet/api/system.collections.ilist) interface.
+
+- Empty collections are always `$false`
+- The special null value indicating the absence of output from a command,
+ `[System.Management.Automation.Internal.AutomationNull]::Value` is always
+ `$false`.
+- Single-element collections evaluate to the **Boolean** value of their one and
+ only element.
+- Collections with more than 1 element are always `$true`.
+
+Examples:
+
+```powershell
+# Empty collections
+PS> [bool]@()
+False
+PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt')
+False
+# Single-element collections
+PS> $a = @(0)
+PS> [bool]$a
+False
+PS> $b = @(1)
+PS> [bool]$b
+True
+# Multi-element collections
+PS> $c = @(0,0)
+PS> [bool]$c
+True
+```
+
+## See also
+
+- [about_Arrays](about_Arrays.md#where)
Microsoft.PowerShell.Core About Comparison Operators (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Comparison_Operators.md
--- description: Describes the operators that compare values in PowerShell. Locale: en-US Previously updated : 03/15/2021 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Comparison Operators
$a -isnot $b.GetType() # Output: True
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) - [Foreach-Object](xref:Microsoft.PowerShell.Core.ForEach-Object) - [Where-Object](xref:Microsoft.PowerShell.Core.Where-Object)
+- [about_Booleans](about_Booleans.md)
[1]: /dotnet/api/system.icomparable [2]: /dotnet/api/system.iequatable-1
Microsoft.PowerShell.Core About Do (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Do.md
---
-description: Runs a statement list one or more times, subject to a While or Until condition.
-keywords: powershell,cmdlet
+description: Runs a statement list one or more times, subject to a While or Until condition.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_do?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Do
Title: about Do
# about_Do ## SHORT DESCRIPTION
-Runs a statement list one or more times, subject to a While or Until
+Runs a statement list one or more times, subject to a `While` or `Until`
condition. ## LONG DESCRIPTION
-The Do keyword works with the While keyword or the Until keyword to run the
-statements in a script block, subject to a condition. Unlike the related
-While loop, the script block in a Do loop always runs at least once.
+The `Do` keyword works with the `While` keyword or the `Until` keyword to run
+the statements in a script block, subject to a condition. Unlike the related
+`While` loop, the script block in a `Do` loop always runs at least once.
-A **Do-While** loop is a variety of the While loop. In a **Do-While** loop,
-the condition is evaluated after the script block has run. As in a While
-loop, the script block is repeated as long as the condition evaluates to
-true.
+A **Do-While** loop is a variety of the `While` loop. In a **Do-While** loop,
+the condition is evaluated after the script block has run. As in a While loop,
+the script block is repeated as long as the condition evaluates to true.
Like a **Do-While** loop, a **Do-Until** loop always runs at least once before the condition is evaluated. However, the script block runs only while the condition is false.
-The *Continue* and *Break* flow control keywords can be used in a
-**Do-While** loop or in a **Do-Until** loop.
+The `Continue` and `Break` flow control keywords can be used in a **Do-While**
+loop or in a **Do-Until** loop.
### Syntax
The following shows the syntax of the **Do-Until** statement:
do {<statement list>} until (<condition>) ```
-The statement list contains one or more statements that run each time the
-loop is entered or repeated.
+The statement list contains one or more statements that run each time the loop
+is entered or repeated.
-The condition portion of the statement resolves to true or false.
+The condition portion of the statement resolves to true or false. For more
+information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
### Example
-The following example of a Do statement counts the items in an array until
-it reaches an item with a value of 0.
+The following example of a `Do` statement counts the items in an array until it
+reaches an item with a value of 0.
```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } while ($x[$a] -ne 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } while ($x[$a] -ne 0)
+PS> $count
3 ```
-The following example uses the Until keyword. Notice that the not equal to
+The following example uses the `Until` keyword. Notice that the not equal to
operator (`-ne`) is replaced by the equal to operator (`-eq`). ```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } until ($x[$a] -eq 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } until ($x[$a] -eq 0)
+PS> $count
3 ```
while (++$a -lt 10)
## SEE ALSO
-[about_While](about_While.md)
-
-[about_Operators](about_Operators.md)
-
-[about_Assignment_Operators](about_Assignment_Operators.md)
-
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Break](about_Break.md)
-
-[about_Continue](about_Continue.md)
+- [about_While](about_While.md)
+- [about_Operators](about_Operators.md)
+- [about_Assignment_Operators](about_Assignment_Operators.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Break](about_Break.md)
+- [about_Continue](about_Continue.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About If (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_If.md
---
-description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
-keywords: powershell,cmdlet
+description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about If
Title: about If
# about_If ## SHORT DESCRIPTION
-Describes a language command you can use to run statement lists based on
-the results of one or more conditional tests.
+Describes a language command you can use to run statement lists based on the
+results of one or more conditional tests.
## LONG DESCRIPTION You can use the `If` statement to run code blocks if a specified conditional
-test evaluates to true. You can also specify one or more additional
-conditional tests to run if all the prior tests evaluate to false. Finally,
-you can specify an additional code block that is run if no other prior
-conditional test evaluates to true.
+test evaluates to true. You can also specify one or more additional conditional
+tests to run if all the prior tests evaluate to false. Finally, you can specify
+an additional code block that is run if no other prior conditional test
+evaluates to true.
### Syntax
if (<test1>)
{<statement list 3>}] ```
-When you run an `If` statement, PowerShell evaluates the `<test1>`
-conditional expression as true or false. If `<test1>` is true,
-`<statement list 1>` runs, and PowerShell exits the `If` statement. If
-`<test1>` is false, PowerShell evaluates the condition specified by the
-`<test2>` conditional statement.
+When you run an `If` statement, PowerShell evaluates the `<test1>` conditional
+expression as true or false. If `<test1>` is true, `<statement list 1>` runs,
+and PowerShell exits the `If` statement. If `<test1>` is false, PowerShell
+evaluates the condition specified by the `<test2>` conditional statement.
-If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the
-`If` statement. If both `<test1>` and `<test2>` evaluate to false, the
-`<statement list 3`> code block runs, and PowerShell exits the If
-statement.
+For more information about boolean evaluation, see
+[about_Booleans](about_Booleans.md).
-You can use multiple Elseif statements to chain a series of conditional
-tests. So, that each test is run only if all the previous tests are false.
-If you need to create an `If` statement that contains many Elseif statements,
+If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the `If`
+statement. If both `<test1>` and `<test2>` evaluate to false, the
+`<statement list 3`> code block runs, and PowerShell exits the If statement.
+
+You can use multiple `Elseif` statements to chain a series of conditional
+tests. So, that each test is run only if all the previous tests are false. If
+you need to create an `If` statement that contains many `Elseif` statements,
consider using a Switch statement instead. Examples:
if ($a -gt 2) {
} ```
-In this example, if the $a variable is greater than 2, the condition
-evaluates to true, and the statement list runs. However, if $a is less than
-or equal to 2 or is not an existing variable, the `If` statement does not
-display a message.
+In this example, if the $a variable is greater than 2, the condition evaluates
+to true, and the statement list runs. However, if $a is less than or equal to 2
+or is not an existing variable, the `If` statement does not display a message.
By adding an Else statement, a message is displayed when $a is less than or equal to 2. As the next example shows:
else {
} ```
-To further refine this example, you can use the Elseif statement to display
-a message when the value of $a is equal to 2. As the next example shows:
+To further refine this example, you can use the Elseif statement to display a
+message when the value of $a is equal to 2. As the next example shows:
```powershell if ($a -gt 2) {
else {
### Using the ternary operator syntax
-PowerShell 7.0 introduced a new syntax using the ternary operator. It follows the C# ternary
-operator syntax:
+PowerShell 7.0 introduced a new syntax using the ternary operator. It follows
+the C# ternary operator syntax:
```Syntax <condition> ? <if-true> : <if-false> ```
-The ternary operator behaves like the simplified `if-else` statement. The `<condition>` expression
-is evaluated and the result is converted to a boolean to determine which branch should be evaluated
-next:
+The ternary operator behaves like the simplified `if-else` statement. The
+`<condition>` expression is evaluated and the result is converted to a boolean
+to determine which branch should be evaluated next:
-- The `<if-true>` expression is executed if the `<condition>` expression is true-- The `<if-false>` expression is executed if the `<condition>` expression is false
+- The `<if-true>` expression is executed if the `<condition>` expression is
+ true
+- The `<if-false>` expression is executed if the `<condition>` expression is
+ false
For example:
For example:
$message = (Test-Path $path) ? "Path exists" : "Path not found" ```
-In this example, the value of `$message` is "Path exists" when `Test-Path` returns `$true`. When
-`Test-Path` returns `$false`, the value of `$message` is "Path not found".
+In this example, the value of `$message` is "Path exists" when `Test-Path`
+returns `$true`. When `Test-Path` returns `$false`, the value of `$message` is
+"Path not found".
```powershell $service = Get-Service BITS $service.Status -eq 'Running' ? (Stop-Service $service) : (Start-Service $service) ```
-In this example, if the service is running, it is stopped, and if its status is not **Running**,
-it is started.
+In this example, if the service is running, it is stopped, and if its status is
+not **Running**, it is started.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Switch](about_Switch.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Switch](about_Switch.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About Remote (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Remote.md
--- description: Describes how to run remote commands in PowerShell.
-keywords: powershell,cmdlet
Locale: en-US Last updated 01/03/2018 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote?view=powershell-7&WT.mc_id=ps-gethelp
remote computer where it terminates the remote command.
- For information about how remoting works, how to manage remote data, special configurations, security issues, and other frequently asked questions, see
- [about_Remote_FAQ](about_Remote_FAQ.md).
+ [PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml).
- For help in resolving remoting errors, see about_Remote_Troubleshooting.
about_Remoting
[about_Remote_Requirements](about_Remote_Requirements.md)
-[about_Remote_FAQ](about_Remote_FAQ.md)
+[PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml)
[about_Remote_TroubleShooting](about_Remote_TroubleShooting.md)
Microsoft.PowerShell.Core About Remote FAQ (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Remote_FAQ.md
-description: Contains questions and answers about running remote commands in PowerShell.
-keywords: powershell,cmdlet
-Locale: en-US
Previously updated : 07/23/2020
-online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote_faq?view=powershell-7&WT.mc_id=ps-gethelp
-schema: 2.0.0
Title: about Remote FAQ
-# about_Remote_FAQ
-
-## Short description
-Contains questions and answers about running remote commands in PowerShell.
-
-## Long description
-
-When you work remotely, you type commands in PowerShell on one computer (known
-as the "local computer"), but the commands run on another computer (known as
-the "remote computer"). The experience of working remotely should be as much
-like working directly at the remote computer as possible.
-
-Note: To use PowerShell remoting, the remote computer must be configured for
-remoting. For more information, see
-[about_Remote_Requirements](about_Remote_Requirements.md).
-
-### Must both computers have PowerShell installed?
-
-Yes. To work remotely, the local and remote computers must have PowerShell, the
-Microsoft .NET Framework, and the Web Services for Management (WS-Management)
-protocol. Any files and other resources that are needed to execute a particular
-command must be on the remote computer.
-
-Computers running Windows PowerShell 3.0 and computers running Windows
-PowerShell 2.0 can connect to each other remotely and run remote commands.
-However, some features, such as the ability to disconnect from a session and
-reconnect to it, work only when both computers are running Windows PowerShell
-3.0.
-
-You must have permission to connect to the remote computer, permission to run
-PowerShell, and permission to access data stores (such as files and folders),
-and the registry on the remote computer.
-
-For more information, see [about_Remote_Requirements](about_Remote_Requirements.md).
-
-### How does remoting work?
-
-When you submit a remote command, the command is transmitted across the network
-to the PowerShell engine on the remote computer, and it runs in the PowerShell
-client on the remote computer. The command results are sent back to the local
-computer and appear in the PowerShell session on the local computer.
-
-To transmit the commands and receive the output, PowerShell uses the
-WS-Management protocol. For information about the WS-Management protocol, see
-[WS-Management Protocol](/windows/win32/winrm/ws-management-protocol) in the
-Windows documentation.
-
-Beginning in Windows PowerShell 3.0, remote sessions are stored on the remote
-computer. This enables you to disconnect from the session and reconnect from a
-different session or a different computer without interrupting the commands or
-losing state.
-
-### Is PowerShell remoting secure?
-
-When you connect to a remote computer, the system uses the username and
-password credentials on the local computer or the credentials that you supply
-in the command to log you in to the remote computer. The credentials and the
-rest of the transmission are encrypted.
-
-To add additional protection, you can configure the remote computer to use
-Secure Sockets Layer (SSL) instead of HTTP to listen for Windows Remote
-Management (WinRM) requests. Then, users can use the **UseSSL** parameter of
-the `Invoke-Command`, `New-PSSession`, and `Enter-PSSession` cmdlets when
-establishing a connection. This option uses the more secure HTTPS channel
-instead of HTTP.
-
-### Do all remote commands require PowerShell remoting?
-
-No. Several cmdlets have a **ComputerName** parameter that lets you get objects
-from the remote computer.
-
-These cmdlets do not use PowerShell remoting. So, you can use them on any
-computer that is running PowerShell, even if the computer is not configured for
-PowerShell remoting or if the computer does not meet the requirements for
-PowerShell remoting.
-
-These cmdlets include the following:
--- `Get-Process`-- `Get-Service`-- `Get-WinEvent`-- `Get-EventLog`-- `Test-Connection`-
-To find all the cmdlets with a **ComputerName** parameter, type:
-
-```powershell
-Get-Help * -Parameter ComputerName
-# or
-Get-Command -ParameterName ComputerName
-```
-
-To determine whether the **ComputerName** parameter of a particular cmdlet
-requires PowerShell remoting, see the parameter description. To display the
-parameter description, type:
-
-```powershell
-Get-Help <cmdlet-name> -Parameter ComputerName
-```
-
-For example:
-
-```powershell
-Get-Help Get-Process -Parameter ComputerName
-```
-
-For all other commands, use the `Invoke-Command` cmdlet.
-
-### How do I run a command on a remote computer?
-
-To run a command on a remote computer, use the `Invoke-Command` cmdlet.
-
-Enclose your command in braces (`{}`) to make it a script block. Use the
-**ScriptBlock** parameter of `Invoke-Command` to specify the command.
-
-You can use the **ComputerName** parameter of `Invoke-Command` to specify a
-remote computer. Or, you can create a persistent connection to a remote
-computer (a session) and then use the **Session** parameter of `Invoke-Command`
-to run the command in the session.
-
-For example, the following commands run a `Get-Process` command remotely.
-
-```powershell
-Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Process}
-
-# - OR -
-
-Invoke-Command -Session $s -ScriptBlock {Get-Process}
-```
-
-To interrupt a remote command, type <kbd>CTRL</kbd>+<kbd>C</kbd>. The
-interruption request is passed to the remote computer, where it terminates the
-remote command.
-
-For more information about remote commands, see about_Remote and the Help
-topics for the cmdlets that support remoting.
-
-### Can I just telnet into a remote computer?
-
-You can use the `Enter-PSSession` cmdlet to start an interactive session with a
-remote computer.
-
-At the PowerShell prompt, type:
-
-```powershell
-Enter-PSSession <ComputerName>
-```
-
-The command prompt changes to show that you are connected to the remote
-computer.
-
-```
-<ComputerName>\C:>
-```
-
-Now, the commands that you type run on the remote computer just as though you
-typed them directly on the remote computer.
-
-To end the interactive session, type:
-
-```powershell
-Exit-PSSession
-```
-
-An interactive session is a persistent session that uses the WS-Management
-protocol. It is not the same as using Telnet, but it provides a similar
-experience.
-
-For more information, see `Enter-PSSession`.
-
-### Can I create a persistent connection?
-
-Yes. You can run remote commands by specifying the name of the remote computer,
-its NetBIOS name, or its IP address. Or, you can run remote commands by
-specifying a PowerShell session (PSSession) that is connected to the remote
-computer.
-
-When you use the **ComputerName** parameter of `Invoke-Command` or
-`Enter-PSSession`, PowerShell establishes a temporary connection. PowerShell
-uses the connection to run only the current command, and then it closes the
-connection. This is a very efficient method for running a single command or
-several unrelated commands, even on many remote computers.
-
-When you use the `New-PSSession` cmdlet to create a PSSession, PowerShell
-establishes a persistent connection for the PSSession. Then, you can run
-multiple commands in the PSSession, including commands that share data.
-
-Typically, you create a PSSession to run a series of related commands that
-share data. Otherwise, the temporary connection created by the **ComputerName**
-parameter is sufficient for most commands.
-
-For more information about sessions, see about_PSSessions.
-
-### Can I run commands on more than one computer at a time?
-
-Yes. The **ComputerName** parameter of the `Invoke-Command` cmdlet accepts
-multiple computer names, and the **Session** parameter accepts multiple
-PSSessions.
-
-When you run an `Invoke-Command` command, PowerShell runs the commands on all
-of the specified computers or in all of the specified PSSessions.
-
-PowerShell can manage hundreds of concurrent remote connections. However, the
-number of remote commands that you can send might be limited by the resources
-of your computer and its capacity to establish and maintain multiple network
-connections.
-
-For more information, see the example in the `Invoke-Command` Help topic.
-
-### Where are my profiles?
-
-PowerShell profiles are not run automatically in remote sessions, so the
-commands that the profile adds are not present in the session. In addition, the
-`$profile` automatic variable is not populated in remote sessions.
-
-To run a profile in a session, use the `Invoke-Command` cmdlet.
-
-For example, the following command runs the CurrentUserCurrentHost profile
-from the local computer in the session in `$s`.
-
-```
-Invoke-Command -Session $s -FilePath $profile
-```
-
-The following command runs the CurrentUserCurrentHost profile from the remote
-computer in the session in `$s`. Because the `$profile` variable is not populated,
-the command uses the explicit path to the profile.
-
-```powershell
-Invoke-Command -Session $s {
- . "$home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
-}
-```
-
-After running this command, the commands that the profile adds to the session
-are available in `$s`.
-
-You can also use a startup script in a session configuration to run a profile
-in every remote session that uses the session configuration.
-
-For more information about PowerShell profiles, see about_Profiles.
-For more information about session configurations, see
-`Register-PSSessionConfiguration`.
-
-### How does throttling work on remote commands?
-
-To help you manage the resources on your local computer, PowerShell
-includes a per-command throttling feature that lets you limit the number of
-concurrent remote connections that are established for each command.
-
-The default is 32 concurrent connections, but you can use the **ThrottleLimit**
-parameter of the cmdlets to set a custom throttle limit for particular
-commands.
-
-When you use the throttling feature, remember that it is applied to each
-command, not to the entire session or to the computer. If you are running
-commands concurrently in several sessions or PSSessions, the number of
-concurrent connections is the sum of the concurrent connections in all the
-sessions.
-
-To find cmdlets with a **ThrottleLimit** parameter, type:
-
-```
-Get-Help * -Parameter ThrottleLimit
--or-
-Get-Command -ParameterName ThrottleLimit
-```
-
-### Is the output of remote commands different from local output?
-
-When you use PowerShell locally, you send and receive "live" .NET
-Framework objects; "live" objects are objects that are associated with actual
-programs or system components. When you invoke the methods or change the
-properties of live objects, the changes affect the actual program or
-component. And, when the properties of a program or component change, the
-properties of the object that represent them also change.
-
-However, because most live objects cannot be transmitted over the network,
-PowerShell "serializes" most of the objects sent in remote commands,
-that is, it converts each object into a series of XML (Constraint Language in
-XML [CLiXML]) data elements for transmission.
-
-When PowerShell receives a serialized object, it converts the XML into
-a deserialized object type. The deserialized object is an accurate record of
-the properties of the program or component at a previous time, but it is no
-longer "live", that is, it is no longer directly associated with the
-component. And, the methods are removed because they are no longer effective.
-
-Typically, you can use deserialized objects just as you would use live
-objects, but you must be aware of their limitations. Also, the objects that
-are returned by the `Invoke-Command` cmdlet have additional properties that help
-you to determine the origin of the command.
-
-Some object types, such as DirectoryInfo objects and GUIDs, are converted back
-into live objects when they are received. These objects do not need any
-special handling or formatting.
-
-For information about interpreting and formatting remote output, see
-[about_Remote_Output](about_Remote_Output.md).
-
-### Can I run background jobs remotely?
-
-Yes. A PowerShell background job is a PowerShell command that
-runs asynchronously without interacting with the session. When you start a
-background job, the command prompt returns immediately, and you can continue
-to work in the session while the job runs even if it runs for an extended
-period of time.
-
-You can start a background job even while other commands are running because
-background jobs always run asynchronously in a temporary session.
-
-You can run background jobs on a local or remote computer. By default, a
-background job runs on the local computer. However, you can use the **AsJob**
-parameter of the `Invoke-Command` cmdlet to run any remote command as a
-background job. And, you can use `Invoke-Command` to run a `Start-Job` command
-remotely.
-
-For more information about background jobs in PowerShell , see
-[about_Jobs(about_Jobs.md)] and [about_Remote_Jobs(about_Remote_Jobs.md)].
-
-### Can I run windows programs on a remote computer?
-
-You can use PowerShell remote commands to run Windows-based programs on remote
-computers. For example, you can run `Shutdown.exe` or `Ipconfig.exe` on a
-remote computer.
-
-However, you cannot use PowerShell commands to open the user interface
-for any program on a remote computer.
-
-When you start a Windows program on a remote computer, the command is not
-completed, and the PowerShell command prompt does not return, until the program
-is finished or until you press <kbd>CTRL</kbd>+<kbd>C</kbd> to interrupt the
-command. For example, if you run the `Ipconfig.exe` program on a remote
-computer, the command prompt does not return until `Ipconfig.exe` is completed.
-
-If you use remote commands to start a program that has a user interface, the
-program process starts, but the user interface does not appear. The PowerShell
-command is not completed, and the command prompt does not return until you stop
-the program process or until you press <kbd>CTRL</kbd>+<kbd>C</kbd>, which
-interrupts the command and stops the process.
-
-For example, if you use a PowerShell command to run `Notepad` on a
-remote computer, the Notepad process starts on the remote computer, but the
-Notepad user interface does not appear. To interrupt the command and restore
-the command prompt, press <kbd>CTRL</kbd>+<kbd>C</kbd>.
-
-### Can I limit the commands that users can run remotely on my computer?
-
-Yes. Every remote session must use one of the session configurations on the
-remote computer. You can manage the session configurations on your computer
-(and the permissions to those session configurations) to determine who can run
-commands remotely on your computer and which commands they can run.
-
-A session configuration configures the environment for the session. You can
-define the configuration by using an assembly that implements a new
-configuration class or by using a script that runs in the session. The
-configuration can determine the commands that are available in the session.
-And, the configuration can include settings that protect the computer, such as
-settings that limit the amount of data that the session can receive remotely
-in a single object or command. You can also specify a security descriptor that
-determines the permissions that are required to use the configuration.
-
-The `Enable-PSRemoting` cmdlet creates the default session configurations on
-your computer: Microsoft.PowerShell, Microsoft.PowerShell.Workflow, and
-Microsoft.PowerShell32 (64-bit operating systems only). `Enable-PSRemoting` sets
-the security descriptor for the configuration to allow only members of the
-Administrators group on your computer to use them.
-
-You can use the session configuration cmdlets to edit the default session
-configurations, to create new session configurations, and to change the
-security descriptors of all the session configurations.
-
-Beginning in Windows PowerShell 3.0, the `New-PSSessionConfigurationFile` cmdlet
-lets you create custom session configurations by using a text file. The file
-includes options for setting the language mode and for specifying the cmdlets
-and modules that are available in sessions that use the session configuration.
-
-When users use the `Invoke-Command`, `New-PSSession`, or `Enter-PSSession`
-cmdlets, they can use the **ConfigurationName** parameter to indicate the
-session configuration that is used for the session. And, they can change the
-default configuration that their sessions use by changing the value of the
-`$PSSessionConfigurationName` preference variable in the session.
-
-For more information about session configurations, see the Help for the
-session configuration cmdlets. To find the session configuration cmdlets,
-type:
-
-```powershell
-Get-Command *PSSessionConfiguration
-```
-
-### What are fan in and fan out configurations?
-
-The most common PowerShell remoting scenario involving multiple
-computers is the one-to-many configuration, in which one local computer (the
-administrator's computer) runs PowerShell commands on numerous remote
-computers. This is known as the "fan-out" scenario.
-
-However, in some enterprises, the configuration is many-to-one, where many
-client computers connect to a single remote computer that is running
-PowerShell, such as a file server or a kiosk. This is known as the "fan-in"
-configuration.
-
-PowerShell remoting supports both fan-out and fan-in configurations.
-
-For the fan-out configuration, PowerShell uses the Web Services for
-Management (WS-Management) protocol and the WinRM service that supports the
-Microsoft implementation of WS-Management. When a local computer connects to a
-remote computer, WS-Management establishes a connection and uses a plug-in for
-PowerShell to start the PowerShell host process
-(Wsmprovhost.exe) on the remote computer. The user can specify an alternate
-port, an alternate session configuration, and other features to customize the
-remote connection.
-
-To support the "fan-in" configuration, PowerShell uses internet Information
-Services (IIS) to host WS-Management, to load the PowerShell plug-in, and to
-start PowerShell. In this scenario, instead of starting each PowerShell session
-in a separate process, all PowerShell sessions run in the same host process.
-
-IIS hosting and fan-in remote management is not supported in Windows XP or in
-Windows Server 2003.
-
-In a fan-in configuration, the user can specify a connection URI and an HTTP
-endpoint, including the transport, computer name, port, and application name.
-IIS forwards all the requests with a specified application name to the
-application. The default is WS-Management, which can host PowerShell.
-
-You can also specify an authentication mechanism and prohibit or allow
-redirection from HTTP and HTTPS endpoints.
-
-### Can I test remoting on a single computer not in a domain?
-
-Yes. PowerShell remoting is available even when the local computer is
-not in a domain. You can use the remoting features to connect to sessions and
-to create sessions on the same computer. The features work the same as they do
-when you connect to a remote computer.
-
-To run remote commands on a computer in a workgroup, change the following
-Windows settings on the computer.
-
-Caution: These settings affect all users on the system and they can make the
-system more vulnerable to a malicious attack. Use caution when making these
-changes.
--- Windows Vista, Windows 7, Windows 8:-
- Create the following registry entry, and then set its value to 1:
- LocalAccountTokenFilterPolicy in
- ` HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System`
-
- You can use the following PowerShell command to add this entry:
-
- ```powershell
- $parameters = @{
- Path='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
- Name='LocalAccountTokenFilterPolicy'
- propertyType='DWord'
- Value=1
- }
- New-ItemProperty @parameters
- ```
--- Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows
- Server 2012 R2:
-
- No changes are needed because the default setting of the "Network Access:
- Sharing and security model for local accounts" policy is "Classic". Verify
- the setting in case it has changed.
-
-### Can I run remote commands on a computer in another domain?
-
-Yes. Typically, the commands run without error, although you might need to use
-the **Credential** parameter of the `Invoke-Command`, `New-PSSession`, or
-`Enter-PSSession` cmdlets to provide the credentials of a member of the
-Administrators group on the remote computer. This is sometimes required even
-when the current user is a member of the Administrators group on the local and
-remote computers.
-
-However, if the remote computer is not in a domain that the local computer
-trusts, the remote computer might not be able to authenticate the user's
-credentials.
-
-To enable authentication, use the following command to add the remote computer
-to the list of trusted hosts for the local computer in WinRM. Type the command
-at the PowerShell prompt.
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value <Remote-computer-name>
-```
-
-For example, to add the Server01 computer to the list of trusted hosts on the
-local computer, type the following command at the PowerShell prompt:
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value Server01
-```
-
-### Does PowerShell support remoting over SSH?
-
-Yes. For more information, see
-[PowerShell remoting over SSH](/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core).
-
-## See also
-
-[about_Remote](about_Remote.md)
-
-[about_Profiles](about_Profiles.md)
-
-[about_PSSessions](about_PSSessions.md)
-
-[about_Remote_Jobs](about_Remote_Jobs.md)
-
-[about_Remote_Variables](about_Remote_Variables.md)
-
-[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command)
-
-[New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)
Microsoft.PowerShell.Core About Switch (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Switch.md
---
-description: Explains how to use a switch to handle multiple `If` statements.
-keywords: powershell,cmdlet
+description: Explains how to use a switch to handle multiple `If` statements.
Locale: en-US Previously updated : 2/27/2019 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Switch
switch -Regex ($target)
https://bing.com is a web address that uses https ```
-A Switch statement condition may be either:
+A `Switch` statement condition may be either:
- An expression whose value is compared to the input value - A script block which should return `$true` if a condition is met.
-The `$_` automatic variable contains the value passed to the switch statement
+The `$_` automatic variable contains the value passed to the `switch` statement
and is available for evaluation and use within the scope of the condition statements.
Microsoft.PowerShell.Core About While (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_While.md
---
-description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
-keywords: powershell,cmdlet
+description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_while?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about While
Title: about While
# about_While ## SHORT DESCRIPTION
-Describes a language statement that you can use to run a command block
-based on the results of a conditional test.
+Describes a language statement that you can use to run a command block based on
+the results of a conditional test.
## LONG DESCRIPTION
-The While statement (also known as a While loop) is a language construct
+The `While` statement (also known as a `While` loop) is a language construct
for creating a loop that runs commands in a command block as long as a
-conditional test evaluates to true. The While statement is easier to
+conditional test evaluates to true. The `While` statement is easier to
construct than a For statement because its syntax is less complicated. In
-addition, it is more flexible than the Foreach statement because you
-specify a conditional test in the While statement to control how many times
-the loop runs.
+addition, it is more flexible than the Foreach statement because you specify a
+conditional test in the `While` statement to control how many times the loop
+runs.
The following shows the While statement syntax:
The following shows the While statement syntax:
while (<condition>){<statement list>} ```
-When you run a While statement, PowerShell evaluates the `<condition>`
-section of the statement before entering the `<statement list>` section. The
-condition portion of the statement resolves to either true or false. As
-long as the condition remains true, PowerShell reruns the `<statement list>`
-section.
+When you run a While statement, PowerShell evaluates the `<condition>` section
+of the statement before entering the `<statement list>` section. The condition
+portion of the statement resolves to either true or false. As long as the
+condition remains true, PowerShell reruns the `<statement list>` section. For
+more information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
-The `<statement list>` section of the statement contains one or more
-commands that are run each time the loop is entered or repeated.
+The `<statement list>` section of the statement contains one or more commands
+that are run each time the loop is entered or repeated.
-For example, the following While statement displays the numbers 1 through 3
-if the $val variable has not been created or if the $val variable has been
+For example, the following While statement displays the numbers 1 through 3 if
+the `$val` variable has not been created or if the `$val` variable has been
created and initialized to 0. ```powershell
while($val -ne 3)
} ```
-In this example, the condition ($val is not equal to 3) is true while $val
-\= 0, 1, 2. Each time through the loop, $val is incremented by 1 using the
-\+\+ unary increment operator ($val\+\+). The last time through the loop,
-$val \= 3. When $val equals 3, the condition statement evaluates to false,
-and the loop exits.
+In this example, the condition (`$val` is not equal to 3) is true while `$val`
+is equal to 0, 1, and 2. Each time through the loop, `$val` is incremented by 1
+using the `++` unary increment operator. The last time through the loop `$val`
+is set to 3, the condition statement evaluates to false, and the loop exits.
To conveniently write this command at the PowerShell command prompt, you can enter it in the following way:
can enter it in the following way:
while($val -ne 3){$val++; Write-Host $val} ```
-Notice that the semicolon separates the first command that adds 1 to $val
-from the second command that writes the value of $val to the console.
+Notice that the semicolon separates the first command that adds 1 to `$val` from
+the second command that writes the value of `$val` to the console.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Do](about_Do.md)
-
-[about_Foreach](about_Foreach.md)
-
-[about_For](about_For.md)
-
-[about_Language_Keywords](about_Language_Keywords.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Do](about_Do.md)
+- [about_Foreach](about_Foreach.md)
+- [about_For](about_For.md)
+- [about_Language_Keywords](about_Language_Keywords.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core Where Object (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/Where-Object.md
--- external help file: System.Management.Automation.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Core Previously updated : 03/19/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Where-Object
The previous example is functionally equivalent to:
- `('hi', '', 'there') | Where-Object Length -GT 0` - `('hi', '', 'there') | Where-Object {$_.Length -gt 0}`
+For more information about how booleans are evaluated, see [about_Booleans](about/about_Booleans.md).
+ ## EXAMPLES ### Example 1: Get stopped services
for the command.
```powershell # Use Where-Object to get commands that have any value for the OutputType property of the command.
-# This omits commands that do not have an OutputType property and those that have an OutputType property, but no property value.
+# This omits commands that do not have an OutputType property and those that have an OutputType
+# property, but no property value.
Get-Command | where OutputType Get-Command | where {$_.OutputType} ``` ```powershell # Use Where-Object to get objects that are containers.
-# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all others.
+# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all
+# others.
Get-ChildItem | where PSIsContainer Get-ChildItem | where {$_.PSIsContainer} ``` ```powershell # Finally, use the Not operator (!) to get objects that are not containers.
-# This gets objects that do have the **PSIsContainer** property and those that have a value of $False for the **PSIsContainer** property.
+# This gets objects that do have the **PSIsContainer** property and those that have a value of
+# $False for the **PSIsContainer** property.
Get-ChildItem | where {!$_.PSIsContainer} # You cannot use the Not operator (!) in the comparison statement format of the command. Get-ChildItem | where PSIsContainer -eq $False
The example uses the script block command format. Logical operators, such as **A
valid only in script blocks. You cannot use them in the comparison statement format of a `Where-Object` command. -- For more information about PowerShell logical operators, see [about_Logical_Operators](./About/about_logical_operators.md).-- For more information about the Updatable Help feature, see [about_Updatable_Help](./About/about_Updatable_Help.md).
+- For more information about PowerShell logical operators, see
+ [about_Logical_Operators](./About/about_logical_operators.md).
+- For more information about the Updatable Help feature, see
+ [about_Updatable_Help](./About/about_Updatable_Help.md).
## PARAMETERS
This cmdlet returns selected items from the input object set.
## NOTES
-Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with collections.
+Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with
+collections.
You can read more about these new methods here [about_arrays](./About/about_Arrays.md)
You can read more about these new methods here [about_arrays](./About/about_Arra
[Sort-Object](../Microsoft.PowerShell.Utility/Sort-Object.md) [Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)+
+[about_Booleans](about/about_Booleans.md)
Microsoft.PowerShell.Core About (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/About.md
---
-description: About topics cover a ranges of concepts about PowerShell.
-Download Help Link: https://Please-enter-FwLink-manually
+description: About topics cover a ranges of concepts about PowerShell.
Help Version: 6.0
-keywords: powershell,cmdlet
Locale: en-US
-Module Guid: 00000000-0000-0000-0000-000000000000
-Module Name: About
Last updated 02/25/2019
-schema: 2.0.0
Title: About topics --- # About topics
Describes how to run remote commands in PowerShell.
### [about_Remote_Disconnected_Sessions](about_Remote_Disconnected_Sessions.md) Explains how to disconnect from and reconnect to a PSSession.
-### [about_Remote_FAQ](about_Remote_FAQ.md)
-Contains questions and answers about running remote commands in PowerShell.
- ### [about_Remote_Jobs](about_Remote_Jobs.md) Describes how to run background jobs on remote computers.
Microsoft.PowerShell.Core About Arrays (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Arrays.md
to accept them.
### Where Allows to filter or select the elements of the array. The script must evaluate
-to anything different than: zero (0), empty string, `$false` or `$null` for
-the element to show after the `Where`
+to anything different than: zero (0), empty string, `$false` or `$null` for the
+element to show after the `Where`. For more information about boolean
+evaluation, see [about_Booleans](about_Booleans.md).
There is one definition for the `Where` method.
Microsoft.PowerShell.Core About Booleans (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Booleans.md
+---
+description: Describes how boolean expressions are evaluated.
+Locale: en-US
Last updated : 06/10/2021
+no-loc:
+schema: 2.0.0
+ Title: about Booleans
+---
+# about_Booleans
+
+PowerShell can implicitly treat any type as a **Boolean**. It is important to
+understand the rules that PowerShell uses to convert other types to **Boolean**
+values.
+
+## Converting from scalar types
+
+A scalar type is an atomic quantity that can hold only one value at a time. The
+following types evaluate to `$false`:
+
+- Empty strings like `''` or `""`
+- Null values like `$null`
+- Any numeric type with the value of `0`
+
+Examples:
+
+```powershell
+PS> $false -eq ''
+True
+PS> if ("") { $true } else { $false }
+False
+PS> if ($null) { $true } else { $false }
+False
+PS> if ([int]0) { $true } else { $false }
+False
+PS> if ([double]0.0) { $true } else { $false }
+False
+```
+
+The following types evaluate to `$true`:
+
+- Non-empty strings
+- Instances of any other non-collection type
+
+Examples:
+
+```powershell
+# a non-collection type
+PS> [bool]@{value = 0}
+True
+# non-empty strings
+PS> if ('hello') { $true } else { $false }
+True
+PS> [bool]'False'
+True
+```
+
+Note that this differs from _explicit string parsing_:
+
+```powershell
+PS> [bool]::Parse('false')
+False
+PS> [bool]::Parse('True')
+True
+PS> [bool]::Parse('Not True')
+MethodInvocationException: Exception calling "Parse" with "1" argument(s):
+"String 'Not True' was not recognized as a valid Boolean."
+```
+
+## Converting from collection types
+
+Arrays are the most common collection type in PowerShell. These rules apply to
+any collection-like types that implement the
+[IList](/dotnet/api/system.collections.ilist) interface.
+
+- Empty collections are always `$false`
+- The special null value indicating the absence of output from a command,
+ `[System.Management.Automation.Internal.AutomationNull]::Value` is always
+ `$false`.
+- Single-element collections evaluate to the **Boolean** value of their one and
+ only element.
+- Collections with more than 1 element are always `$true`.
+
+Examples:
+
+```powershell
+# Empty collections
+PS> [bool]@()
+False
+PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt')
+False
+# Single-element collections
+PS> $a = @(0)
+PS> [bool]$a
+False
+PS> $b = @(1)
+PS> [bool]$b
+True
+# Multi-element collections
+PS> $c = @(0,0)
+PS> [bool]$c
+True
+```
+
+## See also
+
+- [about_Arrays](about_Arrays.md#where)
Microsoft.PowerShell.Core About Comparison Operators (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Comparison_Operators.md
--- description: Describes the operators that compare values in PowerShell. Locale: en-US Previously updated : 03/15/2021 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Comparison Operators
$a -isnot $b.GetType() # Output: True
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) - [Foreach-Object](xref:Microsoft.PowerShell.Core.ForEach-Object) - [Where-Object](xref:Microsoft.PowerShell.Core.Where-Object)
+- [about_Booleans](about_Booleans.md)
[1]: /dotnet/api/system.icomparable [2]: /dotnet/api/system.iequatable-1
Microsoft.PowerShell.Core About Do (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Do.md
---
-description: Runs a statement list one or more times, subject to a While or Until condition.
-keywords: powershell,cmdlet
+description: Runs a statement list one or more times, subject to a While or Until condition.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_do?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Do
Title: about Do
# about_Do ## SHORT DESCRIPTION
-Runs a statement list one or more times, subject to a While or Until
+Runs a statement list one or more times, subject to a `While` or `Until`
condition. ## LONG DESCRIPTION
-The Do keyword works with the While keyword or the Until keyword to run the
-statements in a script block, subject to a condition. Unlike the related
-While loop, the script block in a Do loop always runs at least once.
+The `Do` keyword works with the `While` keyword or the `Until` keyword to run
+the statements in a script block, subject to a condition. Unlike the related
+`While` loop, the script block in a `Do` loop always runs at least once.
-A **Do-While** loop is a variety of the While loop. In a **Do-While** loop,
-the condition is evaluated after the script block has run. As in a While
-loop, the script block is repeated as long as the condition evaluates to
-true.
+A **Do-While** loop is a variety of the `While` loop. In a **Do-While** loop,
+the condition is evaluated after the script block has run. As in a While loop,
+the script block is repeated as long as the condition evaluates to true.
Like a **Do-While** loop, a **Do-Until** loop always runs at least once before the condition is evaluated. However, the script block runs only while the condition is false.
-The *Continue* and *Break* flow control keywords can be used in a
-**Do-While** loop or in a **Do-Until** loop.
+The `Continue` and `Break` flow control keywords can be used in a **Do-While**
+loop or in a **Do-Until** loop.
### Syntax
The following shows the syntax of the **Do-Until** statement:
do {<statement list>} until (<condition>) ```
-The statement list contains one or more statements that run each time the
-loop is entered or repeated.
+The statement list contains one or more statements that run each time the loop
+is entered or repeated.
-The condition portion of the statement resolves to true or false.
+The condition portion of the statement resolves to true or false. For more
+information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
### Example
-The following example of a Do statement counts the items in an array until
-it reaches an item with a value of 0.
+The following example of a `Do` statement counts the items in an array until it
+reaches an item with a value of 0.
```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } while ($x[$a] -ne 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } while ($x[$a] -ne 0)
+PS> $count
3 ```
-The following example uses the Until keyword. Notice that the not equal to
+The following example uses the `Until` keyword. Notice that the not equal to
operator (`-ne`) is replaced by the equal to operator (`-eq`). ```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } until ($x[$a] -eq 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } until ($x[$a] -eq 0)
+PS> $count
3 ```
while (++$a -lt 10)
## SEE ALSO
-[about_While](about_While.md)
-
-[about_Operators](about_Operators.md)
-
-[about_Assignment_Operators](about_Assignment_Operators.md)
-
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Break](about_Break.md)
-
-[about_Continue](about_Continue.md)
-
+- [about_While](about_While.md)
+- [about_Operators](about_Operators.md)
+- [about_Assignment_Operators](about_Assignment_Operators.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Break](about_Break.md)
+- [about_Continue](about_Continue.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About If (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_If.md
---
-description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
-keywords: powershell,cmdlet
+description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about If
Title: about If
# about_If ## SHORT DESCRIPTION
-Describes a language command you can use to run statement lists based on
-the results of one or more conditional tests.
+Describes a language command you can use to run statement lists based on the
+results of one or more conditional tests.
## LONG DESCRIPTION You can use the `If` statement to run code blocks if a specified conditional
-test evaluates to true. You can also specify one or more additional
-conditional tests to run if all the prior tests evaluate to false. Finally,
-you can specify an additional code block that is run if no other prior
-conditional test evaluates to true.
+test evaluates to true. You can also specify one or more additional conditional
+tests to run if all the prior tests evaluate to false. Finally, you can specify
+an additional code block that is run if no other prior conditional test
+evaluates to true.
### Syntax
if (<test1>)
{<statement list 3>}] ```
-When you run an `If` statement, PowerShell evaluates the `<test1>`
-conditional expression as true or false. If `<test1>` is true,
-`<statement list 1>` runs, and PowerShell exits the `If` statement. If
-`<test1>` is false, PowerShell evaluates the condition specified by the
-`<test2>` conditional statement.
+When you run an `If` statement, PowerShell evaluates the `<test1>` conditional
+expression as true or false. If `<test1>` is true, `<statement list 1>` runs,
+and PowerShell exits the `If` statement. If `<test1>` is false, PowerShell
+evaluates the condition specified by the `<test2>` conditional statement.
-If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the
-`If` statement. If both `<test1>` and `<test2>` evaluate to false, the
-`<statement list 3`> code block runs, and PowerShell exits the If
-statement.
+For more information about boolean evaluation, see
+[about_Booleans](about_Booleans.md).
-You can use multiple Elseif statements to chain a series of conditional
-tests. So, that each test is run only if all the previous tests are false.
-If you need to create an `If` statement that contains many Elseif statements,
+If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the `If`
+statement. If both `<test1>` and `<test2>` evaluate to false, the
+`<statement list 3`> code block runs, and PowerShell exits the If statement.
+
+You can use multiple `Elseif` statements to chain a series of conditional
+tests. So, that each test is run only if all the previous tests are false. If
+you need to create an `If` statement that contains many `Elseif` statements,
consider using a Switch statement instead. Examples:
if ($a -gt 2) {
} ```
-In this example, if the $a variable is greater than 2, the condition
-evaluates to true, and the statement list runs. However, if $a is less than
-or equal to 2 or is not an existing variable, the `If` statement does not
-display a message.
+In this example, if the $a variable is greater than 2, the condition evaluates
+to true, and the statement list runs. However, if $a is less than or equal to 2
+or is not an existing variable, the `If` statement does not display a message.
By adding an Else statement, a message is displayed when $a is less than or equal to 2. As the next example shows:
else {
} ```
-To further refine this example, you can use the Elseif statement to display
-a message when the value of $a is equal to 2. As the next example shows:
+To further refine this example, you can use the Elseif statement to display a
+message when the value of $a is equal to 2. As the next example shows:
```powershell if ($a -gt 2) {
else {
### Using the ternary operator syntax
-PowerShell 7.0 introduced a new syntax using the ternary operator. It follows the C# ternary
-operator syntax:
+PowerShell 7.0 introduced a new syntax using the ternary operator. It follows
+the C# ternary operator syntax:
```Syntax <condition> ? <if-true> : <if-false> ```
-The ternary operator behaves like the simplified `if-else` statement. The `<condition>` expression
-is evaluated and the result is converted to a boolean to determine which branch should be evaluated
-next:
+The ternary operator behaves like the simplified `if-else` statement. The
+`<condition>` expression is evaluated and the result is converted to a boolean
+to determine which branch should be evaluated next:
-- The `<if-true>` expression is executed if the `<condition>` expression is true-- The `<if-false>` expression is executed if the `<condition>` expression is false
+- The `<if-true>` expression is executed if the `<condition>` expression is
+ true
+- The `<if-false>` expression is executed if the `<condition>` expression is
+ false
For example:
For example:
$message = (Test-Path $path) ? "Path exists" : "Path not found" ```
-In this example, the value of `$message` is "Path exists" when `Test-Path` returns `$true`. When
-`Test-Path` returns `$false`, the value of `$message` is "Path not found".
+In this example, the value of `$message` is "Path exists" when `Test-Path`
+returns `$true`. When `Test-Path` returns `$false`, the value of `$message` is
+"Path not found".
```powershell $service = Get-Service BITS $service.Status -eq 'Running' ? (Stop-Service $service) : (Start-Service $service) ```
-In this example, if the service is running, it is stopped, and if its status is not **Running**,
-it is started.
+In this example, if the service is running, it is stopped, and if its status is
+not **Running**, it is started.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Switch](about_Switch.md)
-
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Switch](about_Switch.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About Remote (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Remote.md
--- description: Describes how to run remote commands in PowerShell.
-keywords: powershell,cmdlet
Locale: en-US Last updated 01/03/2018 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote?view=powershell-7.1&WT.mc_id=ps-gethelp
remote computer where it terminates the remote command.
- For information about how remoting works, how to manage remote data, special configurations, security issues, and other frequently asked questions, see
- [about_Remote_FAQ](about_Remote_FAQ.md).
+ [PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml).
-- For help in resolving remoting errors, see [about_Remote_Troubleshooting](about_Remote_Troubleshooting.md).
+- For help in resolving remoting errors, see about_Remote_Troubleshooting.
- For information about PSSessions and persistent connections, see [about_PSSessions](about_PSSessions.md).
about_Remoting
[about_Remote_Requirements](about_Remote_Requirements.md)
-[about_Remote_FAQ](about_Remote_FAQ.md)
+[PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml)
[about_Remote_TroubleShooting](about_Remote_TroubleShooting.md)
about_Remoting
[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command) [New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)-
Microsoft.PowerShell.Core About Remote FAQ (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Remote_FAQ.md
-description: Contains questions and answers about running remote commands in PowerShell.
-keywords: powershell,cmdlet
-Locale: en-US
Previously updated : 07/23/2020
-online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote_faq?view=powershell-7.1&WT.mc_id=ps-gethelp
-schema: 2.0.0
Title: about Remote FAQ
-# about_Remote_FAQ
-
-## Short description
-Contains questions and answers about running remote commands in PowerShell.
-
-## Long description
-
-When you work remotely, you type commands in PowerShell on one computer (known
-as the "local computer"), but the commands run on another computer (known as
-the "remote computer"). The experience of working remotely should be as much
-like working directly at the remote computer as possible.
-
-Note: To use PowerShell remoting, the remote computer must be configured for
-remoting. For more information, see
-[about_Remote_Requirements](about_Remote_Requirements.md).
-
-### Must both computers have PowerShell installed?
-
-Yes. To work remotely, the local and remote computers must have PowerShell, the
-Microsoft .NET Framework, and the Web Services for Management (WS-Management)
-protocol. Any files and other resources that are needed to execute a particular
-command must be on the remote computer.
-
-Computers running Windows PowerShell 3.0 and computers running Windows
-PowerShell 2.0 can connect to each other remotely and run remote commands.
-However, some features, such as the ability to disconnect from a session and
-reconnect to it, work only when both computers are running Windows PowerShell
-3.0.
-
-You must have permission to connect to the remote computer, permission to run
-PowerShell, and permission to access data stores (such as files and folders),
-and the registry on the remote computer.
-
-For more information, see [about_Remote_Requirements](about_Remote_Requirements.md).
-
-### How does remoting work?
-
-When you submit a remote command, the command is transmitted across the network
-to the PowerShell engine on the remote computer, and it runs in the PowerShell
-client on the remote computer. The command results are sent back to the local
-computer and appear in the PowerShell session on the local computer.
-
-To transmit the commands and receive the output, PowerShell uses the
-WS-Management protocol. For information about the WS-Management protocol, see
-[WS-Management Protocol](/windows/win32/winrm/ws-management-protocol) in the
-Windows documentation.
-
-Beginning in Windows PowerShell 3.0, remote sessions are stored on the remote
-computer. This enables you to disconnect from the session and reconnect from a
-different session or a different computer without interrupting the commands or
-losing state.
-
-### Is PowerShell remoting secure?
-
-When you connect to a remote computer, the system uses the username and
-password credentials on the local computer or the credentials that you supply
-in the command to log you in to the remote computer. The credentials and the
-rest of the transmission are encrypted.
-
-To add additional protection, you can configure the remote computer to use
-Secure Sockets Layer (SSL) instead of HTTP to listen for Windows Remote
-Management (WinRM) requests. Then, users can use the **UseSSL** parameter of
-the `Invoke-Command`, `New-PSSession`, and `Enter-PSSession` cmdlets when
-establishing a connection. This option uses the more secure HTTPS channel
-instead of HTTP.
-
-### Do all remote commands require PowerShell remoting?
-
-No. Several cmdlets have a **ComputerName** parameter that lets you get objects
-from the remote computer.
-
-These cmdlets do not use PowerShell remoting. So, you can use them on any
-computer that is running PowerShell, even if the computer is not configured for
-PowerShell remoting or if the computer does not meet the requirements for
-PowerShell remoting.
-
-These cmdlets include the following:
--- `Get-Process`-- `Get-Service`-- `Get-WinEvent`-- `Get-EventLog`-- `Test-Connection`-
-To find all the cmdlets with a **ComputerName** parameter, type:
-
-```powershell
-Get-Help * -Parameter ComputerName
-# or
-Get-Command -ParameterName ComputerName
-```
-
-To determine whether the **ComputerName** parameter of a particular cmdlet
-requires PowerShell remoting, see the parameter description. To display the
-parameter description, type:
-
-```powershell
-Get-Help <cmdlet-name> -Parameter ComputerName
-```
-
-For example:
-
-```powershell
-Get-Help Get-Process -Parameter ComputerName
-```
-
-For all other commands, use the `Invoke-Command` cmdlet.
-
-### How do I run a command on a remote computer?
-
-To run a command on a remote computer, use the `Invoke-Command` cmdlet.
-
-Enclose your command in braces (`{}`) to make it a script block. Use the
-**ScriptBlock** parameter of `Invoke-Command` to specify the command.
-
-You can use the **ComputerName** parameter of `Invoke-Command` to specify a
-remote computer. Or, you can create a persistent connection to a remote
-computer (a session) and then use the **Session** parameter of `Invoke-Command`
-to run the command in the session.
-
-For example, the following commands run a `Get-Process` command remotely.
-
-```powershell
-Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Process}
-
-# - OR -
-
-Invoke-Command -Session $s -ScriptBlock {Get-Process}
-```
-
-To interrupt a remote command, type <kbd>CTRL</kbd>+<kbd>C</kbd>. The
-interruption request is passed to the remote computer, where it terminates the
-remote command.
-
-For more information about remote commands, see about_Remote and the Help
-topics for the cmdlets that support remoting.
-
-### Can I just telnet into a remote computer?
-
-You can use the `Enter-PSSession` cmdlet to start an interactive session with a
-remote computer.
-
-At the PowerShell prompt, type:
-
-```powershell
-Enter-PSSession <ComputerName>
-```
-
-The command prompt changes to show that you are connected to the remote
-computer.
-
-```
-<ComputerName>\C:>
-```
-
-Now, the commands that you type run on the remote computer just as though you
-typed them directly on the remote computer.
-
-To end the interactive session, type:
-
-```powershell
-Exit-PSSession
-```
-
-An interactive session is a persistent session that uses the WS-Management
-protocol. It is not the same as using Telnet, but it provides a similar
-experience.
-
-For more information, see `Enter-PSSession`.
-
-### Can I create a persistent connection?
-
-Yes. You can run remote commands by specifying the name of the remote computer,
-its NetBIOS name, or its IP address. Or, you can run remote commands by
-specifying a PowerShell session (PSSession) that is connected to the remote
-computer.
-
-When you use the **ComputerName** parameter of `Invoke-Command` or
-`Enter-PSSession`, PowerShell establishes a temporary connection. PowerShell
-uses the connection to run only the current command, and then it closes the
-connection. This is a very efficient method for running a single command or
-several unrelated commands, even on many remote computers.
-
-When you use the `New-PSSession` cmdlet to create a PSSession, PowerShell
-establishes a persistent connection for the PSSession. Then, you can run
-multiple commands in the PSSession, including commands that share data.
-
-Typically, you create a PSSession to run a series of related commands that
-share data. Otherwise, the temporary connection created by the **ComputerName**
-parameter is sufficient for most commands.
-
-For more information about sessions, see about_PSSessions.
-
-### Can I run commands on more than one computer at a time?
-
-Yes. The **ComputerName** parameter of the `Invoke-Command` cmdlet accepts
-multiple computer names, and the **Session** parameter accepts multiple
-PSSessions.
-
-When you run an `Invoke-Command` command, PowerShell runs the commands on all
-of the specified computers or in all of the specified PSSessions.
-
-PowerShell can manage hundreds of concurrent remote connections. However, the
-number of remote commands that you can send might be limited by the resources
-of your computer and its capacity to establish and maintain multiple network
-connections.
-
-For more information, see the example in the `Invoke-Command` Help topic.
-
-### Where are my profiles?
-
-PowerShell profiles are not run automatically in remote sessions, so the
-commands that the profile adds are not present in the session. In addition, the
-`$profile` automatic variable is not populated in remote sessions.
-
-To run a profile in a session, use the `Invoke-Command` cmdlet.
-
-For example, the following command runs the CurrentUserCurrentHost profile
-from the local computer in the session in `$s`.
-
-```
-Invoke-Command -Session $s -FilePath $profile
-```
-
-The following command runs the CurrentUserCurrentHost profile from the remote
-computer in the session in `$s`. Because the `$profile` variable is not populated,
-the command uses the explicit path to the profile.
-
-```powershell
-Invoke-Command -Session $s {
- . "$home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
-}
-```
-
-After running this command, the commands that the profile adds to the session
-are available in `$s`.
-
-You can also use a startup script in a session configuration to run a profile
-in every remote session that uses the session configuration.
-
-For more information about PowerShell profiles, see about_Profiles.
-For more information about session configurations, see
-`Register-PSSessionConfiguration`.
-
-### How does throttling work on remote commands?
-
-To help you manage the resources on your local computer, PowerShell
-includes a per-command throttling feature that lets you limit the number of
-concurrent remote connections that are established for each command.
-
-The default is 32 concurrent connections, but you can use the **ThrottleLimit**
-parameter of the cmdlets to set a custom throttle limit for particular
-commands.
-
-When you use the throttling feature, remember that it is applied to each
-command, not to the entire session or to the computer. If you are running
-commands concurrently in several sessions or PSSessions, the number of
-concurrent connections is the sum of the concurrent connections in all the
-sessions.
-
-To find cmdlets with a **ThrottleLimit** parameter, type:
-
-```
-Get-Help * -Parameter ThrottleLimit
--or-
-Get-Command -ParameterName ThrottleLimit
-```
-
-### Is the output of remote commands different from local output?
-
-When you use PowerShell locally, you send and receive "live" .NET
-Framework objects; "live" objects are objects that are associated with actual
-programs or system components. When you invoke the methods or change the
-properties of live objects, the changes affect the actual program or
-component. And, when the properties of a program or component change, the
-properties of the object that represent them also change.
-
-However, because most live objects cannot be transmitted over the network,
-PowerShell "serializes" most of the objects sent in remote commands,
-that is, it converts each object into a series of XML (Constraint Language in
-XML [CLiXML]) data elements for transmission.
-
-When PowerShell receives a serialized object, it converts the XML into
-a deserialized object type. The deserialized object is an accurate record of
-the properties of the program or component at a previous time, but it is no
-longer "live", that is, it is no longer directly associated with the
-component. And, the methods are removed because they are no longer effective.
-
-Typically, you can use deserialized objects just as you would use live
-objects, but you must be aware of their limitations. Also, the objects that
-are returned by the `Invoke-Command` cmdlet have additional properties that help
-you to determine the origin of the command.
-
-Some object types, such as DirectoryInfo objects and GUIDs, are converted back
-into live objects when they are received. These objects do not need any
-special handling or formatting.
-
-For information about interpreting and formatting remote output, see
-[about_Remote_Output](about_Remote_Output.md).
-
-### Can I run background jobs remotely?
-
-Yes. A PowerShell background job is a PowerShell command that
-runs asynchronously without interacting with the session. When you start a
-background job, the command prompt returns immediately, and you can continue
-to work in the session while the job runs even if it runs for an extended
-period of time.
-
-You can start a background job even while other commands are running because
-background jobs always run asynchronously in a temporary session.
-
-You can run background jobs on a local or remote computer. By default, a
-background job runs on the local computer. However, you can use the **AsJob**
-parameter of the `Invoke-Command` cmdlet to run any remote command as a
-background job. And, you can use `Invoke-Command` to run a `Start-Job` command
-remotely.
-
-For more information about background jobs in PowerShell , see
-[about_Jobs(about_Jobs.md)] and [about_Remote_Jobs(about_Remote_Jobs.md)].
-
-### Can I run windows programs on a remote computer?
-
-You can use PowerShell remote commands to run Windows-based programs on remote
-computers. For example, you can run `Shutdown.exe` or `Ipconfig.exe` on a
-remote computer.
-
-However, you cannot use PowerShell commands to open the user interface
-for any program on a remote computer.
-
-When you start a Windows program on a remote computer, the command is not
-completed, and the PowerShell command prompt does not return, until the program
-is finished or until you press <kbd>CTRL</kbd>+<kbd>C</kbd> to interrupt the
-command. For example, if you run the `Ipconfig.exe` program on a remote
-computer, the command prompt does not return until `Ipconfig.exe` is completed.
-
-If you use remote commands to start a program that has a user interface, the
-program process starts, but the user interface does not appear. The PowerShell
-command is not completed, and the command prompt does not return until you stop
-the program process or until you press <kbd>CTRL</kbd>+<kbd>C</kbd>, which
-interrupts the command and stops the process.
-
-For example, if you use a PowerShell command to run `Notepad` on a
-remote computer, the Notepad process starts on the remote computer, but the
-Notepad user interface does not appear. To interrupt the command and restore
-the command prompt, press <kbd>CTRL</kbd>+<kbd>C</kbd>.
-
-### Can I limit the commands that users can run remotely on my computer?
-
-Yes. Every remote session must use one of the session configurations on the
-remote computer. You can manage the session configurations on your computer
-(and the permissions to those session configurations) to determine who can run
-commands remotely on your computer and which commands they can run.
-
-A session configuration configures the environment for the session. You can
-define the configuration by using an assembly that implements a new
-configuration class or by using a script that runs in the session. The
-configuration can determine the commands that are available in the session.
-And, the configuration can include settings that protect the computer, such as
-settings that limit the amount of data that the session can receive remotely
-in a single object or command. You can also specify a security descriptor that
-determines the permissions that are required to use the configuration.
-
-The `Enable-PSRemoting` cmdlet creates the default session configurations on
-your computer: Microsoft.PowerShell, Microsoft.PowerShell.Workflow, and
-Microsoft.PowerShell32 (64-bit operating systems only). `Enable-PSRemoting` sets
-the security descriptor for the configuration to allow only members of the
-Administrators group on your computer to use them.
-
-You can use the session configuration cmdlets to edit the default session
-configurations, to create new session configurations, and to change the
-security descriptors of all the session configurations.
-
-Beginning in Windows PowerShell 3.0, the `New-PSSessionConfigurationFile` cmdlet
-lets you create custom session configurations by using a text file. The file
-includes options for setting the language mode and for specifying the cmdlets
-and modules that are available in sessions that use the session configuration.
-
-When users use the `Invoke-Command`, `New-PSSession`, or `Enter-PSSession`
-cmdlets, they can use the **ConfigurationName** parameter to indicate the
-session configuration that is used for the session. And, they can change the
-default configuration that their sessions use by changing the value of the
-`$PSSessionConfigurationName` preference variable in the session.
-
-For more information about session configurations, see the Help for the
-session configuration cmdlets. To find the session configuration cmdlets,
-type:
-
-```powershell
-Get-Command *PSSessionConfiguration
-```
-
-### What are fan in and fan out configurations?
-
-The most common PowerShell remoting scenario involving multiple
-computers is the one-to-many configuration, in which one local computer (the
-administrator's computer) runs PowerShell commands on numerous remote
-computers. This is known as the "fan-out" scenario.
-
-However, in some enterprises, the configuration is many-to-one, where many
-client computers connect to a single remote computer that is running
-PowerShell, such as a file server or a kiosk. This is known as the "fan-in"
-configuration.
-
-PowerShell remoting supports both fan-out and fan-in configurations.
-
-For the fan-out configuration, PowerShell uses the Web Services for
-Management (WS-Management) protocol and the WinRM service that supports the
-Microsoft implementation of WS-Management. When a local computer connects to a
-remote computer, WS-Management establishes a connection and uses a plug-in for
-PowerShell to start the PowerShell host process
-(Wsmprovhost.exe) on the remote computer. The user can specify an alternate
-port, an alternate session configuration, and other features to customize the
-remote connection.
-
-To support the "fan-in" configuration, PowerShell uses internet Information
-Services (IIS) to host WS-Management, to load the PowerShell plug-in, and to
-start PowerShell. In this scenario, instead of starting each PowerShell session
-in a separate process, all PowerShell sessions run in the same host process.
-
-IIS hosting and fan-in remote management is not supported in Windows XP or in
-Windows Server 2003.
-
-In a fan-in configuration, the user can specify a connection URI and an HTTP
-endpoint, including the transport, computer name, port, and application name.
-IIS forwards all the requests with a specified application name to the
-application. The default is WS-Management, which can host PowerShell.
-
-You can also specify an authentication mechanism and prohibit or allow
-redirection from HTTP and HTTPS endpoints.
-
-### Can I test remoting on a single computer not in a domain?
-
-Yes. PowerShell remoting is available even when the local computer is
-not in a domain. You can use the remoting features to connect to sessions and
-to create sessions on the same computer. The features work the same as they do
-when you connect to a remote computer.
-
-To run remote commands on a computer in a workgroup, change the following
-Windows settings on the computer.
-
-Caution: These settings affect all users on the system and they can make the
-system more vulnerable to a malicious attack. Use caution when making these
-changes.
--- Windows Vista, Windows 7, Windows 8:-
- Create the following registry entry, and then set its value to 1:
- LocalAccountTokenFilterPolicy in
- ` HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System`
-
- You can use the following PowerShell command to add this entry:
-
- ```powershell
- $parameters = @{
- Path='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
- Name='LocalAccountTokenFilterPolicy'
- propertyType='DWord'
- Value=1
- }
- New-ItemProperty @parameters
- ```
--- Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows
- Server 2012 R2:
-
- No changes are needed because the default setting of the "Network Access:
- Sharing and security model for local accounts" policy is "Classic". Verify
- the setting in case it has changed.
-
-### Can I run remote commands on a computer in another domain?
-
-Yes. Typically, the commands run without error, although you might need to use
-the **Credential** parameter of the `Invoke-Command`, `New-PSSession`, or
-`Enter-PSSession` cmdlets to provide the credentials of a member of the
-Administrators group on the remote computer. This is sometimes required even
-when the current user is a member of the Administrators group on the local and
-remote computers.
-
-However, if the remote computer is not in a domain that the local computer
-trusts, the remote computer might not be able to authenticate the user's
-credentials.
-
-To enable authentication, use the following command to add the remote computer
-to the list of trusted hosts for the local computer in WinRM. Type the command
-at the PowerShell prompt.
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value <Remote-computer-name>
-```
-
-For example, to add the Server01 computer to the list of trusted hosts on the
-local computer, type the following command at the PowerShell prompt:
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value Server01
-```
-
-### Does PowerShell support remoting over SSH?
-
-Yes. For more information, see
-[PowerShell remoting over SSH](/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core).
-
-## See also
-
-[about_Remote](about_Remote.md)
-
-[about_Profiles](about_Profiles.md)
-
-[about_PSSessions](about_PSSessions.md)
-
-[about_Remote_Jobs](about_Remote_Jobs.md)
-
-[about_Remote_Variables](about_Remote_Variables.md)
-
-[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command)
-
-[New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)
Microsoft.PowerShell.Core About Switch (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Switch.md
---
-description: Explains how to use a switch to handle multiple `If` statements.
-keywords: powershell,cmdlet
+description: Explains how to use a switch to handle multiple `If` statements.
Locale: en-US Previously updated : 05/22/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Switch
switch -Regex ($target)
https://bing.com is a web address that uses https ```
-A Switch statement condition may be either:
+A `Switch` statement condition may be either:
- An expression whose value is compared to the input value - A script block which should return `$true` if a condition is met.
-The `$_` automatic variable contains the value passed to the switch statement
+The `$_` automatic variable contains the value passed to the `switch` statement
and is available for evaluation and use within the scope of the condition statements.
Microsoft.PowerShell.Core About While (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_While.md
---
-description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
-keywords: powershell,cmdlet
+description: Describes a language statement that you can use to run a command block based on the results of a conditional test.
Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_while?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about While
Title: about While
# about_While ## SHORT DESCRIPTION
-Describes a language statement that you can use to run a command block
-based on the results of a conditional test.
+Describes a language statement that you can use to run a command block based on
+the results of a conditional test.
## LONG DESCRIPTION
-The While statement (also known as a While loop) is a language construct
+The `While` statement (also known as a `While` loop) is a language construct
for creating a loop that runs commands in a command block as long as a
-conditional test evaluates to true. The While statement is easier to
+conditional test evaluates to true. The `While` statement is easier to
construct than a For statement because its syntax is less complicated. In
-addition, it is more flexible than the Foreach statement because you
-specify a conditional test in the While statement to control how many times
-the loop runs.
+addition, it is more flexible than the Foreach statement because you specify a
+conditional test in the `While` statement to control how many times the loop
+runs.
The following shows the While statement syntax:
The following shows the While statement syntax:
while (<condition>){<statement list>} ```
-When you run a While statement, PowerShell evaluates the `<condition>`
-section of the statement before entering the `<statement list>` section. The
-condition portion of the statement resolves to either true or false. As
-long as the condition remains true, PowerShell reruns the `<statement list>`
-section.
+When you run a While statement, PowerShell evaluates the `<condition>` section
+of the statement before entering the `<statement list>` section. The condition
+portion of the statement resolves to either true or false. As long as the
+condition remains true, PowerShell reruns the `<statement list>` section. For
+more information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
-The `<statement list>` section of the statement contains one or more
-commands that are run each time the loop is entered or repeated.
+The `<statement list>` section of the statement contains one or more commands
+that are run each time the loop is entered or repeated.
-For example, the following While statement displays the numbers 1 through 3
-if the $val variable has not been created or if the $val variable has been
+For example, the following While statement displays the numbers 1 through 3 if
+the `$val` variable has not been created or if the `$val` variable has been
created and initialized to 0. ```powershell
while($val -ne 3)
} ```
-In this example, the condition ($val is not equal to 3) is true while $val
-\= 0, 1, 2. Each time through the loop, $val is incremented by 1 using the
-\+\+ unary increment operator ($val\+\+). The last time through the loop,
-$val \= 3. When $val equals 3, the condition statement evaluates to false,
-and the loop exits.
+In this example, the condition (`$val` is not equal to 3) is true while `$val`
+is equal to 0, 1, and 2. Each time through the loop, `$val` is incremented by 1
+using the `++` unary increment operator. The last time through the loop `$val`
+is set to 3, the condition statement evaluates to false, and the loop exits.
To conveniently write this command at the PowerShell command prompt, you can enter it in the following way:
can enter it in the following way:
while($val -ne 3){$val++; Write-Host $val} ```
-Notice that the semicolon separates the first command that adds 1 to $val
-from the second command that writes the value of $val to the console.
+Notice that the semicolon separates the first command that adds 1 to `$val` from
+the second command that writes the value of `$val` to the console.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Do](about_Do.md)
-
-[about_Foreach](about_Foreach.md)
-
-[about_For](about_For.md)
-
-[about_Language_Keywords](about_Language_Keywords.md)
-
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Do](about_Do.md)
+- [about_Foreach](about_Foreach.md)
+- [about_For](about_For.md)
+- [about_Language_Keywords](about_Language_Keywords.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core Where Object (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/Where-Object.md
--- external help file: System.Management.Automation.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Core Previously updated : 03/19/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Where-Object
The previous example is functionally equivalent to:
- `('hi', '', 'there') | Where-Object Length -GT 0` - `('hi', '', 'there') | Where-Object {$_.Length -gt 0}`
+For more information about how booleans are evaluated, see [about_Booleans](about/about_Booleans.md).
+ ## EXAMPLES ### Example 1: Get stopped services
for the command.
```powershell # Use Where-Object to get commands that have any value for the OutputType property of the command.
-# This omits commands that do not have an OutputType property and those that have an OutputType property, but no property value.
+# This omits commands that do not have an OutputType property and those that have an OutputType
+# property, but no property value.
Get-Command | where OutputType Get-Command | where {$_.OutputType} ``` ```powershell # Use Where-Object to get objects that are containers.
-# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all others.
+# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all
+# others.
Get-ChildItem | where PSIsContainer Get-ChildItem | where {$_.PSIsContainer} ``` ```powershell # Finally, use the Not operator (!) to get objects that are not containers.
-# This gets objects that do have the **PSIsContainer** property and those that have a value of $False for the **PSIsContainer** property.
+# This gets objects that do have the **PSIsContainer** property and those that have a value of
+# $False for the **PSIsContainer** property.
Get-ChildItem | where {!$_.PSIsContainer} # You cannot use the Not operator (!) in the comparison statement format of the command. Get-ChildItem | where PSIsContainer -eq $False
The example uses the script block command format. Logical operators, such as **A
valid only in script blocks. You cannot use them in the comparison statement format of a `Where-Object` command. -- For more information about PowerShell logical operators, see [about_Logical_Operators](./About/about_logical_operators.md).-- For more information about the Updatable Help feature, see [about_Updatable_Help](./About/about_Updatable_Help.md).
+- For more information about PowerShell logical operators, see
+ [about_Logical_Operators](./About/about_logical_operators.md).
+- For more information about the Updatable Help feature, see
+ [about_Updatable_Help](./About/about_Updatable_Help.md).
## PARAMETERS
This cmdlet returns selected items from the input object set.
## NOTES
-Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with collections.
+Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with
+collections.
You can read more about these new methods here [about_arrays](./About/about_Arrays.md)
You can read more about these new methods here [about_arrays](./About/about_Arra
[Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)
+[about_Booleans](about/about_Booleans.md)
Microsoft.PowerShell.Core About (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/About.md
Describes how to run remote commands in PowerShell.
### [about_Remote_Disconnected_Sessions](about_Remote_Disconnected_Sessions.md) Explains how to disconnect from and reconnect to a PSSession.
-### [about_Remote_FAQ](about_Remote_FAQ.md)
-Contains questions and answers about running remote commands in PowerShell.
- ### [about_Remote_Jobs](about_Remote_Jobs.md) Describes how to run background jobs on remote computers.
Microsoft.PowerShell.Core About Arrays (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Arrays.md
to accept them.
### Where Allows to filter or select the elements of the array. The script must evaluate
-to anything different than: zero (0), empty string, `$false` or `$null` for
-the element to show after the `Where`
+to anything different than: zero (0), empty string, `$false` or `$null` for the
+element to show after the `Where`. For more information about boolean
+evaluation, see [about_Booleans](about_Booleans.md).
There is one definition for the `Where` method.
Microsoft.PowerShell.Core About Booleans (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Booleans.md
+---
+description: Describes how boolean expressions are evaluated.
+Locale: en-US
Last updated : 06/10/2021
+no-loc:
+schema: 2.0.0
+ Title: about Booleans
+---
+# about_Booleans
+
+PowerShell can implicitly treat any type as a **Boolean**. It is important to
+understand the rules that PowerShell uses to convert other types to **Boolean**
+values.
+
+## Converting from scalar types
+
+A scalar type is an atomic quantity that can hold only one value at a time. The
+following types evaluate to `$false`:
+
+- Empty strings like `''` or `""`
+- Null values like `$null`
+- Any numeric type with the value of `0`
+
+Examples:
+
+```powershell
+PS> $false -eq ''
+True
+PS> if ("") { $true } else { $false }
+False
+PS> if ($null) { $true } else { $false }
+False
+PS> if ([int]0) { $true } else { $false }
+False
+PS> if ([double]0.0) { $true } else { $false }
+False
+```
+
+The following types evaluate to `$true`:
+
+- Non-empty strings
+- Instances of any other non-collection type
+
+Examples:
+
+```powershell
+# a non-collection type
+PS> [bool]@{value = 0}
+True
+# non-empty strings
+PS> if ('hello') { $true } else { $false }
+True
+PS> [bool]'False'
+True
+```
+
+Note that this differs from _explicit string parsing_:
+
+```powershell
+PS> [bool]::Parse('false')
+False
+PS> [bool]::Parse('True')
+True
+PS> [bool]::Parse('Not True')
+MethodInvocationException: Exception calling "Parse" with "1" argument(s):
+"String 'Not True' was not recognized as a valid Boolean."
+```
+
+## Converting from collection types
+
+Arrays are the most common collection type in PowerShell. These rules apply to
+any collection-like types that implement the
+[IList](/dotnet/api/system.collections.ilist) interface.
+
+- Empty collections are always `$false`
+- The special null value indicating the absence of output from a command,
+ `[System.Management.Automation.Internal.AutomationNull]::Value` is always
+ `$false`.
+- Single-element collections evaluate to the **Boolean** value of their one and
+ only element.
+- Collections with more than 1 element are always `$true`.
+
+Examples:
+
+```powershell
+# Empty collections
+PS> [bool]@()
+False
+PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt')
+False
+# Single-element collections
+PS> $a = @(0)
+PS> [bool]$a
+False
+PS> $b = @(1)
+PS> [bool]$b
+True
+# Multi-element collections
+PS> $c = @(0,0)
+PS> [bool]$c
+True
+```
+
+## See also
+
+- [about_Arrays](about_Arrays.md#where)
Microsoft.PowerShell.Core About Comparison Operators (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Comparison_Operators.md
--- description: Describes the operators that compare values in PowerShell. Locale: en-US Previously updated : 03/15/2021 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Comparison Operators
Scalar examples:
``` If the input is a collection, the operators return the matching members of that
-collection.
+collection and the `$Matches` automatic variable is `$null`.
Collection examples:
$a -isnot $b.GetType() # Output: True
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object) - [Foreach-Object](xref:Microsoft.PowerShell.Core.ForEach-Object) - [Where-Object](xref:Microsoft.PowerShell.Core.Where-Object)
+- [about_Booleans](about_Booleans.md)
[1]: /dotnet/api/system.icomparable [2]: /dotnet/api/system.iequatable-1
Microsoft.PowerShell.Core About Do (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Do.md
--- description: Runs a statement list one or more times, subject to a While or Until condition. Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_do?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Do
Title: about Do
# about_Do ## SHORT DESCRIPTION
-Runs a statement list one or more times, subject to a While or Until
+Runs a statement list one or more times, subject to a `While` or `Until`
condition. ## LONG DESCRIPTION
-The Do keyword works with the While keyword or the Until keyword to run the
-statements in a script block, subject to a condition. Unlike the related
-While loop, the script block in a Do loop always runs at least once.
+The `Do` keyword works with the `While` keyword or the `Until` keyword to run
+the statements in a script block, subject to a condition. Unlike the related
+`While` loop, the script block in a `Do` loop always runs at least once.
-A **Do-While** loop is a variety of the While loop. In a **Do-While** loop,
-the condition is evaluated after the script block has run. As in a While
-loop, the script block is repeated as long as the condition evaluates to
-true.
+A **Do-While** loop is a variety of the `While` loop. In a **Do-While** loop,
+the condition is evaluated after the script block has run. As in a While loop,
+the script block is repeated as long as the condition evaluates to true.
Like a **Do-While** loop, a **Do-Until** loop always runs at least once before the condition is evaluated. However, the script block runs only while the condition is false.
-The *Continue* and *Break* flow control keywords can be used in a
-**Do-While** loop or in a **Do-Until** loop.
+The `Continue` and `Break` flow control keywords can be used in a **Do-While**
+loop or in a **Do-Until** loop.
### Syntax
The following shows the syntax of the **Do-Until** statement:
do {<statement list>} until (<condition>) ```
-The statement list contains one or more statements that run each time the
-loop is entered or repeated.
+The statement list contains one or more statements that run each time the loop
+is entered or repeated.
-The condition portion of the statement resolves to true or false.
+The condition portion of the statement resolves to true or false. For more
+information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
### Example
-The following example of a Do statement counts the items in an array until
-it reaches an item with a value of 0.
+The following example of a `Do` statement counts the items in an array until it
+reaches an item with a value of 0.
```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } while ($x[$a] -ne 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } while ($x[$a] -ne 0)
+PS> $count
3 ```
-The following example uses the Until keyword. Notice that the not equal to
+The following example uses the `Until` keyword. Notice that the not equal to
operator (`-ne`) is replaced by the equal to operator (`-eq`). ```powershell
-C:\PS> $x = 1,2,78,0
-C:\PS> do { $count++; $a++; } until ($x[$a] -eq 0)
-C:\PS> $count
+PS> $x = 1,2,78,0
+PS> do { $count++; $a++; } until ($x[$a] -eq 0)
+PS> $count
3 ```
while (++$a -lt 10)
## SEE ALSO
-[about_While](about_While.md)
-
-[about_Operators](about_Operators.md)
-
-[about_Assignment_Operators](about_Assignment_Operators.md)
-
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Break](about_Break.md)
-
-[about_Continue](about_Continue.md)
-
+- [about_While](about_While.md)
+- [about_Operators](about_Operators.md)
+- [about_Assignment_Operators](about_Assignment_Operators.md)
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Break](about_Break.md)
+- [about_Continue](about_Continue.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About If (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_If.md
--- description: Describes a language command you can use to run statement lists based on the results of one or more conditional tests. Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about If
Title: about If
# about_If ## SHORT DESCRIPTION
-Describes a language command you can use to run statement lists based on
-the results of one or more conditional tests.
+Describes a language command you can use to run statement lists based on the
+results of one or more conditional tests.
## LONG DESCRIPTION You can use the `If` statement to run code blocks if a specified conditional
-test evaluates to true. You can also specify one or more additional
-conditional tests to run if all the prior tests evaluate to false. Finally,
-you can specify an additional code block that is run if no other prior
-conditional test evaluates to true.
+test evaluates to true. You can also specify one or more additional conditional
+tests to run if all the prior tests evaluate to false. Finally, you can specify
+an additional code block that is run if no other prior conditional test
+evaluates to true.
### Syntax
if (<test1>)
{<statement list 3>}] ```
-When you run an `If` statement, PowerShell evaluates the `<test1>`
-conditional expression as true or false. If `<test1>` is true,
-`<statement list 1>` runs, and PowerShell exits the `If` statement. If
-`<test1>` is false, PowerShell evaluates the condition specified by the
-`<test2>` conditional statement.
+When you run an `If` statement, PowerShell evaluates the `<test1>` conditional
+expression as true or false. If `<test1>` is true, `<statement list 1>` runs,
+and PowerShell exits the `If` statement. If `<test1>` is false, PowerShell
+evaluates the condition specified by the `<test2>` conditional statement.
-If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the
-`If` statement. If both `<test1>` and `<test2>` evaluate to false, the
-`<statement list 3`> code block runs, and PowerShell exits the If
-statement.
+For more information about boolean evaluation, see
+[about_Booleans](about_Booleans.md).
-You can use multiple Elseif statements to chain a series of conditional
-tests. So, that each test is run only if all the previous tests are false.
-If you need to create an `If` statement that contains many Elseif statements,
+If `<test2>` is true, `<statement list 2>` runs, and PowerShell exits the `If`
+statement. If both `<test1>` and `<test2>` evaluate to false, the
+`<statement list 3`> code block runs, and PowerShell exits the If statement.
+
+You can use multiple `Elseif` statements to chain a series of conditional
+tests. So, that each test is run only if all the previous tests are false. If
+you need to create an `If` statement that contains many `Elseif` statements,
consider using a Switch statement instead. Examples:
if ($a -gt 2) {
} ```
-In this example, if the $a variable is greater than 2, the condition
-evaluates to true, and the statement list runs. However, if $a is less than
-or equal to 2 or is not an existing variable, the `If` statement does not
-display a message.
+In this example, if the $a variable is greater than 2, the condition evaluates
+to true, and the statement list runs. However, if $a is less than or equal to 2
+or is not an existing variable, the `If` statement does not display a message.
By adding an Else statement, a message is displayed when $a is less than or equal to 2. As the next example shows:
else {
} ```
-To further refine this example, you can use the Elseif statement to display
-a message when the value of $a is equal to 2. As the next example shows:
+To further refine this example, you can use the Elseif statement to display a
+message when the value of $a is equal to 2. As the next example shows:
```powershell if ($a -gt 2) {
else {
### Using the ternary operator syntax
-PowerShell 7.0 introduced a new syntax using the ternary operator. It follows the C# ternary
-operator syntax:
+PowerShell 7.0 introduced a new syntax using the ternary operator. It follows
+the C# ternary operator syntax:
```Syntax <condition> ? <if-true> : <if-false> ```
-The ternary operator behaves like the simplified `if-else` statement. The `<condition>` expression
-is evaluated and the result is converted to a boolean to determine which branch should be evaluated
-next:
+The ternary operator behaves like the simplified `if-else` statement. The
+`<condition>` expression is evaluated and the result is converted to a boolean
+to determine which branch should be evaluated next:
-- The `<if-true>` expression is executed if the `<condition>` expression is true-- The `<if-false>` expression is executed if the `<condition>` expression is false
+- The `<if-true>` expression is executed if the `<condition>` expression is
+ true
+- The `<if-false>` expression is executed if the `<condition>` expression is
+ false
For example:
For example:
$message = (Test-Path $path) ? "Path exists" : "Path not found" ```
-In this example, the value of `$message` is "Path exists" when `Test-Path` returns `$true`. When
-`Test-Path` returns `$false`, the value of `$message` is "Path not found".
+In this example, the value of `$message` is "Path exists" when `Test-Path`
+returns `$true`. When `Test-Path` returns `$false`, the value of `$message` is
+"Path not found".
```powershell $service = Get-Service BITS $service.Status -eq 'Running' ? (Stop-Service $service) : (Start-Service $service) ```
-In this example, if the service is running, it is stopped, and if its status is not **Running**,
-it is started.
+In this example, if the service is running, it is stopped, and if its status is
+not **Running**, it is started.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Switch](about_Switch.md)
-
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Switch](about_Switch.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core About Remote (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Remote.md
---
-description: Describes how to run remote commands in PowerShell.
+description: Describes how to run remote commands in PowerShell.
Locale: en-US Last updated 01/03/2018 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote?view=powershell-7.2&WT.mc_id=ps-gethelp
remote computer where it terminates the remote command.
- For information about how remoting works, how to manage remote data, special configurations, security issues, and other frequently asked questions, see
- [about_Remote_FAQ](about_Remote_FAQ.md).
+ [PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml).
- For help in resolving remoting errors, see about_Remote_Troubleshooting.
about_Remoting
[about_Remote_Requirements](about_Remote_Requirements.md)
-[about_Remote_FAQ](about_Remote_FAQ.md)
+[PowerShell Remoting FAQ](/powershell/scripting/learn/remoting/powershell-remoting-faq.yml)
[about_Remote_TroubleShooting](about_Remote_TroubleShooting.md)
about_Remoting
[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command) [New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)-
Microsoft.PowerShell.Core About Remote FAQ (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Remote_FAQ.md
-description: Contains questions and answers about running remote commands in PowerShell.
-Locale: en-US
Previously updated : 07/23/2020
-online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_remote_faq?view=powershell-7.2&WT.mc_id=ps-gethelp
-schema: 2.0.0
Title: about Remote FAQ
-# about_Remote_FAQ
-
-## Short description
-Contains questions and answers about running remote commands in PowerShell.
-
-## Long description
-
-When you work remotely, you type commands in PowerShell on one computer (known
-as the "local computer"), but the commands run on another computer (known as
-the "remote computer"). The experience of working remotely should be as much
-like working directly at the remote computer as possible.
-
-Note: To use PowerShell remoting, the remote computer must be configured for
-remoting. For more information, see
-[about_Remote_Requirements](about_Remote_Requirements.md).
-
-### Must both computers have PowerShell installed?
-
-Yes. To work remotely, the local and remote computers must have PowerShell, the
-Microsoft .NET Framework, and the Web Services for Management (WS-Management)
-protocol. Any files and other resources that are needed to execute a particular
-command must be on the remote computer.
-
-Computers running Windows PowerShell 3.0 and computers running Windows
-PowerShell 2.0 can connect to each other remotely and run remote commands.
-However, some features, such as the ability to disconnect from a session and
-reconnect to it, work only when both computers are running Windows PowerShell
-3.0.
-
-You must have permission to connect to the remote computer, permission to run
-PowerShell, and permission to access data stores (such as files and folders),
-and the registry on the remote computer.
-
-For more information, see [about_Remote_Requirements](about_Remote_Requirements.md).
-
-### How does remoting work?
-
-When you submit a remote command, the command is transmitted across the network
-to the PowerShell engine on the remote computer, and it runs in the PowerShell
-client on the remote computer. The command results are sent back to the local
-computer and appear in the PowerShell session on the local computer.
-
-To transmit the commands and receive the output, PowerShell uses the
-WS-Management protocol. For information about the WS-Management protocol, see
-[WS-Management Protocol](/windows/win32/winrm/ws-management-protocol) in the
-Windows documentation.
-
-Beginning in Windows PowerShell 3.0, remote sessions are stored on the remote
-computer. This enables you to disconnect from the session and reconnect from a
-different session or a different computer without interrupting the commands or
-losing state.
-
-### Is PowerShell remoting secure?
-
-When you connect to a remote computer, the system uses the username and
-password credentials on the local computer or the credentials that you supply
-in the command to log you in to the remote computer. The credentials and the
-rest of the transmission are encrypted.
-
-To add additional protection, you can configure the remote computer to use
-Secure Sockets Layer (SSL) instead of HTTP to listen for Windows Remote
-Management (WinRM) requests. Then, users can use the **UseSSL** parameter of
-the `Invoke-Command`, `New-PSSession`, and `Enter-PSSession` cmdlets when
-establishing a connection. This option uses the more secure HTTPS channel
-instead of HTTP.
-
-### Do all remote commands require PowerShell remoting?
-
-No. Several cmdlets have a **ComputerName** parameter that lets you get objects
-from the remote computer.
-
-These cmdlets do not use PowerShell remoting. So, you can use them on any
-computer that is running PowerShell, even if the computer is not configured for
-PowerShell remoting or if the computer does not meet the requirements for
-PowerShell remoting.
-
-These cmdlets include the following:
--- `Get-Process`-- `Get-Service`-- `Get-WinEvent`-- `Get-EventLog`-- `Test-Connection`-
-To find all the cmdlets with a **ComputerName** parameter, type:
-
-```powershell
-Get-Help * -Parameter ComputerName
-# or
-Get-Command -ParameterName ComputerName
-```
-
-To determine whether the **ComputerName** parameter of a particular cmdlet
-requires PowerShell remoting, see the parameter description. To display the
-parameter description, type:
-
-```powershell
-Get-Help <cmdlet-name> -Parameter ComputerName
-```
-
-For example:
-
-```powershell
-Get-Help Get-Process -Parameter ComputerName
-```
-
-For all other commands, use the `Invoke-Command` cmdlet.
-
-### How do I run a command on a remote computer?
-
-To run a command on a remote computer, use the `Invoke-Command` cmdlet.
-
-Enclose your command in braces (`{}`) to make it a script block. Use the
-**ScriptBlock** parameter of `Invoke-Command` to specify the command.
-
-You can use the **ComputerName** parameter of `Invoke-Command` to specify a
-remote computer. Or, you can create a persistent connection to a remote
-computer (a session) and then use the **Session** parameter of `Invoke-Command`
-to run the command in the session.
-
-For example, the following commands run a `Get-Process` command remotely.
-
-```powershell
-Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Process}
-
-# - OR -
-
-Invoke-Command -Session $s -ScriptBlock {Get-Process}
-```
-
-To interrupt a remote command, type <kbd>CTRL</kbd>+<kbd>C</kbd>. The
-interruption request is passed to the remote computer, where it terminates the
-remote command.
-
-For more information about remote commands, see about_Remote and the Help
-topics for the cmdlets that support remoting.
-
-### Can I just telnet into a remote computer?
-
-You can use the `Enter-PSSession` cmdlet to start an interactive session with a
-remote computer.
-
-At the PowerShell prompt, type:
-
-```powershell
-Enter-PSSession <ComputerName>
-```
-
-The command prompt changes to show that you are connected to the remote
-computer.
-
-```
-<ComputerName>\C:>
-```
-
-Now, the commands that you type run on the remote computer just as though you
-typed them directly on the remote computer.
-
-To end the interactive session, type:
-
-```powershell
-Exit-PSSession
-```
-
-An interactive session is a persistent session that uses the WS-Management
-protocol. It is not the same as using Telnet, but it provides a similar
-experience.
-
-For more information, see `Enter-PSSession`.
-
-### Can I create a persistent connection?
-
-Yes. You can run remote commands by specifying the name of the remote computer,
-its NetBIOS name, or its IP address. Or, you can run remote commands by
-specifying a PowerShell session (PSSession) that is connected to the remote
-computer.
-
-When you use the **ComputerName** parameter of `Invoke-Command` or
-`Enter-PSSession`, PowerShell establishes a temporary connection. PowerShell
-uses the connection to run only the current command, and then it closes the
-connection. This is a very efficient method for running a single command or
-several unrelated commands, even on many remote computers.
-
-When you use the `New-PSSession` cmdlet to create a PSSession, PowerShell
-establishes a persistent connection for the PSSession. Then, you can run
-multiple commands in the PSSession, including commands that share data.
-
-Typically, you create a PSSession to run a series of related commands that
-share data. Otherwise, the temporary connection created by the **ComputerName**
-parameter is sufficient for most commands.
-
-For more information about sessions, see about_PSSessions.
-
-### Can I run commands on more than one computer at a time?
-
-Yes. The **ComputerName** parameter of the `Invoke-Command` cmdlet accepts
-multiple computer names, and the **Session** parameter accepts multiple
-PSSessions.
-
-When you run an `Invoke-Command` command, PowerShell runs the commands on all
-of the specified computers or in all of the specified PSSessions.
-
-PowerShell can manage hundreds of concurrent remote connections. However, the
-number of remote commands that you can send might be limited by the resources
-of your computer and its capacity to establish and maintain multiple network
-connections.
-
-For more information, see the example in the `Invoke-Command` Help topic.
-
-### Where are my profiles?
-
-PowerShell profiles are not run automatically in remote sessions, so the
-commands that the profile adds are not present in the session. In addition, the
-`$profile` automatic variable is not populated in remote sessions.
-
-To run a profile in a session, use the `Invoke-Command` cmdlet.
-
-For example, the following command runs the CurrentUserCurrentHost profile
-from the local computer in the session in `$s`.
-
-```
-Invoke-Command -Session $s -FilePath $profile
-```
-
-The following command runs the CurrentUserCurrentHost profile from the remote
-computer in the session in `$s`. Because the `$profile` variable is not populated,
-the command uses the explicit path to the profile.
-
-```powershell
-Invoke-Command -Session $s {
- . "$home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
-}
-```
-
-After running this command, the commands that the profile adds to the session
-are available in `$s`.
-
-You can also use a startup script in a session configuration to run a profile
-in every remote session that uses the session configuration.
-
-For more information about PowerShell profiles, see about_Profiles.
-For more information about session configurations, see
-`Register-PSSessionConfiguration`.
-
-### How does throttling work on remote commands?
-
-To help you manage the resources on your local computer, PowerShell
-includes a per-command throttling feature that lets you limit the number of
-concurrent remote connections that are established for each command.
-
-The default is 32 concurrent connections, but you can use the **ThrottleLimit**
-parameter of the cmdlets to set a custom throttle limit for particular
-commands.
-
-When you use the throttling feature, remember that it is applied to each
-command, not to the entire session or to the computer. If you are running
-commands concurrently in several sessions or PSSessions, the number of
-concurrent connections is the sum of the concurrent connections in all the
-sessions.
-
-To find cmdlets with a **ThrottleLimit** parameter, type:
-
-```
-Get-Help * -Parameter ThrottleLimit
--or-
-Get-Command -ParameterName ThrottleLimit
-```
-
-### Is the output of remote commands different from local output?
-
-When you use PowerShell locally, you send and receive "live" .NET
-Framework objects; "live" objects are objects that are associated with actual
-programs or system components. When you invoke the methods or change the
-properties of live objects, the changes affect the actual program or
-component. And, when the properties of a program or component change, the
-properties of the object that represent them also change.
-
-However, because most live objects cannot be transmitted over the network,
-PowerShell "serializes" most of the objects sent in remote commands,
-that is, it converts each object into a series of XML (Constraint Language in
-XML [CLiXML]) data elements for transmission.
-
-When PowerShell receives a serialized object, it converts the XML into
-a deserialized object type. The deserialized object is an accurate record of
-the properties of the program or component at a previous time, but it is no
-longer "live", that is, it is no longer directly associated with the
-component. And, the methods are removed because they are no longer effective.
-
-Typically, you can use deserialized objects just as you would use live
-objects, but you must be aware of their limitations. Also, the objects that
-are returned by the `Invoke-Command` cmdlet have additional properties that help
-you to determine the origin of the command.
-
-Some object types, such as DirectoryInfo objects and GUIDs, are converted back
-into live objects when they are received. These objects do not need any
-special handling or formatting.
-
-For information about interpreting and formatting remote output, see
-[about_Remote_Output](about_Remote_Output.md).
-
-### Can I run background jobs remotely?
-
-Yes. A PowerShell background job is a PowerShell command that
-runs asynchronously without interacting with the session. When you start a
-background job, the command prompt returns immediately, and you can continue
-to work in the session while the job runs even if it runs for an extended
-period of time.
-
-You can start a background job even while other commands are running because
-background jobs always run asynchronously in a temporary session.
-
-You can run background jobs on a local or remote computer. By default, a
-background job runs on the local computer. However, you can use the **AsJob**
-parameter of the `Invoke-Command` cmdlet to run any remote command as a
-background job. And, you can use `Invoke-Command` to run a `Start-Job` command
-remotely.
-
-For more information about background jobs in PowerShell , see
-[about_Jobs(about_Jobs.md)] and [about_Remote_Jobs(about_Remote_Jobs.md)].
-
-### Can I run windows programs on a remote computer?
-
-You can use PowerShell remote commands to run Windows-based programs on remote
-computers. For example, you can run `Shutdown.exe` or `Ipconfig.exe` on a
-remote computer.
-
-However, you cannot use PowerShell commands to open the user interface
-for any program on a remote computer.
-
-When you start a Windows program on a remote computer, the command is not
-completed, and the PowerShell command prompt does not return, until the program
-is finished or until you press <kbd>CTRL</kbd>+<kbd>C</kbd> to interrupt the
-command. For example, if you run the `Ipconfig.exe` program on a remote
-computer, the command prompt does not return until `Ipconfig.exe` is completed.
-
-If you use remote commands to start a program that has a user interface, the
-program process starts, but the user interface does not appear. The PowerShell
-command is not completed, and the command prompt does not return until you stop
-the program process or until you press <kbd>CTRL</kbd>+<kbd>C</kbd>, which
-interrupts the command and stops the process.
-
-For example, if you use a PowerShell command to run `Notepad` on a
-remote computer, the Notepad process starts on the remote computer, but the
-Notepad user interface does not appear. To interrupt the command and restore
-the command prompt, press <kbd>CTRL</kbd>+<kbd>C</kbd>.
-
-### Can I limit the commands that users can run remotely on my computer?
-
-Yes. Every remote session must use one of the session configurations on the
-remote computer. You can manage the session configurations on your computer
-(and the permissions to those session configurations) to determine who can run
-commands remotely on your computer and which commands they can run.
-
-A session configuration configures the environment for the session. You can
-define the configuration by using an assembly that implements a new
-configuration class or by using a script that runs in the session. The
-configuration can determine the commands that are available in the session.
-And, the configuration can include settings that protect the computer, such as
-settings that limit the amount of data that the session can receive remotely
-in a single object or command. You can also specify a security descriptor that
-determines the permissions that are required to use the configuration.
-
-The `Enable-PSRemoting` cmdlet creates the default session configurations on
-your computer: Microsoft.PowerShell, Microsoft.PowerShell.Workflow, and
-Microsoft.PowerShell32 (64-bit operating systems only). `Enable-PSRemoting` sets
-the security descriptor for the configuration to allow only members of the
-Administrators group on your computer to use them.
-
-You can use the session configuration cmdlets to edit the default session
-configurations, to create new session configurations, and to change the
-security descriptors of all the session configurations.
-
-Beginning in Windows PowerShell 3.0, the `New-PSSessionConfigurationFile` cmdlet
-lets you create custom session configurations by using a text file. The file
-includes options for setting the language mode and for specifying the cmdlets
-and modules that are available in sessions that use the session configuration.
-
-When users use the `Invoke-Command`, `New-PSSession`, or `Enter-PSSession`
-cmdlets, they can use the **ConfigurationName** parameter to indicate the
-session configuration that is used for the session. And, they can change the
-default configuration that their sessions use by changing the value of the
-`$PSSessionConfigurationName` preference variable in the session.
-
-For more information about session configurations, see the Help for the
-session configuration cmdlets. To find the session configuration cmdlets,
-type:
-
-```powershell
-Get-Command *PSSessionConfiguration
-```
-
-### What are fan in and fan out configurations?
-
-The most common PowerShell remoting scenario involving multiple
-computers is the one-to-many configuration, in which one local computer (the
-administrator's computer) runs PowerShell commands on numerous remote
-computers. This is known as the "fan-out" scenario.
-
-However, in some enterprises, the configuration is many-to-one, where many
-client computers connect to a single remote computer that is running
-PowerShell, such as a file server or a kiosk. This is known as the "fan-in"
-configuration.
-
-PowerShell remoting supports both fan-out and fan-in configurations.
-
-For the fan-out configuration, PowerShell uses the Web Services for
-Management (WS-Management) protocol and the WinRM service that supports the
-Microsoft implementation of WS-Management. When a local computer connects to a
-remote computer, WS-Management establishes a connection and uses a plug-in for
-PowerShell to start the PowerShell host process
-(Wsmprovhost.exe) on the remote computer. The user can specify an alternate
-port, an alternate session configuration, and other features to customize the
-remote connection.
-
-To support the "fan-in" configuration, PowerShell uses internet Information
-Services (IIS) to host WS-Management, to load the PowerShell plug-in, and to
-start PowerShell. In this scenario, instead of starting each PowerShell session
-in a separate process, all PowerShell sessions run in the same host process.
-
-IIS hosting and fan-in remote management is not supported in Windows XP or in
-Windows Server 2003.
-
-In a fan-in configuration, the user can specify a connection URI and an HTTP
-endpoint, including the transport, computer name, port, and application name.
-IIS forwards all the requests with a specified application name to the
-application. The default is WS-Management, which can host PowerShell.
-
-You can also specify an authentication mechanism and prohibit or allow
-redirection from HTTP and HTTPS endpoints.
-
-### Can I test remoting on a single computer not in a domain?
-
-Yes. PowerShell remoting is available even when the local computer is
-not in a domain. You can use the remoting features to connect to sessions and
-to create sessions on the same computer. The features work the same as they do
-when you connect to a remote computer.
-
-To run remote commands on a computer in a workgroup, change the following
-Windows settings on the computer.
-
-Caution: These settings affect all users on the system and they can make the
-system more vulnerable to a malicious attack. Use caution when making these
-changes.
--- Windows Vista, Windows 7, Windows 8:-
- Create the following registry entry, and then set its value to 1:
- LocalAccountTokenFilterPolicy in
- ` HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System`
-
- You can use the following PowerShell command to add this entry:
-
- ```powershell
- $parameters = @{
- Path='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
- Name='LocalAccountTokenFilterPolicy'
- propertyType='DWord'
- Value=1
- }
- New-ItemProperty @parameters
- ```
--- Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows
- Server 2012 R2:
-
- No changes are needed because the default setting of the "Network Access:
- Sharing and security model for local accounts" policy is "Classic". Verify
- the setting in case it has changed.
-
-### Can I run remote commands on a computer in another domain?
-
-Yes. Typically, the commands run without error, although you might need to use
-the **Credential** parameter of the `Invoke-Command`, `New-PSSession`, or
-`Enter-PSSession` cmdlets to provide the credentials of a member of the
-Administrators group on the remote computer. This is sometimes required even
-when the current user is a member of the Administrators group on the local and
-remote computers.
-
-However, if the remote computer is not in a domain that the local computer
-trusts, the remote computer might not be able to authenticate the user's
-credentials.
-
-To enable authentication, use the following command to add the remote computer
-to the list of trusted hosts for the local computer in WinRM. Type the command
-at the PowerShell prompt.
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value <Remote-computer-name>
-```
-
-For example, to add the Server01 computer to the list of trusted hosts on the
-local computer, type the following command at the PowerShell prompt:
-
-```powershell
-Set-Item WSMan:\localhost\Client\TrustedHosts -Value Server01
-```
-
-### Does PowerShell support remoting over SSH?
-
-Yes. For more information, see
-[PowerShell remoting over SSH](/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core).
-
-## See also
-
-[about_Remote](about_Remote.md)
-
-[about_Profiles](about_Profiles.md)
-
-[about_PSSessions](about_PSSessions.md)
-
-[about_Remote_Jobs](about_Remote_Jobs.md)
-
-[about_Remote_Variables](about_Remote_Variables.md)
-
-[Invoke-Command](xref:Microsoft.PowerShell.Core.Invoke-Command)
-
-[New-PSSession](xref:Microsoft.PowerShell.Core.New-PSSession)
Microsoft.PowerShell.Core About Switch (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Switch.md
--- description: Explains how to use a switch to handle multiple `If` statements. Locale: en-US Previously updated : 05/22/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Switch
switch -Regex ($target)
https://bing.com is a web address that uses https ```
-A Switch statement condition may be either:
+A `Switch` statement condition may be either:
- An expression whose value is compared to the input value - A script block which should return `$true` if a condition is met.
-The `$_` automatic variable contains the value passed to the switch statement
+The `$_` automatic variable contains the value passed to the `switch` statement
and is available for evaluation and use within the scope of the condition statements.
Microsoft.PowerShell.Core About While (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_While.md
--- description: Describes a language statement that you can use to run a command block based on the results of a conditional test. Locale: en-US Previously updated : 06/09/2017 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_while?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about While
Title: about While
# about_While ## SHORT DESCRIPTION
-Describes a language statement that you can use to run a command block
-based on the results of a conditional test.
+Describes a language statement that you can use to run a command block based on
+the results of a conditional test.
## LONG DESCRIPTION
-The While statement (also known as a While loop) is a language construct
+The `While` statement (also known as a `While` loop) is a language construct
for creating a loop that runs commands in a command block as long as a
-conditional test evaluates to true. The While statement is easier to
+conditional test evaluates to true. The `While` statement is easier to
construct than a For statement because its syntax is less complicated. In
-addition, it is more flexible than the Foreach statement because you
-specify a conditional test in the While statement to control how many times
-the loop runs.
+addition, it is more flexible than the Foreach statement because you specify a
+conditional test in the `While` statement to control how many times the loop
+runs.
The following shows the While statement syntax:
The following shows the While statement syntax:
while (<condition>){<statement list>} ```
-When you run a While statement, PowerShell evaluates the `<condition>`
-section of the statement before entering the `<statement list>` section. The
-condition portion of the statement resolves to either true or false. As
-long as the condition remains true, PowerShell reruns the `<statement list>`
-section.
+When you run a While statement, PowerShell evaluates the `<condition>` section
+of the statement before entering the `<statement list>` section. The condition
+portion of the statement resolves to either true or false. As long as the
+condition remains true, PowerShell reruns the `<statement list>` section. For
+more information about how booleans are evaluated, see
+[about_Booleans](about_Booleans.md).
-The `<statement list>` section of the statement contains one or more
-commands that are run each time the loop is entered or repeated.
+The `<statement list>` section of the statement contains one or more commands
+that are run each time the loop is entered or repeated.
-For example, the following While statement displays the numbers 1 through 3
-if the $val variable has not been created or if the $val variable has been
+For example, the following While statement displays the numbers 1 through 3 if
+the `$val` variable has not been created or if the `$val` variable has been
created and initialized to 0. ```powershell
while($val -ne 3)
} ```
-In this example, the condition ($val is not equal to 3) is true while $val
-\= 0, 1, 2. Each time through the loop, $val is incremented by 1 using the
-\+\+ unary increment operator ($val\+\+). The last time through the loop,
-$val \= 3. When $val equals 3, the condition statement evaluates to false,
-and the loop exits.
+In this example, the condition (`$val` is not equal to 3) is true while `$val`
+is equal to 0, 1, and 2. Each time through the loop, `$val` is incremented by 1
+using the `++` unary increment operator. The last time through the loop `$val`
+is set to 3, the condition statement evaluates to false, and the loop exits.
To conveniently write this command at the PowerShell command prompt, you can enter it in the following way:
can enter it in the following way:
while($val -ne 3){$val++; Write-Host $val} ```
-Notice that the semicolon separates the first command that adds 1 to $val
-from the second command that writes the value of $val to the console.
+Notice that the semicolon separates the first command that adds 1 to `$val` from
+the second command that writes the value of `$val` to the console.
## SEE ALSO
-[about_Comparison_Operators](about_Comparison_Operators.md)
-
-[about_Do](about_Do.md)
-
-[about_Foreach](about_Foreach.md)
-
-[about_For](about_For.md)
-
-[about_Language_Keywords](about_Language_Keywords.md)
-
+- [about_Comparison_Operators](about_Comparison_Operators.md)
+- [about_Do](about_Do.md)
+- [about_Foreach](about_Foreach.md)
+- [about_For](about_For.md)
+- [about_Language_Keywords](about_Language_Keywords.md)
+- [about_Booleans](about_Booleans.md)
Microsoft.PowerShell.Core Where Object (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/Where-Object.md
external help file: System.Management.Automation.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Core Previously updated : 03/19/2020 Last updated : 06/10/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Where-Object
The previous example is functionally equivalent to:
- `('hi', '', 'there') | Where-Object Length -GT 0` - `('hi', '', 'there') | Where-Object {$_.Length -gt 0}`
+For more information about how booleans are evaluated, see [about_Booleans](about/about_Booleans.md).
+ ## EXAMPLES ### Example 1: Get stopped services
for the command.
```powershell # Use Where-Object to get commands that have any value for the OutputType property of the command.
-# This omits commands that do not have an OutputType property and those that have an OutputType property, but no property value.
+# This omits commands that do not have an OutputType property and those that have an OutputType
+# property, but no property value.
Get-Command | where OutputType Get-Command | where {$_.OutputType} ``` ```powershell # Use Where-Object to get objects that are containers.
-# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all others.
+# This gets objects that have the **PSIsContainer** property with a value of $True and excludes all
+# others.
Get-ChildItem | where PSIsContainer Get-ChildItem | where {$_.PSIsContainer} ``` ```powershell # Finally, use the Not operator (!) to get objects that are not containers.
-# This gets objects that do have the **PSIsContainer** property and those that have a value of $False for the **PSIsContainer** property.
+# This gets objects that do have the **PSIsContainer** property and those that have a value of
+# $False for the **PSIsContainer** property.
Get-ChildItem | where {!$_.PSIsContainer} # You cannot use the Not operator (!) in the comparison statement format of the command. Get-ChildItem | where PSIsContainer -eq $False
The example uses the script block command format. Logical operators, such as **A
valid only in script blocks. You cannot use them in the comparison statement format of a `Where-Object` command. -- For more information about PowerShell logical operators, see [about_Logical_Operators](./About/about_logical_operators.md).-- For more information about the Updatable Help feature, see [about_Updatable_Help](./About/about_Updatable_Help.md).
+- For more information about PowerShell logical operators, see
+ [about_Logical_Operators](./About/about_logical_operators.md).
+- For more information about the Updatable Help feature, see
+ [about_Updatable_Help](./About/about_Updatable_Help.md).
## PARAMETERS
This cmdlet returns selected items from the input object set.
## NOTES
-Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with collections.
+Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with
+collections.
You can read more about these new methods here [about_arrays](./About/about_Arrays.md)
You can read more about these new methods here [about_arrays](./About/about_Arra
[Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)
+[about_Booleans](about/about_Booleans.md)
dsc Msft Dsclocalconfigurationmanager Applyconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-applyconfiguration.md
If there is no configuration pending, this method reapplies the current configur
```mof uint32 ApplyConfiguration(
- [in] boolean force
+ [in] boolean force
); ```
dsc Msft Dsclocalconfigurationmanager Enabledebugconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-enabledebugconfiguration.md
Enables DSC resource debugging.
```mof uint32 EnableDebugConfiguration(
- [in] boolean BreakAll
+ [in] boolean BreakAll
); ```
dsc Msft Dsclocalconfigurationmanager Getconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-getconfiguration.md
Configuration Agent to apply the configuration.
```mof uint32 GetConfiguration(
- [in]  uint8            configurationData[],
- [out] OMI_BaseResource configurations[]
+ [in] uint8 configurationData[],
+ [out] OMI_BaseResource configurations[]
); ```
dsc Msft Dsclocalconfigurationmanager Getconfigurationresultoutput https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-getconfigurationresultoutput.md
Gets the Configuration Agent output associated with a specific job.
```mof uint32 GetConfigurationResultOutput(
- [in]  string                      jobId,
- [in]  uint8                       resumeOutputBookmark[],
- [out] MSFT_DSCConfigurationOutput output[]
+ [in] string jobId,
+ [in] uint8 resumeOutputBookmark[],
+ [out] MSFT_DSCConfigurationOutput output[]
); ```
dsc Msft Dsclocalconfigurationmanager Getconfigurationstatus https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-getconfigurationstatus.md
Get the configuration status history.
```mof uint32 GetConfigurationStatus(
- [in]  boolean                     All,
- [out] MSFT_DSCConfigurationStatus configurationStatus[]
+ [in] boolean All,
+ [out] MSFT_DSCConfigurationStatus configurationStatus[]
); ```
dsc Msft Dsclocalconfigurationmanager Getmetaconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-getmetaconfiguration.md
Gets the local Configuration Manager settings that are used to control the Confi
```mof uint32 GetMetaConfiguration(
- [out] MSFT_DSCMetaConfiguration MetaConfiguration
+ [out] MSFT_DSCMetaConfiguration MetaConfiguration
); ```
dsc Msft Dsclocalconfigurationmanager Performrequiredconfigurationchecks https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-performrequiredconfigurationchecks.md
Starts a consistency check by using the Task Scheduler.
```mof uint32 PerformRequiredConfigurationChecks(
- [in] uint32 Flags
+ [in] uint32 Flags
); ```
dsc Msft Dsclocalconfigurationmanager Removeconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-removeconfiguration.md
Removes the configuration files.
```mof uint32 RemoveConfiguration(
- [in] uint32  Stage,
- [in] boolean Force
+ [in] uint32 Stage,
+ [in] boolean Force
); ```
dsc Msft Dsclocalconfigurationmanager Resourceget https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-resourceget.md
Directly calls the **Get** method of a DSC resource.
```mof uint32 ResourceGet(
- [in]  string           ResourceType,
- [in]  string           ModuleName,
- [in]  uint8            resourceProperty[],
- [out] OMI_BaseResource configurations
+ [in] string ResourceType,
+ [in] string ModuleName,
+ [in] uint8 resourceProperty[],
+ [out] OMI_BaseResource configurations
); ```
dsc Msft Dsclocalconfigurationmanager Resourceset https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-resourceset.md
Directly calls the **Set** method of a DSC resource.
```mof uint32 ResourceSet(
- [in]  string  ResourceType,
- [in]  string  ModuleName,
- [in]  uint8   resourceProperty[],
- [out] boolean RebootRequired
+ [in] string ResourceType,
+ [in] string ModuleName,
+ [in] uint8 resourceProperty[],
+ [out] boolean RebootRequired
); ```
dsc Msft Dsclocalconfigurationmanager Resourcetest https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-resourcetest.md
Directly calls the **Test** method of a DSC resource.
```mof uint32 ResourceTest(
- [in]  string  ResourceType,
- [in]  string  ModuleName,
- [in]  uint8   resourceProperty[],
- [out] boolean InDesiredState
+ [in] string ResourceType,
+ [in] string ModuleName,
+ [in] uint8 resourceProperty[],
+ [out] boolean InDesiredState
); ```
dsc Msft Dsclocalconfigurationmanager Rollback https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-rollback.md
Rolls back the configuration to a previous version.
```mof uint32 RollBack(
- [in] uint8 configurationNumber
+ [in] uint8 configurationNumber
); ```
dsc Msft Dsclocalconfigurationmanager Sendconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-sendconfiguration.md
Sends the configuration document to the managed node and saves it as a pending c
```mof uint32 SendConfiguration(
- [in] uint8   ConfigurationData[],
- [in] boolean force
+ [in] uint8 ConfigurationData[],
+ [in] boolean force
); ```
dsc Msft Dsclocalconfigurationmanager Sendconfigurationapply https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-sendconfigurationapply.md
Sends the configuration document to the managed node and uses the Configuration
```mof uint32 SendConfigurationApply(
- [in] uint8   ConfigurationData[],
- [in] boolean force
+ [in] uint8 ConfigurationData[],
+ [in] boolean force
); ```
dsc Msft Dsclocalconfigurationmanager Sendconfigurationapplyasync https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-sendconfigurationapplyasync.md
to apply the configuration.
```mof uint32 SendConfigurationApplyAsync(
- [in] uint8   ConfigurationData[],
- [in] boolean force,
- [in] string  jobId
+ [in] uint8 ConfigurationData[],
+ [in] boolean force,
+ [in] string jobId
); ```
dsc Msft Dsclocalconfigurationmanager Sendmetaconfigurationapply https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-sendmetaconfigurationapply.md
Sets the Local Configuration Manager settings that are used to control the Confi
```mof uint32 SendMetaConfigurationApply(
- [in] uint8   ConfigurationData[],
- [in] boolean force
+ [in] uint8 ConfigurationData[],
+ [in] boolean force
); ```
dsc Msft Dsclocalconfigurationmanager Stopconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-stopconfiguration.md
Stops the configuration change that is in progress.
```mof uint32 StopConfiguration(
- [in] boolean force
+ [in] boolean force
); ```
dsc Msft Dsclocalconfigurationmanager Testconfiguration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/dsc/reference/mof-classes/msft-dsclocalconfigurationmanager-testconfiguration.md
Sends the configuration document to the managed node and verifies the current co
```mof uint32 TestConfiguration(
- [in]  uint8                          configurationData[],
- [out] boolean                        InDesiredState,
- [out] MSFT_ResourceInDesiredState    ResourcesInDesiredState[],
- [out] MSFT_ResourceNotInDesiredState ResourcesNotInDesiredState[]
+ [in] uint8 configurationData[],
+ [out] boolean InDesiredState,
+ [out] MSFT_ResourceInDesiredState ResourcesInDesiredState[],
+ [out] MSFT_ResourceNotInDesiredState ResourcesNotInDesiredState[]
); ```
learn 08 Powershell Remoting https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/learn/ps101/08-powershell-remoting.md
multiple commands against the same remote computer.
## Recommended Reading - [about_Remote][]-- [about_Remote_FAQ][] - [about_Remote_Output][] - [about_Remote_Requirements][] - [about_Remote_Troubleshooting][] - [about_Remote_Variables][]
+- [PowerShell Remoting FAQ][]
<!-- link references -->
+[PowerShell Remoting FAQ]: ../remoting/powershell-remoting-faq.yml
[about_Remote]: /powershell/module/microsoft.powershell.core/about/about_remote
-[about_Remote_FAQ]: /powershell/module/microsoft.powershell.core/about/about_remote_faq
[about_Remote_Output]: /powershell/module/microsoft.powershell.core/about/about_remote_output [about_Remote_Requirements]: /powershell/module/microsoft.powershell.core/about/about_remote_requirements [about_Remote_Troubleshooting]: /powershell/module/microsoft.powershell.core/about/about_remote_troubleshooting
learn Running Remote Commands https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/learn/remoting/Running-Remote-Commands.md
or in the Windows PowerShell console, type `Get-Help wsman`.
For more information, see: -- [About Remote FAQ](/powershell/module/microsoft.powershell.core/about/about_remote_faq)
+- [PowerShell Remoting FAQ](powershell-remoting-faq.yml)
- [Register-PSSessionConfiguration](xref:Microsoft.PowerShell.Core.Register-PSSessionConfiguration) - [Import-PSSession](xref:Microsoft.PowerShell.Utility.Import-PSSession)
-For help with remoting errors, see [about_Remote_Troubleshooting](/powershell/module/microsoft.powershell.core/about/about_Remote_Troubleshooting).
+For help with remoting errors, see
+[about_Remote_Troubleshooting](/powershell/module/microsoft.powershell.core/about/about_Remote_Troubleshooting).
## See Also - [about_Remote](/powershell/module/microsoft.powershell.core/about/about_remote_faq)-- [about_Remote_FAQ](/powershell/module/microsoft.powershell.core/about/about_remote_faq) - [about_Remote_Requirements](/powershell/module/microsoft.powershell.core/about/about_remote_requirements) - [about_Remote_Troubleshooting](/powershell/module/microsoft.powershell.core/about/about_Remote_Troubleshooting) - [about_PSSessions](/powershell/module/microsoft.powershell.core/about/about_PSSessions)