Author Posts

August 8, 2018 at 5:51 am

I am new to PowerShell and I am trying to combine Citrix cmdlets to output to single CSV/file.

1) Get-BrokerDesktopgroup | Select Deliverytype,Name,TotalApplications,TotalDesktops

2) Get-BrokerApplication | Select ApplicationName, AssociatedUserFullNames,ClientFolder,CommandLineExecutable

When I run the command separately, I get the output. I tried with few options but still unable to get desired results. Any guidance will be much appreciated

August 8, 2018 at 7:45 am

As a new PS type, it's vital that you get yourself up to speed with all the
no cost ebook resource on this site, video training on

– MS MVA ...

'https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276'
'https://mva.microsoft.com/training-topics/powershell'

– MSDN Channel9

'https://channel9.msdn.com/Series/GetStartedPowerShell3'
'https://channel9.msdn.com/tags/PowerShell'

– even Youtube

https://www.youtube.com/results?search_query=beginning+powershell

Then grab yourself a copy of all the free eBooks on this site and these:

'https://www.amazon.com/Learn-Windows-PowerShell-Month-Lunches/dp/1617294160/ref=sr_1_1?ie=UTF8&qid=1533712412&sr=8-1&keywords=learn+powershell+in+a+month+of+lunches+3rd+edition'

'https://www.amazon.com/Windows-PowerShell-Action-Second-Payette/dp/1935182137/ref=sr_1_sc_1?ie=UTF8&qid=1533712434&sr=8-1-spell&keywords=oershell+in+actio'

'https://www.amazon.com/Windows-PowerShell-Cookbook-Scripting-Microsofts/dp/1449320686/ref=sr_1_3?ie=UTF8&qid=1533712461&sr=8-3&keywords=powershell+cookbook'

What you are getting is what you asked PS to do.  8^)

Your issue here as you've posted. These are completely two separate command, with what you show as no property or value that could relate them together.

You don't say what optiosn you tried and what the results were.
You don't say how you want the final results of this to look like.

So, that leaves us to guess.

If you are saying that you want a csv of these individual data sets to look like this...

"Deliverytype","Name","TotalApplications","TotalDesktops","ApplicationName", "AssociatedUserFullNames","ClientFolder","CommandLineExecutable"
"SomeDeliverytype","SomeName","CountOfTotalApplications","CountOfTotalDesktops","SomeApplicationName", "SomeAssociatedUserFullNames","SomeClientFolder","SomeCommandLineExecutable"
"SomeDeliverytype","SomeName","CountOfTotalApplications","CountOfTotalDesktops","SomeApplicationName", "SomeAssociatedUserFullNames","SomeClientFolder","SomeCommandLineExecutable"
"SomeDeliverytype","SomeName","CountOfTotalApplications","CountOfTotalDesktops","SomeApplicationName", "SomeAssociatedUserFullNames","SomeClientFolder","SomeCommandLineExecutable"
...

Then you have to iterate ove each dataset, line by line and join them. I've no way to test this as I do not use Citrix. However, in most cases if you can iterate, you can join on each pass

# Collect your dataset
$BrokerDesktopgroup = Get-BrokerDesktopgroup | Select Deliverytype,Name,TotalApplications,TotalDesktops
$BrokerApplication = Get-BrokerApplication | Select ApplicationName, AssociatedUserFullNames,ClientFolder,CommandLineExecutable

# Loop thru BrokerDesktopgroup and join data with BrokerApplication.

Yet where to join them?
Why join them?

Again, I am not a Citrx guy. Yet, data is data.

# Looking at the Ctrix PS cmdlet docs, says...

— Name (System.String)
Unique administrative name of application.

Notes

Get-BrokerApplication returns just the application object, and as such is not a complete picture. The returned objects do not tell you what File-Type Associations are configured for this application, etc.

Use the following cmdlets to gather data related to applications (shown with examples of syntax):

Get-BrokerDesktopGroup -ApplicationUid $app.Uid

https://docs.citrix.com/en-us/xenapp-and-xendesktop/7-5/cds-sdk-wrapper-rho/cds-sdk-cmdlet-help/citrix-broker-admin-v2-wrapper-xd75/get-brokerapplication-xd75.html

$BrokerDesktopgroup = Get-BrokerDesktopgroup | Select Deliverytype,Name,TotalApplications,TotalDesktops,ApplicationUid
$BrokerApplication = Get-BrokerApplication | Select ApplicationName, AssociatedUserFullNames,ClientFolder,CommandLineExecutable,Uid

So, this appears to get you the join point, but you have to decide which comes first and what you want the outcome to be.

August 8, 2018 at 8:02 am

Hi postano

Thanks for your reply. Sorry for missing info. The following are the output of each command. I am trying to join the commands into single script, so I get the output in one CSV instead of two different files and then merge the output from file. Each commands pulls out different data and I need to combine the data to make it single report.

PS C:\Temp> Get-BrokerDesktopgroup | Select Deliverytype,Name,TotalApplications,TotalDesktops

DeliveryType Name                                  TotalApplications TotalDesktops
———— —-                                  —————– ————-
DesktopsOnly Windows 10 – Test1                                 0            32
DesktopsOnly Windows 10 – Test                                 0             1

 

PS C:\Temp> Get-BrokerApplication | Select ApplicationName, AssociatedUserFullNames

ApplicationName             AssociatedUserFullNames
—————             ———————–
Notepad – TRAINING    {}
Notepad_PROD                {}

 

 

August 8, 2018 at 8:36 am

No worries.
The, what seems like pictures, did not come thru.
However, You don't what, should come first and if this should be a single row per record for each.
If you are just appending one result beneath the other, due to the property selection, then this is just two results sets in the same file, vs an Excel / database-like look.

So, IAW the Citrix docs, you can chain this by the last to properties, noted. Yet, you still need to decide which comes first and what it should look like.

If, for example, this set of data is a 1 to 1 match, then this is common. I don't have anything Citrix, but if I would do something similar with Exchange, it would look something like this.

$outputCollection = @()
$users = Get-User -Filter "..."
$mailboxes = Get-Mailbox -Filter "..."

$users | Foreach-Object {
    #Associate objects
    $userObject = $_
    $mailboxObject = $mailboxes | Where-Object {$_.Name -eq $userObject.Name}

    #Make a combined object
    $outputObject = "" | Select Name, UserAttribute, MailboxAttribute
    $outputObject.Name = $userObject.Name
    $outputObject.UserAttribute = $userObject.UserAttribute
    $outputObject.MailboxAttribute = $mailboxObject.MailboxAttribute

    #Add the object to the collection
    $outputCollection += $outputObject
}

$outputCollection

With the ApplicationUid, Uid properties, you should be able to accomplish the same or something even better.

August 8, 2018 at 1:35 pm

I don't have Citrix to be able to test this so consider this sudo code, but when I need to compbine 2 collections into one object I use a hash table @{Get-Help about_Hash_Tables}

$BrokDesktop = Get-BrokerDesktopgroup
$BrokApplications = Get-BrokerApplication

$object = [ordered]@{'Deliverytype' = $BrokDesktop.Deliverytype;
'Name' =$BrokDesktop.Name;
'TotalApplications' = $BrokDesktop.TotalApplications;
'TotalDesktops' = $BrokDesktop.TotalDesktops;
'ApplicationName' = $BrokApplications.ApplicationName;
'AssociatedUser' = $BrokApplications.AssociatedUserFullNames;
'ClientFolder' = $BrokApplications.ClientFolder;
'Executable' = $BrokApplications.CommandLineExecutable}
 $CitrixData = New-Object -TypeName PSObject -Property $object
Write-Output -InputObject $CitrixData

You also need to consider if the output of those Citrix commands give more than one single object you would need the hash table to be builtin in a foreach loop appending each object as it loops to the custom PSObject. Hash tables are very hard to master and I can not test the code, but you can get more ideas by searching your favorite PowerShell resources online for "has tables" and look at other examples. Hash Tables are the best way I know of to combine more than one collection into one custom PSObject.

-VERN