# XenDesktop

# PowerShell Quick Commands

Every command from this collection needs to be run on one of the Delivery Controllers.

### Turn off Citrix VDI

```powershell
Add-PSSnapin citrix*
New-BrokerHostingPowerAction -Action TurnOff -MachineName <vdimachinename>
```

### Set maintenance mode

```powershell
Add-PSSnapin citrix*
Set-BrokerMachineMaintenanceMode -InputObject <domain>\<vdimachinename> $true
```

### Get VDI details by desktop group

```powershell
Add-PSSnapin citrix*
Get-BrokerDesktop -Filter {DesktopGroupName -like <vdimachinename>} -MaxRecordCount 100000 | Select-Object DesktopGroupName, MachineName, LastConnectionTime, InMaintenanceMode, @{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}}
```

### Delete old resources

```powershell
Add-PSSnapin citrix*

$oldDevices = Get-BrokerDesktop | where {$_.MachineName -like "S-*"}

Foreach($oldDevice in $oldDevices){
    Remove-BrokerMachine $olddevice.machinename -DesktopGroup $olddevice.desktopgroupname
    Remove-BrokerMachine -inputobject $olddevice.machinename -Force
}
```