Here’s a quick list of Powershell commands I find myself using frequently. I’ll keep this updated.
Get a list of all brokered connections
[code language=”powershell”]
Get-BrokerConnectionLog | Sort BrokeringTime
[/code]
I always sort by BrokeringTime because the order appears to be odd otherwise because the log is updated with the initial brokering time as well as the EndTime.
Add an application to multiple delivery groups
[code language=”powershell”]
Add-BrokerApplication -Name "AppNameHere" -DesktopGroup "NewDesktopGroupHere"
[/code]
Adding an application to multiple desktop groups is 100% supported, it’s just not exposed in the GUI as of XenApp 7.5. Otherwise, if you try to add an application that already exists, you’ll get “Microsoft Word_1″. Also note when you do this, you can also set a priority to different desktop group- by default, the priority is added as zero – take a look:
[code language=”powershell”]
PS C:\Windows\system32> Get-BrokerApplication -Name "Notepad"
ApplicationType : HostedOnDesktop
AssociatedDesktopGroupPriorities : {0, 0}
AssociatedDesktopGroupUids : {1, 2}
AssociatedUserFullNames : {Domain Users, Jake Rutski}
AssociatedUserNames : {lab\Domain Users, lab\jrutski}
AssociatedUserUPNs : {, [email protected]}
BrowserName : Notepad
ClientFolder : AppCategory
CommandLineArguments :
[/code]
To set a different priority, use the ‘-priority’ argument:
[code language=”powershell”]
Add-BrokerApplication -name "notepad" -DesktopGroup "Test Delivery Group" -Priority 5
[/code]
View the SQL DB info for the site
[code language=”powershell”]
Get-BrokerDBConnection
Server=TESTSQL1;Initial Catalog=CitrixTestSite;Integrated Security=True
[/code]
Monitoring Scripts
This script was used with a monitoring solution to return the count of unregistered machines, not in maintenance mode, powered on, and with a user assigned to the desktop:
[code language=”powershell”]
(Get-BrokerDesktop -MaxRecordCount 2000 -AdminAddress yourddc.goes.here | Where {($_.RegistrationState -eq "Unregistered") -and ($_.AssociatedUserNames) -and !($_.InMaintenanceMode) -and ($_.PowerState -eq "On")}).Count
[/code]
[code language=”powershell”]
(Get-BrokerSession -SessionState Disconnected -AdminAddress yourddc.goes.here | Where {$_.SessionStateChangeTime -gt ((Get-Date).AddMinutes(-5))}).Count
[/code]
[code language=”powershell”]
$NewVMObj = Get-ADComputer -Server your.domain.controller -Filter {Name -eq $NewVMName}
Set-HypAdminConnection -AdminAddress "yourddc.goes.here"
$XDVMId = (Get-Item "XDHyp:\Connections\Your Cluster\Your.datacenter\$($NewCluster).cluster\$($NewVMName).vm").Id
# Add machine to machine catalog; add user to machine
New-BrokerMachine -AdminAddress "yourddc.goes.here" -CatalogUid 3 -HostedMachineId $XDVMId -HypervisorConnectionUid 2 -MachineName $NewVMObj.SID
Add-BrokerUser -AdminAddress "yourddc.goes.here" -Machine (Get-BrokerMachine -SID $NewVMObj.SID).Uid -Name "YOURDOMAIN\$($NewUser)"
# Add machine to desktop group;
Get-BrokerMachine -SID $NewVMObj.SID | Add-BrokerMachine -AdminAddress "yourddc.goes.here" -DesktopGroup "Your Desktop Group Here"
[/code]
[code language=”powershell”]
Get-BrokerDesktop -MaxRecordCount 2000 | Where {((Get-Date) – $_.LastConnectionTime).Days -gt 60} | sort LastConnectionTime | Select DNSName,LastConnectionTime,@{Name="UserName";Expression={$UserN = $_.AssociatedUserNames.Replace("YOURDOMAINHERE\",""); $UserObj = Get-ADUser -Filter {Name -eq $UserN}; "$($UserObj.GivenName) $($UserObj.Surname)"}}
[/code]
hi,
could you please help me in the below two things:
1-could you please provide me the command line using power shell to get the below requirements.
1-i want get the list of all delivery group defined within the DDC.
2-i want to extract the list of delivery group in which the Mozilla Firefox is installed.
Prangya,
1. Get-BrokerDesktopGroup -Property Name,DeliveryType,DesktopKind
Use the -Property parameter so that you don’t get the entire object returned.
2. Get-BrokerDesktopGroup | Where {$_.UUID -in ((Get-BrokerApplication -Name ‘Mozilla Firefox’).AssociatedDesktopGroupUUIDs.GUID)} | Select Name,DeliveryType,DesktopKind
Again using the Select so that you don’t get the entire desktopGroup object
Hi,
Could you help me in below situation
I have application google chrome which is published from shared application citrix server with controller 7.12 and vda 7.15 ,I want below
1. Disconnect the idle session which is more than an hours idle. for the application Google Chrome
2 Than log off that disconnected session which is using google chrome but i only want that session not all other sessions which are opened from that user.