2016年8月22日星期一

PowerShell Maintenance Script for Citrix Xenapp 7.6

  Function Global:Enable-MaintenanceMode([string]$groupname) {
    # Get the machine list
    $machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
    foreach ($machine in $machines)
    {
        Write-Output "$machine.MachineName : " $machine.MachineName
        set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $true
    }
}


Function Global:Disable-MaintenanceMode([string]$groupname) {
    # Get the machine list
    $machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
    foreach ($machine in $machines)
    {
        Write-Output "$machine.MachineName : " $machine.MachineName
        set-BrokerSharedDesktop $machine.MachineName -InMaintenanceMode $false
    }
}

Function Global:Logoff-AllSession([string]$groupname) {
    #Get-BrokerSession | where { $_.DesktopGroupName -eq $groupname } | Stop-BrokerSession
    Get-BrokerSession -DesktopGroupName $groupname | Stop-BrokerSession
}

Function Global:Restart-Machine([string]$groupname) {
    # Get the machine list
    $machines = @( Get-BrokerMachine -DesktopGroupName $groupname )
    foreach ($machine in $machines)
    {
        Write-Output "$machine.MachineName : " $machine.MachineName
        New-BrokerHostingPowerAction -MachineName $machine.MachineName -Action Restart
    }
}

Add-PSSnapin Citrix*

# Logoff all sessions by Delivery Group
Logoff-AllSession -groupname GROUP1

# Turn on maintenance mode by Delivery Group
Enable-MaintenanceMode -groupname GROUP1

# Turn off maintenance mode by Delivery Group
Disable-MaintenanceMode -groupname GROUP1

# Restart server by Delivery Group
Restart-Machine -groupname GROUP1

-------------------------------------------------------------
# Show all Citrix command
Get-Command -Module Citrix*

# Show help of a command
Get-Help New-BrokerHostingPowerAction -Full

沒有留言:

發佈留言