1

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

krapulax
  • 115
  • 2
  • 10

1 Answers1

0

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
Scepticalist
  • 3,737
  • 1
  • 13
  • 30
  • Thanks for the response...It did not seem to give the expected result (if I put it that way it is asking for connection broker and collection name for the Remove- part. I went with the workaround of removing the VDI from the collection and immediately after adding it back (Remove-RDVirtualDesktopFromCollection and Add-RDVirtualDesktopToCollection), which is not elegant, but does the job, as the VDI becomes unasigned at the end, which is my goal in this one. Thanks! – krapulax Dec 04 '20 at 16:30