SHARE
TWEET

PVS Collection vDisk Update

david62277 Mar 31st, 2017 (edited) 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -Version 4.0
  2. <#
  3. Written by David Ott
  4. This script is to run on a Provisioning server running v7.12+ (might work on lower, but tested on 7.12).
  5. Use this for reference and installing the pvs module if needed:
  6. https://docs.citrix.com/content/dam/docs/en-us/provisioning-services/7-12/downloads/PvsSnapInCommands_7_12.pdf
  7. Search for and pay attention to any comments marked with #####
  8. #>
  9. ##### Function that checks with the delivery controller, and reboots the pvs machine if there is no session
  10. function check($m) {
  11. ##### Make sure you have powershell remoting enabled on your delivery controller
  12. $return = Invoke-Command -ComputerName $deliverycontroller -ScriptBlock {
  13. $c = $args[0]
  14. asnp citrix*
  15. $comp = get-brokerdesktop -machinename "*$c"
  16. if ($comp.SummaryState -ne "InUse") {
  17. "Restarting "+$comp.machinename
  18. Get-BrokerMachine -MachineName "*$c" | New-BrokerHostingPowerAction -Action Restart | Out-Null
  19. } else {
  20. "Unable to restart "+$comp.machinename+" due to active session(s)"
  21. }
  22. } -ArgumentList $m
  23. $return
  24. }
  25. ##### Script starts here!
  26. ##### load the PVS module
  27. ipmo 'C:\Program Files\Citrix\Provisioning Services Console\Citrix.PVS.SnapIn.dll'
  28. $deliverycontroller = "deliverycontrollername" ##### put your delivery controller name between the quotes
  29. $collections = Get-PvsCollection | select CollectionName,CollectionId
  30. ##### Will output to out-gridview for selection - select the collection and hit ok
  31. $selectedcollection = $collections | Out-GridView -OutputMode Single -Title "Select the Collection you want to update"
  32. if (!($selectedcollection)) {break} ##### ends if you don't select a collection
  33. $devices = Get-PvsDeviceInfo -CollectionId $selectedcollection.CollectionId | ?{$_.active -eq $true -and $_.DiskVersionAccess -ne "1"} | select DeviceName,DiskLocatorId,DiskFileName | sort DeviceName <##### get devices in the collection
  34. which are powered on, and not allowed to access the maintenance version of vdisks #####>
  35.  
  36. <##### runs through each device in the collection.  checks for the latest production (or override) version of the vdisk
  37. if the device is not running the latest version of the vdisk (or override) it will pass the computer name to the "check" function
  38. #####>
  39. foreach ($device in $devices) {
  40. $diskver = Get-PvsDiskVersion -DiskLocatorId $device.DiskLocatorId | ?{$_.CanPromote -eq $false} | select version,DiskFileName,CanOverride
  41. if ($diskver.canoverride -contains $false) {
  42. $latest = ($diskver | ?{$_.canoverride -eq $false}).diskfilename
  43. } else {
  44. $latest = ($diskver | ?{$_.version -eq ($diskver.version | measure -Maximum).maximum}).diskfilename
  45. }
  46. if ($device.DiskFileName -ne $latest) {
  47. $message = $device.DeviceName+" is not using the latest vDisk version!  Checking for active session."
  48. Write-Host $message -f Red
  49. check -m $device.DeviceName
  50. } else {
  51. $message = $device.DeviceName+" is on the latest vdisk version"
  52. Write-Host $message -f Green
  53. }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top