Failed to remove VDI assignment

249 views Asked by At

I am working on a script which deals with leavers, and as part of it, it should remove the Virtual Desktop Assignment of the user. The script is executed from a remote server, and in this part it should "ask" the connection broker server to remove the assignment of the user.

I made sure that all the parameters are the same, and Get-RDPersonalVirtualDesktopAssignment shows the test user has a vdi assigned. But Remove-RDPersonalVirtualDesktopAssignment in turn tells me : "Remove-RDPersonalVirtualDesktopAssignment : User is not assigned any personal virtual desktop in this collection."

Any thoughts on what am I missing here would be much appreciated, as it is driving me nuts :(

Clear-Host

Import-Module RemoteDesktop
$cb = "<connectionBrokerServer>
$colection = "<collectionName>"
$user = "<DOMAIN\User>"

Write-Host -ForegroundColor Cyan "Locating VDI assignment for $user"
Get-RDPersonalVirtualDesktopAssignment -ConnectionBroker $cb `
-CollectionName (Get-RDVirtualDesktopCollection $colection -ConnectionBroker $cb).CollectionName `
-User $user 

Write-Host -ForegroundColor Cyan "Removing VDI assignment of $user"
Remove-RDPersonalVirtualDesktopAssignment -ConnectionBroker $cb `
-CollectionName (Get-RDVirtualDesktopCollection $colection -ConnectionBroker $cb).CollectionName `
-User $user `
-WhatIf

Script result

1

There are 1 answers

1
Scepticalist On

I don't use this so can't test myself, but will it allow you to pipe the "Get" result to the remove command? e.g.

Write-Host -ForegroundColor Cyan "Locating VDI assignment for $user"
$CurrentAssignment = Get-RDPersonalVirtualDesktopAssignment -ConnectionBroker $cb `
-CollectionName (Get-RDVirtualDesktopCollection $colection -ConnectionBroker $cb).CollectionName `
-User $user 
Write-Host $CurrentAssignment

Write-Host -ForegroundColor Cyan "Removing VDI assignment of $user"
$CurrentAssignment | Remove-RDPersonalVirtualDesktopAssignment -WhatIf