Citrix Delivery Groups Power Plan Management – Powershell Script
Usually customers whom invest in VDI want to save on consumption whenever its possible, in terms of power management the user VDI VMs shouldn’t be up and running 24/7 they should be shutdown after working hours and then readied at the beginning of the business day.
In the case of PVS, the default behavior is that any VDA will shutdown upon user logoff, even if we set “ShutdownDesktopsAfterUse” to false the situation remains the same and it seems that this Desktop Group parameter only works with MCS provisioned virtual machines.
Long story short, I did a lot of testing in my lab and I have come with a mechanism to have a proper power plan a long with the capability of keeping my VDA’s up and running within working hours even if a user signs out of the VDA.
This is the series of the Powershell commands that I have used:
- Set-BrokerDesktopGroup -Name <DGNAME> -AutomaticPowerOnForAssigned $True -AutomaticPowerOnForAssignedDuringPeak $False -PeakBufferSizePercent 100 -ShutdownDesktopsAfterUse $False
- Get-BrokerPowerTimeScheme and Remove-BrokerPowerTimeScheme for the default created power plans.
- New-BrokerPowerTimeScheme -Name “DGNAME” -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday,Saturday -PeakHours ( 0..23 | %{ $_ -lt 7 -and $_ -gt 19 } ) -DesktopGroupUid <UID>
Since the project that I was involved it had a lot of delivery groups with different power plans for each, I wrote a little PowerShell script to facilitate the power plan management process.
# Citrix Delivery Group Power Management Script # # Created by Abdullah Abdullah | http://notes.doodzzz.net | @do0dzZZ # # Date of creation 05/02/2016 at 01:00AM # Write-Host "Adding Citrix Powershell SDK Modules!" Add-PSSnapin Citrix* function CDGPPC_menu_list { Clear-Host Write-Host "╔════════════════════════════════════════════====╗" Write-Host "║====Citrix Delivery Group Power Plan Config=====║" -BackgroundColor Yellow -ForegroundColor Black Write-Host "╠════════════════════════════════════════════====╣" Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ 1.List Current Delivery Groups ║" -BackgroundColor Black -ForegroundColor White Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ 2.Configure Power Parameters ║" -BackgroundColor Black -ForegroundColor White Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ 3.Remove Default Power Scheme ║" -BackgroundColor Black -ForegroundColor White Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ 4.Create new Power Scheme ║" -BackgroundColor Black -ForegroundColor White Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ 5.Remove new Power Scheme ║" -BackgroundColor Black -ForegroundColor White Write-Host "╠════════════════════════════════════════════====╣" Write-Host "╠════════════════════════════════════════════====╣" Write-Host "║ q.I am done, all power regulated! (Quit) ║" -BackgroundColor Yellow -ForegroundColor Black Write-Host "╚════════════════════════════════════════════====╝" } do { CDGPPC_menu_list $input = Read-Host "What would you have me do?" switch ($input) { '1' { Clear-Host '[:: List Current Delivery Groups ::]' Get-BrokerDesktopGroup | ft Name, uid } '2' { Clear-Host '[:: Configure Power Parameters ::]' Get-BrokerDesktopGroup | ft Name, uid $DGName = Read-Host "Please provide the Delivery Group Name:" Set-BrokerDesktopGroup -Name $DGName -AutomaticPowerOnForAssigned $True -AutomaticPowerOnForAssignedDuringPeak $False -PeakBufferSizePercent 100 -ShutdownDesktopsAfterUse $False Write-Host "AutomaticPowerOnForAssigned set to True" Write-Host "AutomaticPowerOnForAssignedDuringPeak set to False" Write-Host "PeakBufferSizePercent set to 100" Write-Host "ShutdownDesktopsAfterUse set to False" } '3' { Clear-Host '[:: Remove Delivery Group Default Power Scheme ::]' Get-BrokerDesktopGroup | ft Name, uid $DGName = Read-Host "Please provide the Delivery Group Name:" Remove-BrokerPowerTimeScheme -Name $DGName'_Weekdays' Remove-BrokerPowerTimeScheme -Name $DGName'_Weekend' Write-Host "Power Time Schemes $DGName'_Weekdays' and $DGName'_Weekdend' removed" } '4' { Clear-Host '[:: Create new Power Scheme ::]' Get-BrokerDesktopGroup | ft Name, uid $DGName = Read-Host "Please provide the Delivery Group Name:" $DGUid = Read-Host "Please provide the Delivery Group Uid:" $t1 = Read-Host "Machines should be ready at (time in 24 hours):" $t2 = Read-Host "Machines should rest at (time in 24 hours):" New-BrokerPowerTimeScheme -Name $DGName"_PowerPlan" -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday,Saturday -PeakHours ( 0..23 | %{ $_ -gt $t1 -and $_ -lt $t2} ) -DesktopGroupUid $DGUid Write-Host "Power Time Scheme created successfully!" } '5' { Clear-Host '[:: Remove new Power Scheme ::]' Get-BrokerPowerTimeScheme | ft Name $BPTS = Read-Host "Please provide the name of the power time scheme you wish to delete:" Remove-BrokerPowerTimeScheme -Name $BPTS Write-Host "Power Time Scheme $BPTS deleted successfully!" } 'q' { return } } pause } until ($input -eq 'q')</pre> <pre>
The script’s functionality is straight forwards and does the required job,
where you can delete the default power plan scheme and then create a new one of your own. One thing you should take into consideration is that I have chosen to include Saturdays in my plan because we do work on Saturdays here in Lebanon, please feel free to adjust the power plan criteria however you see fit for your environment.
Hopefully this will be of aid to someone and thank you for taking the time to read this,
(Abdullah)^2