azure-powershell
azure-powershell copied to clipboard
[ConnectedMachine] Connect-AzConnectedMachine throws if multiple sessions are used
Description
Connect-AzConnectedMachine throws errors if multiple sessions are used. This is due to how the output is being processed. This line https://github.com/Azure/azure-powershell/blob/482a460d705dd2aef9b1106c556acf363a2579cd/src/ConnectedMachine/custom/Connect-AzConnectedMachine.ps1#L244 should not process $ShowResult
but should use $_
instead.
Issue script & Debug output
$sessions = New-PSSession -ComputerName ARCDB01,ARCWB01
$DebugPreference = 'Continue'
Connect-AzConnectedMachine -ResourceGroupName ALArc -PSSession $sessions -Location 'westeurope'
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01%20ARCWB01?api-version=2022-0
3-10
DEBUG: RequestCreated: /subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01%20ARCWB01?api-version=20
22-03-10
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01 ARCWB01?api-version
=2022-03-10
Headers:
x-ms-unique-id : 8
x-ms-client-request-id : 8dd87b5c-6169-4fae-8072-5e6e5bcccc6d
CommandName : Get-AzConnectedMachine
FullCommandName : Get-AzConnectedMachine_Get
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,PSVersion/v5.1.22621.169,Az.ConnectedMachine/0.4.0
Body:
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : 90e38f89-944c-4c3d-97b9-03f639630959
x-ms-correlation-request-id : 90e38f89-944c-4c3d-97b9-03f639630959
x-ms-routing-request-id : GERMANYWESTCENTRAL:20220921T072415Z:90e38f89-944c-4c3d-97b9-03f639630959
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Cache-Control : no-cache
Date : Wed, 21 Sep 2022 07:24:15 GMT
Body:
{
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please go to https://aka.ms/AR
MResourceNotFoundFix"
}
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzConnectedMachine : The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please go to
https://aka.ms/ARMResourceNotFoundFix
At C:\Program Files\WindowsPowerShell\Modules\Az.ConnectedMachine\0.4.0\custom\Connect-AzConnectedMachine.ps1:250 char:9
+ Get-AzConnectedMachine -Name $Name -ResourceGroupName $Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ SubscriptionI...01, Expand = }:<>f__AnonymousType2`4) [Get-AzConnectedMachine_Get], Exception
+ FullyQualifiedErrorId : ResourceNotFound,Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Cmdlets.GetAzConnectedMachine_Get
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSResourceNotFoundCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.ConnectedMachine:0.4.0; CommandName: Get-AzConnectedMachine; PSVersion: 5.1.22621.169; IsSuccess: False; Duration: 00:00:00.6718266; Excep
tion: InternalException;
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01%20ARCWB01?api-version=2022-0
3-10
DEBUG: RequestCreated: /subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01%20ARCWB01?api-version=20
22-03-10
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/28b63f87-8edc-43a8-afd2-828189c80823/resourceGroups/ALArc/providers/Microsoft.HybridCompute/machines/ARCDB01 ARCWB01?api-version
=2022-03-10
Headers:
x-ms-unique-id : 9
x-ms-client-request-id : 31453cca-bba9-4cea-b29a-42382150372d
CommandName : Get-AzConnectedMachine
FullCommandName : Get-AzConnectedMachine_Get
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v0.0.0,PSVersion/v5.1.22621.169,Az.ConnectedMachine/0.4.0
Body:
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : 5bfa8cae-d63e-4bf1-bfc9-cdf36b90f488
x-ms-correlation-request-id : 5bfa8cae-d63e-4bf1-bfc9-cdf36b90f488
x-ms-routing-request-id : GERMANYWESTCENTRAL:20220921T072416Z:5bfa8cae-d63e-4bf1-bfc9-cdf36b90f488
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Cache-Control : no-cache
Date : Wed, 21 Sep 2022 07:24:15 GMT
Body:
{
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please go to https://aka.ms/AR
MResourceNotFoundFix"
}
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzConnectedMachine : The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please go to
https://aka.ms/ARMResourceNotFoundFix
At C:\Program Files\WindowsPowerShell\Modules\Az.ConnectedMachine\0.4.0\custom\Connect-AzConnectedMachine.ps1:250 char:9
+ Get-AzConnectedMachine -Name $Name -ResourceGroupName $Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ SubscriptionI...01, Expand = }:<>f__AnonymousType2`4) [Get-AzConnectedMachine_Get], Exception
+ FullyQualifiedErrorId : ResourceNotFound,Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Cmdlets.GetAzConnectedMachine_Get
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSResourceNotFoundCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.ConnectedMachine:0.4.0; CommandName: Get-AzConnectedMachine; PSVersion: 5.1.22621.169; IsSuccess: False; Duration: 00:00:00.2185318; Excep
tion: InternalException;
Environment data
This issue concerns all versions due to the way the results are processed. I reproduced the issue on:
Name Value
---- -----
PSVersion 5.1.22621.169
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.169
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
and:
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.10.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
Script 4.31.0 Az.Compute {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk...}
Script 0.4.0 Az.ConnectedMachine {Connect-AzConnectedMachine, Get-AzConnectedMachine, Get-AzConnectedMachineExtension, Get-AzConnectedPrivateL...
Script 6.2.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}
Error output
HistoryId: 15
Message : [ResourceNotFound] : The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please
go to https://aka.ms/ARMResourceNotFoundFix
StackTrace :
Exception : System.Exception
InvocationInfo : {Get-AzConnectedMachine_Get}
Line : Get-AzConnectedMachine -Name $Name -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
Position : At C:\Program Files\WindowsPowerShell\Modules\Az.ConnectedMachine\0.4.0\custom\Connect-AzConnectedMachine.ps1:250 char:9
+ Get-AzConnectedMachine -Name $Name -ResourceGroupName $Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 15
Message : [ResourceNotFound] : The Resource 'Microsoft.HybridCompute/machines/ARCDB01 ARCWB01' under resource group 'ALArc' was not found. For more details please
go to https://aka.ms/ARMResourceNotFoundFix
StackTrace :
Exception : System.Exception
InvocationInfo : {Get-AzConnectedMachine_Get}
Line : Get-AzConnectedMachine -Name $Name -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
Position : At C:\Program Files\WindowsPowerShell\Modules\Az.ConnectedMachine\0.4.0\custom\Connect-AzConnectedMachine.ps1:250 char:9
+ Get-AzConnectedMachine -Name $Name -ResourceGroupName $Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 15