Citrx XenApp MFCOM Powershell


I am writing a program that displays Application Names and the servers they are published on.
It works fine if the published application has only one server, but if it has two, the results ends up putting the server names on one line in a array.

I have what I currently get below and what I want the desired results to be. I feel like it is a easy task but my coworker and I cannot seem to get this.


$farm = New-Object -ComObject 'MetaframeCOM.MetaFrameFarm'
$farm.Initialize(1)

$farm.Applications | %{$_.LoadData(1);$_} | Select-Object AppName, foreach($S in $Servers){$S.ServerName}

---CURRENT OUTPUT----------------------
P4V                                     ServerName
P4 Command Prompt                       ServerName
PowerShell                              ServerName
SMIViewer                               {ServerName1, ServerName2}      ------------------THIS IS THE PROBLEM-----------
SMIHeatMap                              {ServerName, ServerName2}      ------------------THIS IS THE PROBLEM-----------
SMITridentEventViewer                   {ServerName, ServerName2}      ------------------THIS IS THE PROBLEM-----------
Dynamics GP2010 - Dev - New String      ServerName





-----------WHAT I WANT-----------------
P4V                                     ServerName
P4 Command Prompt                       ServerName
PowerShell                              ServerName
SMIViewer                               ServerName1
SMIViewer                        ServerName2
SMIHeatMap                              ServerName1
SMIHeatMap                        ServerName2
SMITridentEventViewer                   ServerName1
SMITridentEventViewer                  ServerName2
Dynamics GP2010 - Dev - New String      ServerName
Problem.txt
MichaelZappaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale HarrisProfessional Services EngineerCommented:
So I'm not sure about testing this out as I don't have the same environment, but it looks to me like an array appending issue.

Here's what I would do(expanded for readability):

$List = @()
$farm = New-Object -ComObject 'MetaframeCOM.MetaFrameFarm'
$farm.Initialize(1)

$Apps = $farm.Applications | %{$_.LoadData(1);$_}
Foreach ($App in $Apps){
Foreach ($Server in $App.servers)
$List += "$($App.AppName) $($Server.ServerName)"
}
$List

Not tested, but it should work for your purposes.

Dale
0
Dale HarrisProfessional Services EngineerCommented:
Oops, forgot a closing brace:

$List = @()
$farm = New-Object -ComObject 'MetaframeCOM.MetaFrameFarm'
$farm.Initialize(1)

$Apps = $farm.Applications | %{$_.LoadData(1);$_}
Foreach ($App in $Apps){
Foreach ($Server in $App.servers)
$List += "$($App.AppName) $($Server.ServerName)"
} #end foreach server in server
} #end foreach app in apps
$List
0
Dale HarrisProfessional Services EngineerCommented:
One more try:

$List = @()
$farm = New-Object -ComObject 'MetaframeCOM.MetaFrameFarm'
$farm.Initialize(1)

$Apps = $farm.Applications | %{$_.LoadData(1);$_}
Foreach ($App in $Apps){
   Foreach ($Server in $App.servers){
      $List += "$($App.AppName) $($Server.ServerName)"
   } #end foreach server in server
} #end foreach app in apps
$List
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MichaelZappaAuthor Commented:
Thankyou.



$farm = New-Object -ComObject 'MetaframeCOM.MetaFrameFarm'
$farm.Initialize(1)
$List = @()
Foreach($App in $farm.Applications)
{
$App.LoadData($True)
$AppName = $App.AppName

foreach($Server in $App.Servers)
{
$List += "$($AppName) $($Server.ServerName)"
}

}
$List
0
MichaelZappaAuthor Commented:
What would be a method for formatting the output such like this

AppName:            ServerName:
Names                  Names
Names                  Names
Names                  Names
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Citrix

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.