Trying to pipe Get-AzWvdUserSession result to Send-AzWvdUserSessionMessage, can't pass session ID...

Occasional Contributor



I'm trying to rebuild equivalent scripts that I did for fall 2019 module, but I get an issue with the send Send-AzWvdUserSessionMessage.    I want to get all sessions from a specific session host and send them a message on the screen.  The only parameter that blocks me it the session ID, it does not accept the format of the session ID variable provided by Get-AzWvdUserSession.


Here is the example:


Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostpoolName $HostPoolName -SessionHostName "" | ForEach-Object {Send-AzWvdUserSessionMessage -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName -SubscriptionId $SubscriptionID -SessionHostName $SessionHostName -UserSessionId $_.Id -MessageTitle "Watchout! YOu need to logoff in 60 secondes" -MessageBody "Good bye!  see you later"


I get the following error message: Send-AzWvdUserSessionMessage : The server responded with a Request Error, Status: NotFound...


If I manually set the session ID with only the session number (3), it work, but it becomes useless to script that.


Any idea what am I doing wrong? or if it is a bug that needs to be addressed?









2 Replies

@Patrick Brodeur It looks like you need to use just the session number at the end of that long string.


Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostpoolName $HostPoolName -SessionHostName "" | ForEach-Object {Send-AzWvdUserSessionMessage -ResourceGroupName $ResourceGroupName -HostPoolName $HostPoolName -SubscriptionId $SubscriptionID -SessionHostName $SessionHostName -UserSessionId ($_.Id -split '/')[-1] -MessageTitle "Watchout! YOu need to logoff in 60 secondes" -MessageBody "Good bye!  see you later"

@bakegreg   Thank you!  I was thinking about doing something like this to get the session number out of the string, but not very good yet at it.  I was about to study that tomorrow, but thanks you found it for me!   I'll try it and give you some news in dew days.