Script to Resize Citrix AppDisk on vSphere

I wrote this script to resize Citrix AppDisks which are running on vSphere.

The script finds the vCenter address and datastore that the AppDisk is located on, connects to vCenter and increases the size.

You need to have the XenApp / XenDesktop PowerShell cmdlets and Power CLI installed.

Disclaimer: Use this script at your own risk. All scripts should be tested on non-Production environments first.

We don’t have a code signing certificate yet so both script are available as .txt and .ps1 unsigned.

[download id=”2935″]

[download id=”2933″]

<# .SYNOPSIS Resizes Citrix AppDisk Running on VMware vSphere. .DESCRIPTION Script resizes a Citrix AppDisk running on vSphere. The script will query the AppDisk to get the vCenter address and connect to that address to resize the disk Script uses XenDesktop P VMware vCenter and Power CLI. .PARAMETER AppDiskName Name of the AppDisk to be renamed .PARAMETER NewAppDiskSize The new size of the AppDisk .PARAMETER vCenterUserName Username of an account with permission to connect to vCenter and resize the disk .PARAMETER vCenterPassword Password of the account to connect to vCenter. .PARAMETER AdminAddress Address of a XenApp / XenDesktop Controller being .EXAMPLE PS C:\Scripts > .\Citrix_AppDisk_Resize.ps -AppDiskName Finance -NewAppDiskSize 30 -vCenterUserName admin -vCenterPassword vmwarepassword -AdminAddress XDController1.domain.com
-Path \\IREALVFIL001\XenAppScaling

Resize AppDisk called finance to 30GB

Connect to XenDesktop / XenApp controller on address XDController1.domain.com
.INPUTS
None. You cannot pipe objects to this script.
.OUTPUTS
No objects are output from this script. This script creates a its own logs files
.LINK

.NOTES
NAME: Resize_Citrix_AppDisk_V1.0.ps1
VERSION: 1.00
AUTHOR: Shaun Ritchie
shaun.ritchie@euc.consulting
https://merazuppdwebwordpress01.azurewebsites.net

The script must be executed using an account which has permissions to query the XenApp / XenDesktop farm
#>

[CmdletBinding(SupportsShouldProcess = $false, ConfirmImpact = “None”, DefaultParameterSetName = “”) ]

Param ([parameter(Mandatory=$true)]
[Alias(“AD”)]
[ValidateNotNullOrEmpty()]
[String]$AppDiskName=””,

[parameter(Mandatory=$true)]
[Alias(“NewAD”)]
[ValidateNotNullOrEmpty()]
[Int]$NewAppDiskSize=””,

[parameter(Mandatory=$true)]
[Alias(“User”)]
[ValidateNotNullOrEmpty()]
[String]$vCenterUserName=””,

[parameter(Mandatory=$true)]
[Alias(“Pass”)]
[ValidateNotNullOrEmpty()]
[String]$vCenterPassword=””,

[parameter(Mandatory=$false)]
[Alias(“Address”)]
[ValidateNotNullOrEmpty()]
[String]$AdminAddress=”localhost”

)

$modules = ‘Citrix.AppLibrary.Admin.V1′,’Citrix.Broker.Admin.V2′,’ Citrix.Host.Admin.V2′,’VMware.VimAutomation.Core’

foreach ($module in $modules)
{
If (!(Get-PSSnapin $module -ErrorAction SilentlyContinue))
{
Add-PSSnapin $module -ErrorAction SilentlyContinue
}
}

# Get Citrix AppDisk

$appLibAppDisk = Get-AppLibAppDisk -AppDiskName $appDiskName -AdminAddress $AdminAddress

# Get the vSphere datastore specific to where the AppDisk is located

$dataStore = Get-ChildItem ‘XDHyp:\HostingUnits’ | Where-Object {$_.HostingUnitUid -eq $appLibAppDisk.HostingUnitUid.Guid}
$dataStore = [regex]::match($dataStore.Storage[0].StoragePath,'(?<=cluster\\).+(?=.storage)’)

# Get vCenter address specific to the AppDisk

$vCenterAddress = Get-ChildItem ‘XDHyp:\Connections’ | Where-Object {$_.HypervisorConnectionUid -eq $appLibAppDisk.HypervisorConnectionUid.Guid}
$vCenterAddress = [regex]::match($vCenterAddress.HypervisorAddress,'(?<=//).+(?=/sdk)’)

# Connect to vCenter

Connect-VIServer -Server $vCenterAddress.Value -User $vCenterUserName -Password $vCenterPassword -Force | Out-Null

# Get the vmdk and resize

Get-HardDisk -Datastore $dataStore.Value | Where-Object {$_.Filename -like (“*” + $appLibAppDisk.VirtualDiskId.Guid.ToString() + “*”)} | Set-HardDisk -CapacityGB $newAppDiskSize -Confirm:$false | Out-Null

# Query the newly resized vmdk

$hardDisk = Get-HardDisk -Datastore $dataStore.Value | Where-Object {$_.Filename -like (“*” + $appLibAppDisk.VirtualDiskId.Guid.ToString() + “*”)}
$hardDiskNewSize = $hardDisk.CapacityGB

# Write size of new vmdk

Write-Host `r`n “Appdisk is now resized to $hardDiskNewSize GBs”
Write-Host `r`n

Book a free consultation
and discuss your IT challenges with us