Updates from: 04/21/2021 03:35:33
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Utility Invoke Restmethod (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Utility/Invoke-RestMethod.md
--- external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 04/05/2021 Last updated : 04/20/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Invoke-RestMethod
Invoke-RestMethod [-Method <WebRequestMethod>] [-UseBasicParsing] [-Uri] <Uri>
## Description The `Invoke-RestMethod` cmdlet sends HTTP and HTTPS requests to Representational State Transfer
-(REST) web services that returns richly structured data.
+(REST) web services that return richly structured data.
-Windows PowerShell formats the response based to the data type. For an RSS or ATOM feed, Windows
-PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML,
-Windows PowerShell converts (or deserializes) the content into objects.
+PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns
+the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or
+deserializes, the content into `[PSCustomObject]` objects.
+
+> [!NOTE]
+> When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe
+> the output from `Invoke-RestMethod` to another command, it is sent as a single `[Object[]]`
+> object. The contents of that array are not enumerated for the next command on the pipeline.
This cmdlet is introduced in Windows PowerShell 3.0.
$R.Forms[0].Password = "MyPassword"
Invoke-RestMethod https://website.com/service.aspx -Body $R.Forms[0] ```
+### Example 4: Enumerate returned items on the pipeline
+
+GitHub returns multiple objects an array. If you pipe the output to another command, it is sent as a
+single `[Object[]]`object.
+
+To enumerate the objects into the pipeline, pipe the results to `Write-Output` or wrap the cmdlet in
+parentheses. The following example counts the number of objects returned by GitHub. Then counts the
+number of objects enumerated to the pipeline.
+
+```powershell
+$uri = 'https://api.github.com/repos/microsoftdocs/powershell-docs/issues'
+$x = 0
+Invoke-RestMethod -Uri $uri | ForEach-Object { $x++ }
+$x
+1
+
+$x = 0
+(Invoke-RestMethod -Uri $uri) | ForEach-Object { $x++ }
+$x
+30
+
+$x = 0
+Invoke-RestMethod -Uri $uri | Write-Output | ForEach-Object { $x++ }
+$x
+30
+```
+ ## Parameters ### -Body
Microsoft.PowerShell.Utility Invoke Restmethod (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Utility/Invoke-RestMethod.md
--- external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 04/05/2021 Last updated : 04/20/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Invoke-RestMethod
The `Invoke-RestMethod` cmdlet sends HTTP and HTTPS requests to Representational
PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or
-deserializes, the content into objects.
+deserializes, the content into `[PSCustomObject]` objects.
+
+> [!NOTE]
+> When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe
+> the output from `Invoke-RestMethod` to another command, it is sent as a single `[Object[]]`
+> object. The contents of that array are not enumerated for the next command on the pipeline.
This cmdlet is introduced in Windows PowerShell 3.0.
$headers = @{
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body ```
+### Example 6: Enumerate returned items on the pipeline
+
+GitHub returns multiple objects an array. If you pipe the output to another command, it is sent as a
+single `[Object[]]`object.
+
+To enumerate the objects into the pipeline, pipe the results to `Write-Output` or wrap the cmdlet in
+parentheses. The following example counts the number of objects returned by GitHub. Then counts the
+number of objects enumerated to the pipeline.
+
+```powershell
+$uri = 'https://api.github.com/repos/microsoftdocs/powershell-docs/issues'
+$x = 0
+Invoke-RestMethod -Uri $uri | ForEach-Object { $x++ }
+$x
+1
+
+$x = 0
+(Invoke-RestMethod -Uri $uri) | ForEach-Object { $x++ }
+$x
+30
+
+$x = 0
+Invoke-RestMethod -Uri $uri | Write-Output | ForEach-Object { $x++ }
+$x
+30
+```
+ ## Parameters ### -AllowUnencryptedAuthentication
Microsoft.PowerShell.Utility Invoke Restmethod (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Utility/Invoke-RestMethod.md
--- external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-keywords: powershell,cmdlet
Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 04/05/2021 Last updated : 04/20/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Invoke-RestMethod
The `Invoke-RestMethod` cmdlet sends HTTP and HTTPS requests to Representational
PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or
-deserializes, the content into objects.
+deserializes, the content into `[PSCustomObject]` objects.
+
+> [!NOTE]
+> When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe
+> the output from `Invoke-RestMethod` to another command, it is sent as a single `[Object[]]`
+> object. The contents of that array are not enumerated for the next command on the pipeline.
This cmdlet is introduced in Windows PowerShell 3.0.
$headers = @{
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body ```
+### Example 6: Enumerate returned items on the pipeline
+
+GitHub returns multiple objects an array. If you pipe the output to another command, it is sent as a
+single `[Object[]]`object.
+
+To enumerate the objects into the pipeline, pipe the results to `Write-Output` or wrap the cmdlet in
+parentheses. The following example counts the number of objects returned by GitHub. Then counts the
+number of objects enumerated to the pipeline.
+
+```powershell
+$uri = 'https://api.github.com/repos/microsoftdocs/powershell-docs/issues'
+$x = 0
+Invoke-RestMethod -Uri $uri | ForEach-Object { $x++ }
+$x
+1
+
+$x = 0
+(Invoke-RestMethod -Uri $uri) | ForEach-Object { $x++ }
+$x
+30
+
+$x = 0
+Invoke-RestMethod -Uri $uri | Write-Output | ForEach-Object { $x++ }
+$x
+30
+```
+ ## Parameters ### -AllowUnencryptedAuthentication
Microsoft.PowerShell.Core Enter Pssession (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/Enter-PSSession.md
Title: Enter-PSSession
--- # Enter-PSSession
-## SYNOPSIS
+## Synopsis
Starts an interactive session with a remote computer.
-## SYNTAX
+## Syntax
### ComputerName (Default)
Enter-PSSession [-ComputerName] <String> [-EnableNetworkAccess] [[-Credential] <
``` Enter-PSSession [-HostName] <String> [-Port <Int32>] [-UserName <String>] [-KeyFilePath <String>]
- [-SSHTransport] [<CommonParameters>]
+ [-SSHTransport] [-ConnectingTimeout <int>] [<CommonParameters>]
``` ### Session
Enter-PSSession [-ContainerId] <String> [-ConfigurationName <String>] [-RunAsAdm
[<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Enter-PSSession` cmdlet starts an interactive session with a single remote computer. During the session, the commands that you type run on the remote computer, just as if you were
information about how to set up PowerShell SSH remoting, see
To end the interactive session and disconnect from the remote computer, use the `Exit-PSSession` cmdlet, or type `exit`.
-## EXAMPLES
+## Examples
### Example 1: Start an interactive session
This example shows how to start an interactive session using SSH. It uses the **
specify the port to use and the **KeyFilePath** parameter to specify an RSA key used to authenticate the user on the remote computer.
-## PARAMETERS
+## Parameters
### -AllowRedirection
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False ```
+### -ConnectingTimeout
+
+Specifies the amount of time in milliseconds allowed for the initial SSH connection to complete. If
+the connection doesn't complete within the specified time, an error is returned.
+
+This parameter was introduced in PowerShell 7.2
+
+```yaml
+Type: System.Int32
+Parameter Sets: SSHHost
+Aliases:
+
+Required: False
+Position: Named
+Default value: unlimited
+Accept pipeline input: False
+Accept wildcard characters: False
+```
+ ### -ConnectionUri Specifies a URI that defines the connection endpoint for the session. The URI must be fully
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.String, System.Management.Automation.Runspaces.PSSession You can pipe a computer name, as a string, or a session object to this cmdlet.
-## OUTPUTS
+## Outputs
### None The cmdlet does not return any output.
-## NOTES
+## Notes
To connect to a remote computer, you must be a member of the Administrators group on the remote computer. To start an interactive session on the local computer, you must start PowerShell with the
Prior to PowerShell 7.1, remoting over SSH did not support second-hop remote ses
capability was limited to sessions using WinRM. PowerShell 7.1 allows `Enter-PSSession` and `Enter-PSHostProcess` to work from within any interactive remote session.
-## RELATED LINKS
+## Related Links
[Exit-PSSession](Exit-PSSession.md)
Microsoft.PowerShell.Core Invoke Command (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/Invoke-Command.md
Title: Invoke-Command
# Invoke-Command
-## SYNOPSIS
+## Synopsis
Runs commands on local and remote computers.
-## SYNTAX
+## Syntax
### InProcess (Default)
Invoke-Command -Credential <PSCredential> [-ConfigurationName <String>] [-Thrott
Invoke-Command [-Port <Int32>] [-AsJob] [-HideComputerName] [-JobName <String>] [-ScriptBlock] <ScriptBlock> -HostName <String[]> [-UserName <String>] [-KeyFilePath <String>] [-SSHTransport] [-RemoteDebug] [-InputObject <PSObject>] [-ArgumentList <Object[]>]
- [-Subsystem <String>] [<CommonParameters>]
+ [-Subsystem <String>] [-ConnectingTimeout <int>] [<CommonParameters>]
``` ### ContainerId
Invoke-Command [-AsJob] [-HideComputerName] -FilePath <String> -SSHConnection <H
[-RemoteDebug] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Invoke-Command` cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. Using a single `Invoke-Command` command, you can run commands on
connection information. For more information about how to set up PowerShell SSH
Some code samples use splatting to reduce the line length. For more information, see [about_Splatting](./About/about_Splatting.md).
-## EXAMPLES
+## Examples
### Example 1: Run a script on a server
$sshConnections =
$results = Invoke-Command -FilePath c:\Scripts\CollectEvents.ps1 -SSHConnection $sshConnections ```
-## PARAMETERS
+## Parameters
### -AllowRedirection
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False ```
+### -ConnectingTimeout
+
+Specifies the amount of time in milliseconds allowed for the initial SSH connection to complete. If
+the connection doesn't complete within the specified time, an error is returned.
+
+This parameter was introduced in PowerShell 7.2
+
+```yaml
+Type: System.Int32
+Parameter Sets: SSHHost
+Aliases:
+
+Required: False
+Position: Named
+Default value: unlimited
+Accept pipeline input: False
+Accept wildcard characters: False
+```
+ ### -ConnectionUri Specifies a Uniform Resource Identifier (URI) that defines the connection endpoint of the session.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.Management.Automation.ScriptBlock You can pipe a command in a script block to `Invoke-Command`. Use the `$Input` automatic variable to represent the input objects in the command.
-## OUTPUTS
+## Outputs
### System.Management.Automation.PSRemotingJob, System.Management.Automation.Runspaces.PSSession, or the output of the invoked command
This cmdlet returns a job object, if you use the **AsJob** parameter. If you spe
**InDisconnectedSession** parameter, `Invoke-Command` returns a **PSSession** object. Otherwise, it returns the output of the invoked command, which is the value of the **ScriptBlock** parameter.
-## NOTES
+## Notes
On Windows Vista, and later versions of the Windows operating system, to use the **ComputerName** parameter of `Invoke-Command` to run a command on the local computer, you must run PowerShell using
disconnect/reconnect features are currently not supported. For more information
PowerShell SSH remoting, see [PowerShell Remoting Over SSH](/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core).
-## RELATED LINKS
+## Related Links
[about_PSSessions](./About/about_PSSessions.md)
PowerShell SSH remoting, see
[Remove-PSSession](Remove-PSSession.md) [WSMan Provider](../Microsoft.WsMan.Management/About/about_WSMan_Provider.md)-
Microsoft.PowerShell.Core New Pssession (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/New-PSSession.md
Title: New-PSSession
--- # New-PSSession
-## SYNOPSIS
+## Synopsis
Creates a persistent connection to a local or remote computer.
-## SYNTAX
+## Syntax
### ComputerName (Default)
New-PSSession [-Name <String[]>] [-UseWindowsPowerShell] [<CommonParameters>]
### SSHHost ```
-New-PSSession [-Name <String[]>] [-Port <Int32>] [-HostName] <String[]> [-UserName <String>]
- [-KeyFilePath <String>] [-SSHTransport] [-Subsystem <String>] [<CommonParameters>]
+New-PSSession [-Name <String[]>] [-Port <Int32>] [-HostName] <String[]> [-UserName <String>] [-KeyFilePath <String>]
+[-SSHTransport] [-Subsystem <String>] [-ConnectingTimeout <int>] [<CommonParameters>]
``` ### SSHHostHashParam
New-PSSession [-Name <String[]>] [-Port <Int32>] [-HostName] <String[]> [-UserNa
New-PSSession [-Name <String[]>] -SSHConnection <Hashtable[]> [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `New-PSSession` cmdlet creates a PowerShell session (**PSSession**) on a local or remote computer. When you create a **PSSession**, PowerShell establishes a persistent connection to the
connection information. For more information about how to set up PowerShell SSH
> this if you are in an environment where you can be certain of the server certificate and the > network connection to the target system.
-## EXAMPLES
+## Examples
### Example 1: Create a session on the local computer
This example shows how to create multiple sessions using Secure Shell (SSH) and
contain connection information for each session. Note that this example requires that the target remote computers have SSH configured to support key based user authentication.
-## PARAMETERS
+## Parameters
### -AllowRedirection
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False ```
+### -ConnectingTimeout
+
+Specifies the amount of time in milliseconds allowed for the initial SSH connection to complete. If
+the connection doesn't complete within the specified time, an error is returned.
+
+This parameter was introduced in PowerShell 7.2
+
+```yaml
+Type: System.Int32
+Parameter Sets: SSHHost
+Aliases:
+
+Required: False
+Position: Named
+Default value: unlimited
+Accept pipeline input: False
+Accept wildcard characters: False
+```
+ ### -ConnectionUri Specifies a URI that defines the connection endpoint for the session. The URI must be fully
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-WarningAction, and -WarningVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.String, System.URI, System.Management.Automation.Runspaces.PSSession You can pipe a string, URI, or session object to this cmdlet.
-## OUTPUTS
+## Outputs
### System.Management.Automation.Runspaces.PSSession
-## NOTES
+## Notes
- This cmdlet uses the PowerShell remoting infrastructure. To use this cmdlet, the local computer and any remote computers must be configured for PowerShell remoting. For more
You can pipe a string, URI, or session object to this cmdlet.
more information about how to set up PowerShell SSH remoting, see [PowerShell Remoting Over SSH](/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core).
-## RELATED LINKS
+## Related Links
[Connect-PSSession](Connect-PSSession.md)
You can pipe a string, URI, or session object to this cmdlet.
[Receive-PSSession](Receive-PSSession.md) [Remove-PSSession](Remove-PSSession.md)-
Microsoft.PowerShell.Utility Invoke Restmethod (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Utility/Invoke-RestMethod.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 04/05/2021 Last updated : 04/20/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Invoke-RestMethod
The `Invoke-RestMethod` cmdlet sends HTTP and HTTPS requests to Representational
PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or
-deserializes, the content into objects.
+deserializes, the content into `[PSCustomObject]` objects.
+
+> [!NOTE]
+> When the REST endpoint returns multiple objects, the objects are received as an array. If you pipe
+> the output from `Invoke-RestMethod` to another command, it is sent as a single `[Object[]]`
+> object. The contents of that array are not enumerated for the next command on the pipeline.
This cmdlet is introduced in Windows PowerShell 3.0.
$headers = @{
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body ```
+### Example 6: Enumerate returned items on the pipeline
+
+GitHub returns multiple objects an array. If you pipe the output to another command, it is sent as a
+single `[Object[]]`object.
+
+To enumerate the objects into the pipeline, pipe the results to `Write-Output` or wrap the cmdlet in
+parentheses. The following example counts the number of objects returned by GitHub. Then counts the
+number of objects enumerated to the pipeline.
+
+```powershell
+$uri = 'https://api.github.com/repos/microsoftdocs/powershell-docs/issues'
+$x = 0
+Invoke-RestMethod -Uri $uri | ForEach-Object { $x++ }
+$x
+1
+
+$x = 0
+(Invoke-RestMethod -Uri $uri) | ForEach-Object { $x++ }
+$x
+30
+
+$x = 0
+Invoke-RestMethod -Uri $uri | Write-Output | ForEach-Object { $x++ }
+$x
+30
+```
+ ## Parameters ### -AllowUnencryptedAuthentication