Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -Version 4.0
- <#
- Written by David Ott
- This script is to run on a Provisioning server running v7.12+ (might work on lower, but tested on 7.12).
- Use this for reference and installing the pvs module if needed:
- https://docs.citrix.com/content/dam/docs/en-us/provisioning-services/7-12/downloads/PvsSnapInCommands_7_12.pdf
- Search for and pay attention to any comments marked with #####
- #>
- ##### Function that checks with the delivery controller, and reboots the pvs machine if there is no session
- function check($m) {
- ##### Make sure you have powershell remoting enabled on your delivery controller
- $return = Invoke-Command -ComputerName $deliverycontroller -ScriptBlock {
- $c = $args[0]
- asnp citrix*
- $comp = get-brokerdesktop -machinename "*$c"
- if ($comp.SummaryState -ne "InUse") {
- "Restarting "+$comp.machinename
- Get-BrokerMachine -MachineName "*$c" | New-BrokerHostingPowerAction -Action Restart | Out-Null
- } else {
- "Unable to restart "+$comp.machinename+" due to active session(s)"
- }
- } -ArgumentList $m
- $return
- }
- ##### Script starts here!
- ##### load the PVS module
- ipmo 'C:\Program Files\Citrix\Provisioning Services Console\Citrix.PVS.SnapIn.dll'
- $deliverycontroller = "deliverycontrollername" ##### put your delivery controller name between the quotes
- $collections = Get-PvsCollection | select CollectionName,CollectionId
- ##### Will output to out-gridview for selection - select the collection and hit ok
- $selectedcollection = $collections | Out-GridView -OutputMode Single -Title "Select the Collection you want to update"
- if (!($selectedcollection)) {break} ##### ends if you don't select a collection
- $devices = Get-PvsDeviceInfo -CollectionId $selectedcollection.CollectionId | ?{$_.active -eq $true -and $_.DiskVersionAccess -ne "1"} | select DeviceName,DiskLocatorId,DiskFileName | sort DeviceName <##### get devices in the collection
- which are powered on, and not allowed to access the maintenance version of vdisks #####>
- <##### runs through each device in the collection. checks for the latest production (or override) version of the vdisk
- if the device is not running the latest version of the vdisk (or override) it will pass the computer name to the "check" function
- #####>
- foreach ($device in $devices) {
- $diskver = Get-PvsDiskVersion -DiskLocatorId $device.DiskLocatorId | ?{$_.CanPromote -eq $false} | select version,DiskFileName,CanOverride
- if ($diskver.canoverride -contains $false) {
- $latest = ($diskver | ?{$_.canoverride -eq $false}).diskfilename
- } else {
- $latest = ($diskver | ?{$_.version -eq ($diskver.version | measure -Maximum).maximum}).diskfilename
- }
- if ($device.DiskFileName -ne $latest) {
- $message = $device.DeviceName+" is not using the latest vDisk version! Checking for active session."
- Write-Host $message -f Red
- check -m $device.DeviceName
- } else {
- $message = $device.DeviceName+" is on the latest vdisk version"
- Write-Host $message -f Green
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement