To effectively manage workloads in Citrix DaaS, first, you must set up the credentials profile on a server where PowerShell SDK is installed and the required firewall communication is allowed for the Citrix DaaS URLs. Refer to my previous blog post about the firewall rules and ports required for communication with Citrix DaaS - Guidelines for Migration from CVAD on Prem to Citrix DAAS – Control Layer (Part1)
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Script to create credential profile on the server
Note- Before you run through this script block, Generate your Client ID and Secret in your DaaS Tenant referencing the article - Generating the customer ID, client ID, and secret key
# Script to setup Citrix Cloud credential profile
asnp Citrix*
$secureClientProd = “D:\Temp\secureclient.csv"
$xdCredsProd = import-csv $secureClientProd
# Set prod profile using your client ID and Secret
Set-XDCredentials -CustomerId $xdCredsProd.CustomerId -SecureClientFile $secureClientProd -ProfileType CloudAPI –StoreAs "XDCloudPRD"
# Set Default profile using your client ID and Secret
Set-XDCredentials -CustomerId $xdCredsProd.CustomerId -SecureClientFile $secureClientProd -ProfileType CloudAPI –StoreAs "Default"
# List profiles
Get-XDCredentials -ListProfile
# Load credentials
Get-XDCredentials -ProfileName "Default"
#Set Credentials
Set-XDCredentials -ProfileName “Default”
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Once the credentials are loaded in the profile, all the respective Site operations could be performed within the PowerShell console.
All you need is below commands before every command or script you would execute within the powershell to manage your DaaS workloads.
Add-PSSnapin Citrix*
Set-XDCredentials -ProfileName “Default”
++++++++++++++++++++++++++++++++++++++++++++++++++++++
In this blog post, I would like to provide quick references to some commonly used PowerShell commands for Citrix Site configuration with some examples, which would be useful for system admins in managing and maintaining console operations effectively.
Get-BrokerDesktopGroup
Example 1
Get-BrokerDesktopGroup | select DesktopGroupName,DesktopKind,AutoscalingEnabled
DesktopGroupName DesktopKind AutoscalingEnabled
---------------- ----------- ------------------
az_z1_mcs_dg1 Private False
az_z1_mcs_dg2 Private False
az_z1_pvs_dg1 Shared False
Example 2
Get-BrokerDesktopGroup | Where-Object {$_.DesktopKind -like "private"} | select DesktopGroupName,DesktopKind,AutoscalingEnabled | Sort-Object desktopgroupname
DesktopGroupName DesktopKind AutoscalingEnabled
---------------- ----------- ------------------
az_z1_mcs_dg1 Private False
az_z1_mcs_dg2 Private False
The above command will display the list of DesktopgroupName with DesktopKind as Private.
Example 3
Get-BrokerDesktopGroup | Where-Object {$_.DesktopKind -like "shared"} | select DesktopGroupName,DesktopKind,AutoscalingEnabled | Sort-Object desktopgroupname
DesktopGroupName DesktopKind AutoscalingEnabled
---------------- ----------- ------------------
az_z1_pvs_dg1 Shared False
The above command will display the list of DesktopgroupName with DesktopKind as Shared.
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get-BrokerCatalog
Example 1
This command displays the list of all the catalog names available in the site database.
Get-BrokerCatalog | Select CatalogName,AvailableCount,ProvisioningType
CatalogName AvailableCount ProvisioningType
----------- -------------- ----------------
az_z1_mcs_pooled_mc1 0 MCS
az_z1_mcs_pooled_mc2 0 MCS
az_z1_mcs_manual_mc1 0 Manual
Example 2
This command displays the list of all the catalog names with provisioning type MCS
Get-BrokerCatalog | Where-Object {$_.ProvisioningType -like "MCS"} | select CatalogName,ProvisioningType,AvailableCount
CatalogName ProvisioningType AvailableCount
----------- -------------- ----------------
az_z1_mcs_pooled_mc1 MCS 5
az_z1_mcs_pooled_mc2 MCS 10
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get-ProvScheme
Example 1
Get-ProvScheme | Where-Object {$_.ProvisioningSchemeName -like "*XenApp*"} | select ProvisioningSchemeName,HostingUnitName,DiskSize,MasterImageVM
ProvisioningSchemeName HostingUnitName DiskSize MasterImageVM
---------------------- --------------- -------- -------------
QA_XenApp_Server_2019 XenDesktop_VALN1 100 XDHyp:\HostingUnits\XenDesktop_VLAN1-\2019MCSMASTER.vm\XenApp_2019_11_15_2022.snapshot
QA_XenApp_Server_2019_Cache XenApp_VLAN1 100 XDHyp:\HostingUnits\XenApp_VLAN1\2019MCSMASTERold.vm\XenApp_2019_11_15_2022.snapshot
Displays the list of the provisioning schemes set up on your site with the MasterImageVM details. This command function is pretty much customizable as per the requirement and could be easily scheduled on the server to maintain reporting for your provisioning scheme locally for management.
++++++++++++++++++++++++++++++++++++++++++++++++++++
Set-ProvScheme
This command lets you perform the image updates on the catalog to reference the specific master image VM and snapshot. All you would require is the master image VM name and the snapshot.
Set-ProvScheme -ProvisioningSchemeName 'ABCTest' -MachineProfile "XDHyp:\HostingUnits\AwsHostingUnit\us-east-1a.availabilityzone\machine-profile-vm (i-00c55f1107b662c04).vm"
Note: Previously, this command looked for a parameter named MasterImageVM, which is now replaced with MachineProfile in DaaS.
For On-Prem Hypervisor connections, you could use the MasterImageVM parameter instead of the MachineProfile
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get-BrokerMachine & Set-BrokerMachine
Example 1
The below command will let you display the list of machine names with ‘abc’ in their machine name. Output below for reference:
Get-BrokerMachine -MaxRecordCount 9999999 | Where-Object {$_.MachineName -match "*abc*"} | Select @{Name='UserID';Expression={($_.AssociatedUserNames)}},@{name='UserName';Expression={$_.AssociatedUserFullNames}},DNSName
UserID UserName DNSName
------ -------- -------
Domain\udjajoo1 Jajoo, Uddave machine1.udjajoo.com
Example 2
Get-BrokerMachine -MaxRecordCount 9999999 | Where-Object {$_.DesktopKind -like "Private"} | Select @{Name='UserID';Expression={($_.AssociatedUserNames)}},@{name='UserName';Expression={$_.AssociatedUserFullNames}},DNSName
The above command will display the list of machine names with desktop kind private assigned with their username and UPN address. Output below for reference:
UserID UserName DNSName
------ -------- -------
Domain\udjajoo1 Jajoo Uddave 1 machine0001.udjajoo.com
Domain\udjajoo2 Jajoo Uddave 2 machine0002.udjajoo.com
Example 3
Get-BrokerMachine -MaxRecordCount 9999999 | ?{$_.MachineName -like "*abc*"} | Select MachineName,RegistrationState,InMaintenanceMode,PowerState | Set-BrokerMachine -InMaintenanceMode $true
This command will let you perform the maintenance mode operations on multiple machines simultaneously, based on the output of machines generated, it will then process the maintenance mode for all the machines and set it to True. Output below for reference:-
MachineName RegistrationState InMaintenanceMode PowerState
----------- ----------------- ----------------- ----------
domain\machine0001 Registered True On
domain\machine0002 Registered True On
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get_BrokerHostingPowerAction
Example
Get-BrokerHostingPowerAction -MaxRecordCount 999999 | ?{$_.MachineName -like '*xyz*'} | Select MachineName,Action,ActionCompletionTime
Using this command you would be easily able to identify the power action completion time for the respective machines which contains character “xyz” in the name specified and then using the pipeline variable can trigger it to perform the required hosting power action TurnOn, Restart, Shutdown. Output below for reference:-
MachineName Action ActionCompletionTime
----------- ------ --------------------
Domain\machine0001 TurnOn 10/12/2024 4:01:39 PM
Domain\machine0002 TurnOn 10/12/2024 4:32:12 PM
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get-BrokerApplication
Example 1
Get-BrokerApplication | Select ApplicationName,AssociatedUserNames,BrowserName
ApplicationName AdminFolderName AssociatedUserNames
--------------- ------------------- -------------------
Acrobat Reader Adobe {Jajoo, Uddave}
Excel Office {Jajoo, Uddave}
Chrome Google {Jajoo, Uddave}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Below is a script that could be used for reporting purposes to get the list of Applications running in your environment with all the properties listed in CSV format.
<#
This script could be used in any environment hosting Citrix DaaS Site
Execute using Scheduled task or directly in PowerShell command prompt with Admin privileges
How to run: C:\Windows\System32>.\ApplicationReport.ps1
Caution- Review the script thoroughly before running in any production environments.
#>
#==============================START===================================#
Add-PSSnapin citrix*
Get-XDAuthentication -ProfileName <Cloud site authentication profile>
$Site = (get-BrokerSite).Name
$Report = @()
$Folder = "c:\temp\"
$Date = get-date -uformat "%m%d%Y"
$csvfilename = "AppReport_$Site.csv"
$outpath = $Folder+$csvfilename
$apps = Get-BrokerApplication -MaxRecordCount 2147483647
foreach($app in $apps)
{
$AdminFolderName = $app.AdminFolderName
$FolderName = $AdminFolderName.Split('\')[0]
$ApplicationName = $app.ApplicationName
$ApplicationType = $app.ApplicationType
$AssociatedUserNames = $app.AssociatedUserNames
$ClientFolder = $app.ClientFolder
$CommandLineArguments = $app.CommandLineArguments
$CommandLineExecutable = $app.CommandLineExecutable
$Description = $app.Description
$Enabled = $app.Enabled
$DGUid = $app.AllAssociatedDesktopGroupUids
$DGName = (Get-BrokerDesktopGroup -uid "$DGUid").Name
#$AGUid = $app.AssociatedApplicationGroupUids
#$AGName = (Get-BrokerApplicationGroup -uid "$AGUid").Name
$PublishedName = $app.PublishedName
$Servers=Get-BrokerMachine -AdminAddress $DC -MaxRecordCount 2147483647 | Where-Object {$_.DesktopGroupName -eq "$DGName"}
$ServerName = $servers.DNSName
$server = $ServerName.Split(' ')[0]
$MC=Get-BrokerMachine -AdminAddress $DC -DNSName $server
$MCName = $MC.CatalogName
$UserFilterEnabled = $app.UserFilterEnabled
$Visible = $app.Visible
$Tags = $app.Tags
$WorkingDirectory = $app.WorkingDirectory
$MaxPerUserInstances = $app.MaxPerUserInstances
if ($MaxPerUserInstances -eq "0") {$MIPUA = "Unlimited"}
if ($MaxPerUserInstances -ne "0") {$MIPUA = $MaxPerUserInstances}
$MaxTotalInstances = $app.MaxTotalInstances
if ($MaxTotalInstances -eq "0") {$MaxTotalInstances = "Unlimited"}
# $Name = $app.Name
$report += {$PublishedName,$ApplicationName,$Site,$ApplicationType,$Description,$UserFilterEnabled,$AssociatedUserNames,$CommandLineExecutable,$CommandLineArguments,
$WorkingDirectory,$AdminFolderName,$ClientFolder,$MaxTotalInstances,$Enabled,$ServerName,$MCName,$DGName,$Tags} |
Select-Object @{n='ApplicationName';e={$ApplicationName}},@{n='PublishedName';e={$PublishedName}},@{n='FarmName';e={$Site}},
@{n='ApplicationType';e={$ApplicationType}},@{n='Description';e={$Description}}, @{n='UserFilterEnabled';e={$UserFilterEnabled}},@{n='UserAccounts';e={$AssociatedUserNames}}, @{n='CommandLineExecutable';e={$CommandLineExecutable}},@{n='CommandLineArguments';e={$CommandLineArguments}},
{n='WorkingDirectory';e={$WorkingDirectory}},@{n='ContentAddress';e={$Null}}, @{n='AdminFolderName';e={$AdminFolderName}},@{n='ClientFolder';e={$ClientFolder}}, @{n='InstanceLimit';e={$MaxTotalInstances}},@{n='MultipleInstancesPerUserAllowed';e={$MIPUA}}, @{n='Enabled';e={$Enabled}},@{n='EncryptionLevel';e={$Null}},@{n='ServerNames';e={$ServerName}},@{n='MachineCatalog';e={$MCName}},
@{n='DeliveryGroup';e={$DGName}},@{n='ApplicationGroup';e={$Null}},@{n='Tags';e={$Tags}},@{n='ReportTime'; e={$Time}}
}
$report | Export-Csv $outpath -NoTypeInformation
#===================================END================================#
Reference Links
https://developer-docs.citrix.com/en-us/citrix-virtual-apps-desktops-sdk/2407/
https://developer-docs.citrix.com/en-us/citrix-daas-sdk/sdkproxy/set-xdcredentials
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now