An Interactive Case for Powershell (Yet more Citrix Fun!)
I was recently in a discussion on Brian Madden Forums about listing Citrix Information and exporting to CSV. It seemed like a
perfect fit for Powershell so I converted the VBScripts to Powershell (of course taking an 85 line script to 3 lines. Convert is
hardly the correct term.)
Here is the Forum Topic
http://www.brianmadden.com/Forum/Topic/95285
Here is my Code. There were three scripts, so I made three as well.
$MF = (New-Object -com MetaFrameCOM.MetaFrameFarm)
$MF.Initialize(1)
$MF.Servers | Select-Object ServerName -expand Applications | Select-Object ServerName,AppName,DistinguishedName,
@{n=‘Users’;e={$_.Users | %{$_.UserName}}},
@{n=‘Groups’;e={$_.Groups | %{$_.GroupName}}} | export-Csv C:\AppsByServer.Csv -noType
$MF = New-Object -com MetaFrameCOM.MetaFrameFarm
$MF.Initialize(1)
$MF.Applications | Select-Object AppName,DistinguishedName,
@{n="Servers";e={$_.Servers | foreach{$_.ServerName}}} | export-Csv C:\AppsWithServer.Csv -noType
$MF = New-Object -com MetaFrameCOM.MetaFrameFarm
$MF.Initialize(1)
$MF.Applications | Select-Object AppName,DistinguishedName,
@{n="Servers";e={$_.Servers | foreach{$_.ServerName}}},
@{n=‘Users’;e={$_.Users | %{$_.UserName}}},
@{n=‘Groups’;e={$_.Groups | %{$_.GroupName}}} | export-Csv C:\AppsWithServerandUsers.Csv -noType
If you notice in my three scripts they all start with the same two lines. Effectively these are one liners that could be used
interactively. I think this does a great job of showing Citrix Admins how nicely Powershell will fit in to their daily lives.
Things that use to take 100s of lines of script writing can now be done interactively at a shell.
tshell :: Jan.28.2008 :: Citrix, HowTo, Powershell, Scripting :: No Comments »

Can you explain the last part of each script? Specifically the @{n=”Servers”;…}etc. I understand that we are creating some sort of an array, but if I run it as is, I don’t get any values returned.
Thanks.
Hi Brandon
Can you please explain what @{n=”Servers”;e={$_.Servers | foreach{$_.ServerName}}}, ….etc does in powershell sytanx. I am new to powershell and trying to understand what you did.
Thanks
That is what they call a calculated property… I explain it in detail in
http://bsonposh.com/modules/wordpress/?p=72
and
http://bsonposh.com/modules/wordpress/?p=74