Forum Discussion
Trying to pipe Get-AzWvdUserSession result to Send-AzWvdUserSessionMessage, can't pass session ID...
PatBrodeur It looks like you need to use just the session number at the end of that long string.
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.
- AshishKumarGuptaMay 24, 2021Copper 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'
}
}
}
}