Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.22k stars 3.83k forks source link

You cannot pipe Get-AzWvdUserSession to Disconnect-AzWvdUserSession #21232

Closed JimMoyle closed 2 months ago

JimMoyle commented 1 year ago

Description

You should be able to do this

Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName -SessionHostName $SessionHostName | Where-Object {$_.UserPrincipalName -eq $UserName } | Disconnect-AzWvdUserSession

Pipeling could work in 2 ways neither of them work

  1. The inputobject accepts pipelining by type whereas the output object type of Get-AzWvdUserSession is Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api20210712.UserSession
  2. Associating by parameter name, this fails due to the output property of ID is an ARM Path /subscriptions//resourcegroups//providers/Microsoft.DesktopVirtualization/hostpools//sessionhosts//usersessions/ whilst the input parameter called Id expects the session number.

Also the session number is going to be an int, whereas the help for the parameter says the following:

 help disconnect-AzWvdUserSession -Parameter id

-Id <String>
    The name of the user session within the specified session host

    Required?                    true
    Position?                    named
    Default value
    Accept pipeline input?       false
    Accept wildcard characters?  false

Which is clearly denoted as a string and says the name of the user session rather than the number, this not only gives the wrong instruction, but also the wrong eror in code when pipelining is associated with the parameter

Issue script & Debug output

Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName -SessionHostName $SessionHostName | Where-Object {$_.UserPrincipalName -eq $UserName } | Disconnect-AzWvdUserSession -Debug
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing: 
DEBUG: CmdletProcessRecordStart: 

Confirm
Are you sure you want to perform this action?
Performing the operation "Disconnect-AzWvdUserSession_DisconnectViaIdentity" on target "Call remote 'UserSessionsDisconnect' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: CmdletGetPipeline: 
DEBUG: CmdletBeforeAPICall: 
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd: 
DEBUG: [CmdletException]: Received Exception with message 'Exception - Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/disconnect' :    at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.DesktopVirtualizationClient.UserSessionsDisconnectViaIdentity(String viaIdentity, Func`2 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()
   at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()'
DEBUG: CmdletException: Exception - Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/disconnect' :    at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.DesktopVirtualizationClient.UserSessionsDisconnectViaIdentity(String viaIdentity, Func`2 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()
   at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()
Disconnect-AzWvdUserSession_DisconnectViaIdentity: Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/disconnect'
DEBUG: CmdletProcessRecordEnd:

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
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.0Get-Module Az

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.11.2                Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     3.1.1                 Az.DesktopVirtualization            {Disconnect-AzWvdUserSession, Expand-AzWvdMsixImage, Get-AzWvdApplication, Get-AzWvdApplicationGroup…}

Error output

HistoryId: 44

Message        : Invalid identity for URI '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}/sessionHosts/{sessionHostName}/userSessions/{userSessionId}/disconnect'    
StackTrace     :    at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.DesktopVirtualizationClient.UserSessionsDisconnectViaIdentity(String viaIdentity, Func`2 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
                    at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()
                    at Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Cmdlets.DisconnectAzWvdUserSession_DisconnectViaIdentity.ProcessRecordAsync()
Exception      : System.Exception
InvocationInfo : {Disconnect-AzWvdUserSession_DisconnectViaIdentity}
Line           : Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName -SessionHostName $SessionHostName | Where-Object {$_.UserPrincipalName -eq $UserName } | Disconnect-AzWvdUserSession -Debug
Position       : At line:1 char:1
                 + Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostPoolN …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 44
ghost commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

alec-baird commented 2 months ago

This should be resolved in latest stable with Identity being correctly handling to allow piping. Please upgrade to latest stable API.