Citrix maintenance mode via PowerShell

This is a task you will have likely carried out, on a regular basis during your day to day Citrix farm administration. You have Citrix VDA machines that you need to put in maintenance mod. Maybe it’s one machine, maybe it’s a dozen. The reasons can be to carry out maintenance, or upgrades. Whatever the reason, yes you can do it via Studio, but what about PowerShell?

Of course you can do it via PowerShell too! If you’re like me and more interested in getting comfortable with PowerShell then here’s a little note on how to put machines in maintenance mode via PowerShell with a few example scenarios.

Firstly, launch PowerShell either via studio or by running Add-PSSnapin Citrix.* within your PowerShell console.

Machines used in scenarios:

  1. CitrixDesktop1
  2. CitrixDesktop2
  3. CitrixDesktop3

Scenario 1 – Put CitrixDesktop1 in to maintenance mode

  1. Set-BrokerMachineMaintenanceMode -InputObject DOMAIN\CitrixDesktop1 $true
  2. Get-BrokerMachine -MachineName DOMAIN\CitrixDesktop1 | fl InMaintenanceMode

The first command sets the machine in maintenance mode. The second queries for the end result.

1

Scenario 2 – Put CitrixDesktop1 and CitrixDesktop2 in to maintenance mode

  1. Set-BrokerMachineMaintenanceMode -InputObject DOMAIN\CitrixDesktop1, DOMAIN\CitrixDesktop2 $true

Scenario 3 – Put all three machines in to maintenance mode

  1. $machines = Get-BrokerMachine -MachineName DOMAIN\CitrixDesktop*
  2. Set-BrokerMachineMaintenanceMode -InputObject $machins $true

The first command gets a list of machines with CitrixDesktop in their name. The second puts them in to maintenance mode.


4 Comments

  • SunilKumar Botu

    June 9, 2017

    Thanks but how do I put multiple machines with different names in a delivery group. I cant use wild card. thanks in advance. I am looking to give machine list as input file and run a loop.

    Reply
    • George Spiers

      June 9, 2017

      $machines = Get-Content C:\MachineList.txt
      foreach ($machine in $machines) {
      Add-BrokerMachine “DOMAINNAME\$machine” -DesktopGroup “DeliveryGroupName”
      }

      Reply
  • Santosh Kumar

    October 27, 2017

    How do you send a message to all the connected users using PowerShell script? If the names of the machines are different.

    Reply
    • George Spiers

      October 27, 2017

      Are you using server based hosts or VDI desktops? You know Restart Schedules via Studio can send notifications for you?

      Reply

Leave a Reply