Citrix Powershell

PowerShell – While Loop

While Loop for PowerShell

I have seen loops in programming languages, SQL query and it also exists in PowerShell. If you have been reading my posts, you may recall that I was working on a Citrix migration project. The project was already done. I am now fine-tuning my script so that I can automate deploying applications for new Delivery Groups. We have a farm that contains many Delivery Groups. Each Delivery Group contain the same set of applications that are hosted on a series of VDAs that are dedicated to that country. Now that I am done copying from the old farm, I have to automate adding machines for new Delivery Groups. To do that, I decided to use a while loop.

First, I will define a variable, asking the user (in this case, myself) how many VDA there is for this new country. We have country that only has 1 VDA, and we also have country that has as many as 15 VDAs. Our VDAs are hosted on Azure. In this example, I will use the naming convention “AZUEPRDVDA01” (azure East US Production VDA 01) for the VDAs.

asnp Citrix*

$AdminAddress = #put the FQDN of your Delivery Controller here
$DeliveryGroup = #put the name of the DeliveryGroup here
$CatalogName = #put the name of the Machine Catalog here

$Catalog = Get-BrokerCatalog -AdminAddress $AdminAddress -Name $CatalogName

$VDA = Read-Host -Prompt "How many VDA are you adding?"

#While $N is less than or equal to $VDA, add new broker machine to make them available in the site.

$N = 1
        $MachineName = "Domain\AZUEPRDVDA0" + $N
        New-BrokerMachine -AdminAddress $AdminAddress -CatalogUID $Catalog.Uid $MachineName 
        N++} While ($N -le $VDA)

#While $N is less than or equal to $VDA, add new broker machine to the Delivery Group.

$N = 1
        $MachineName = "Domain\AZUEPRDVDA0" + $N
        Add-BrokerMachine -AdminAddress $AdminAddress -MachineName $MachineName -DesktopGroup $DeliveryGroup
        N++} While ($N -le $VDA)

If we enter “5” when prompt about the amount of VDA we are adding, the loop will start at 1 and go all the way to 5.


will be added to the delivery group we define as $DeliveryGroup.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s