henrydenhengst

Reset PVD for a Desktop Group via PowerShell and WMI

Aug 20th, 2015
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $NameSpace = "ROOT\citrix"
  2. $ClassName = "Citrix_PvDPool"
  3.  
  4. # Change this value to the name of the desktop group you want to reset
  5. $DesktopGroupName = "My PVD Desktop Group"
  6.  
  7. # Add Citrix PowerShell snap-ins
  8. asnp Citrix*
  9.  
  10. Write-Host
  11. Write-Host "Preparing to reset the Personal vDisk on all VMs in Desktop Group " -nonewline; Write-Host -foregroundcolor green """$DesktopGroupName"""
  12. Write-Host
  13. Write-Host -foregroundcolor cyan "IMPORTANT" -nonewline; Write-Host " - please ensure all VMs are in a started and registered state!"
  14. Write-Host
  15.  
  16. #Insert a pause
  17. Write-Host "Press any key to continue..."
  18. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  19.  
  20. # Work out if all desktops are registered
  21. $PVDDesktopGroup = Get-BrokerDesktopGroup -name $DesktopGroupName
  22. if ($PVDDesktopGroup.DesktopsAvailable -lt $PVDDesktopGroup.TotalDesktops)
  23. {
  24. Write-Host
  25. Write-Host -foregroundcolor cyan "WARNING" -nonewline; Write-Host " - Not all desktops appear to be registered, are you sure you want to continue? If so, press any key..."
  26. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  27. }
  28.  
  29. $PVDDesktops = Get-Brokermachine -DesktopGroupName $DesktopGroupName
  30.  
  31. Write-Host
  32. Write-Host "Resetting Personal vDisks for the following machines:"
  33.  
  34. # Perform the PVD Reset via WMI
  35. foreach ($PVDDesktopsMachine in $PVDDesktops)
  36. {
  37. Write-Host $PVDDesktopsMachine.DNSName
  38. Invoke-WMIMethod -Class $classname -ComputerName $PVDDesktopsMachine.DNSName -Namespace $namespace -Name Reset
  39. }
  40.  
  41. Write-Host
  42. Write-Host "All done!"
  43. Write-Host
Advertisement
Add Comment
Please, Sign In to add comment