Forum Discussion

PatBrodeur's avatar
PatBrodeur
Copper Contributor
May 20, 2020

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

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:

 

Get-AzWvdUserSession -ResourceGroupName $ResourceGroupName -HostpoolName $HostPoolName -SessionHostName "PoolTest1vm-0.solulan.int" | 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?

 

Thanks!

 

 

 

 

 

 

  • bakegreg's avatar
    bakegreg
    Copper Contributor

    PatBrodeur 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 "PoolTest1vm-0.solulan.int" | 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"
    }
    • PatBrodeur's avatar
      PatBrodeur
      Copper Contributor

      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.

      • AshishKumarGupta's avatar
        AshishKumarGupta
        Copper Contributor

        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'
        }
        }
        }
        }

Resources