Hello fellow IT industry professionals! I’m Preston K. Parsard, and I’m truly excited to bring you some awesome automation opportunities, so to start, let’s consider these scenarios:
1. Yo...
I am trying to automate logging off Disconnected users from the Windows Virtual Desktop session. i have the following code so far which executes without giving me any error:
$TenantName = "<Our-Tenant-Name"
$HostPoolName = "<Our-Hostpool-Name>"
$rdsContext = get-rdscontext -ErrorAction SilentlyContinue
if ($rdsContext -eq $null) {
try {
Write-host "Use the login window to connect to WVD" -ForegroundColor Red
Add-RdsAccount -ErrorAction Stop -DeploymentUrl "https://rdbroker.wvd.microsoft.com"
}
catch {
$ErrorMessage = $_.Exception.message
write-host ('Error logging into the WVD account ' + $ErrorMessage)
exit
}
}
Get-RdsUserSession -TenantName $TenantName -HostPoolName $HostPoolName
$AllDiscUsers = (Get-RdsUserSession -TenantName $TenantName -HostPoolName $HostPoolName | where { $_.SessionState -eq "Disconnected" }).UserPrincipalName
Foreach ($DiscUser in $AllDiscUsers)
{
Get-RdsUserSession -TenantName $TenantName -HostPoolName $HostPoolName | where { $_.UserPrincipalName -eq $DiscUser } | Invoke-RdsUserSessionLogoff -NoUserPrompt
}
It executes without any error but it is not doing what it is suppose to do. i.e. to log off disconnected users: