May 19 2020 07:39 PM
Hi,
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:
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?
Thanks!
May 27 2020 09:27 AM
@Patrick Brodeur It looks like you need to use just the session number at the end of that long string.
May 27 2020 10:17 AM
@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.
May 24 2021 10:51 AM
Please try below code:
$HSessionHosts = (Get-AzWvdSessionHost -ResourceGroupName WVD2-RG -HostPoolName WVD2HOSTPOOL | Where-object -Property AllowNewSession -eq $true).Name
foreach ($HSessionHost in $HSessionHosts) {
$HSessionDetail = $HSessionHost.split("/")
$HSessionIDs = (Get-AzWvdUserSession -ResourceGroupName WVD2-RG -HostPoolName WVD2HOSTPOOL -SessionHostName $HSessionDetail[1]).name
if ($HSessionIDs -ne $null)
{
foreach ($HSessionID in $HSessionIDs)
{
if ($HSessionID -ne $null)
{
$SplitHSessionID = $HSessionID.split("/").split("/")
Send-AzWvdUserSessionMessage -ResourceGroupName WVD2-RG -HostPoolName $SplitHSessionID[0] -SessionHostName $SplitHSessionID[1] -UserSessionId $SplitHSessionID[2] -MessageBody 'Dear User, Save your Work! the System will power-off at 07:00 pm' -MessageTitle 'System Alert'
}
}
}
}