Nick has recently released a really cool Vista Gadget for XenApp. It is yet another use case of building innovative tools using MFCOM SDK. If you are a XenApp Admin check this tool directly at his blog

Brandon Shell (MVP PowerShell) and I are planning a more advanced level MFCOM and PowerShell Webinar to manage XenApp. We are looking for some input for the webinar content. Tell us what particular script or sample code you would like to see via comments. If you would like us to demo a particular method or a call then please leave us a comment. We would try our best to include it in the webinar.
Follow the link provided to view the previous webinar where Brandon explained how to write MFCOM scripts using PowerShell to manage XenApp.
We have just released the XenApp Management SDK (MFCOM) for XenApp 5.0, and it is now available as a free download.
This SDK allows creating programs or scripts that automate the management of XenApp. Examples of use for this SDK range from simple scripts to the implementation of full-fledge custom consoles for fully managing a XenApp deployment.
This release of the SDK adds support for Health Monitoring and Recovery, for reboot schedules, and for session policies. For additional details see the SDK and the XenApp documentation. You can also visit the very active Community Forum for this SDK.
XenApp 5.0 was announced earlier this week. If you want to learn more about it, you should not miss Citrix Delivery Center Live. This live virtual event will take place on September 9th. Make sure to register now!
In my last blog I have started with the Introduction of PowerShell and MFCom. Today we'll provide you more information's about MFCom Objects and how to use them with PowerShell.
Check Session State
To retrieve the session state for each session within the Citrix farm you have to query IMetaFrameSession.SessionState. If the returned state of the session is MFSessionStateStale, no further attempt to read other session properties should be made. This state indicates that the session may no longer exist.
The following PowerShell script displays all active sessions within the farm and adds additional session information to the output. To check other session's states you only have to replace the session state type in the last line of the code.
#Type Definitions
$MetaFrameWinFarmObject = 1
$MFSessionStateUnknown = 0 #Unknown state
$MFSessionStateActive = 1 #User logged on
$MFSessionStateConnected = 2 #Connected to client
$MFSessionStateConnecting = 3 #Connecting to client
$MFSessionStateShadowing = 4 #Shadowing another session
$MFSessionStateDisconnected = 5 #Logged on but no client
$MFSessionStateIdle = 6 #Waiting for connection
$MFSessionStateListening = 7 #Listening for connection
$MFSessionStateResetting = 8 #Reset in progress
$MFSessionStateDown = 9 #Down due to error
$MFSessionStateInit = 10 #Initializing
$MFSessionStateStale = 11 #Stale session object
#Main
$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize($MetaFrameWinFarmObject)
$farm.FarmName
$farm.Sessions | Where-Object { $_.SessionState -eq $MFSessionStateActive {color:black}}| Format-table Username,SessionName,AppName,ServerName,SessionState
Find disabled Application
Finding disabled applications is mostly useful in your production or test environment where you have to handle with many published applications. This property IMetaFrameApplication.EnableApp enables or disables the application.
- When you publish an application, it is enabled by default. Enabled applications are available to the users specified when the application was published. Disabled applications are not available to users.
- The application can become disabled internally if its server list becomes empty, or if its user list becomes empty and the application is not configured to accept anonymous connections.
- A disabled application is not available to clients.
#Type Definitions
$MetaFrameWinFarmObject = 1
#Main
$farm = new-Object -com "MetaFrameCOM.MetaframeFarm"
$farm.Initialize($MetaFrameWinFarmObject)
$farm.FarmName
$app = $farm.Applications
$app | foreach { $_ | ? { $_.EnableApp -eq 0 }}|Format-Table DistinguishedName
Microsoft Windows PowerShell command line shell and scripting language helps IT professionals achieve greater control and productivity. Using a new admin-focused scripting language, more than 130 standard command line tools, and consistent syntax and utilities, Windows PowerShell allows IT professionals to control system administration and accelerate automation more easily
With PowerShell, Citrix Administrators can script MFCom Objects to manage and administer the XenApp Farm. The secret of using COM objects starts with the command: New-Object -COM.
The following PowerShell example creates a new MetaFrame object (do not get confused with the COM Object naming), initializes the Farm and prints out the farmname:
$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.FarmName
It's not going to be a spectacular script. But look at the following little code enhancement:
$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.FarmName
$farm.sessions | Format-Table UserName,ClientAddress
Just adding one more lines of code and you will get all sessions within the farm displaying the Username and IP Address.
Setting up your PowerShell / MFCom environment
Beginning with PowerShell / MFCom Scripting you should install Microsoft Powershell on a Citrix Presentation / XenApp Server in your lab. I recommend downloading the PowerShell Graphical Helpfile which also provides great information's about VBScript to PowerShell conversion.
For creating and editing your PowerShell scripts I suggest downloading the free PowerGui graphical user interface and script editor. Its easy to use and works well with COM Objects.
PowerShell
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
PowerShell Graphical Help File
http://www.microsoft.com/downloads/details.aspx?FamilyId=3B3F7CE4-43EA-4A21-90CC-966A7FC6C6E8&displaylang=en
PowerGui - Graphical user interface and script editor
http://www.powergui.org

Displaying apps in your farm
To give you some basic ideas where PowerShell leverages your daily administrative tasks, I've created the following script:
$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.FarmName
$farm.applications| where {$_.BrowserName -like "Winword*" {color:black}} | select DistinguishedName
The script above enumerates each application published in the farm and selects all applications where Winword* is contained in the BrowserName.
PowerShell Examples provided by CDN
PowerShell and other scripting examples can be found on the Citrix Developer Network:
If you are attending IT professionals TechMentor event this week in Orlando then I would recommend you go and check out Bradon Shell's session on "Automating Citrix Server Administration with Windows PowerShell"
"In this session you'll learn how to use Powershell to make Citrix server management easier. We'll also walk through the Citrix road map and how Powershell fits in. We will cover several different common administrative tasks and show how Powershell can make these tasks faster and easier to perform, including publishing applications, unpublishing applications, getting application information, and getting servers online. We'll look at using the PowerShell pipeline, and see how to make your scripts output information that can be piped to other scripts. Finally, you'll learn how to use MFCOM, get information from it, and look at some of the gotchas you'll need to be aware of when dealing with it"
Brandon and I have recently done a webinar on PowerShell and Citrix MFCOM. You can view the Webinar at this URL
https://www1.gotomeeting.com/register/114744868
UPDATE:
I have got several emails asking me if there will be any session on PowerShell and MFCOM during Citrix Synergy event . There is no specific session on PowerShell and MFCOM but we have speakers giving advance classes on MFCOM SDK and Hands on training with MFCOM SDK during Synergy. If you still have questions regarding PowerShell and MFCOM then come by during my Geek Speak session and I will try my best to answer them
Last week Dr. SDK completed his ultimate guide to MFCOM (101 pages). This is the only guide you will ever need to understand and learn about MFCOM SDK. It covers everything up to SDK version 4.5.
It covers all the advance MFCOM topics such as multifarm management, publishing different type of Applications, policies, load evaluators and more.
Hope you enjoy reading it.
I want to thanks everyone who attended the webinar yesterday. If you missed the webinar then you can watch the recording at the following URL https://www1.gotomeeting.com/register/114744868
You can also download the slide deck here Dowload link
If you are interested in learning PowerShell then subscribe to Brandon Shell rss feed. I totally love the way he explains PowerShell concepts.
I am going to send out a more detailed survey to everyone who attended the webinar. Your feedback will help us determine future webinars and chats.
| Would you like to see an advance PowerShell and MFCOM webinar? | Choose |
|---|---|
| Yes | |
| No |
| How would you rate yesterday's webinar on a scale to 1 to 5 with 5 being Awesome? | Choose |
|---|---|
| 1 Totally sucked | |
| 2 Just OK | |
| 3 Good stuff | |
| 4 Great. | |
| 5 Awesome |
Please let me know via comments what SDK and technology webinar you would like to see in future. I will try my best to get the experts do it for CDN members.
Brandon Shell (http://bsonposh.com) and I are going to do a free webinar on PowerShell and Citrix
UPDATE : Tuesday 29th April 1PM - 2PM EST.
UPDATE 28th April : International direct dial + 1 617 801 6700
We are targeting audiences with following skill.
Basic Powershell, Basic Citrix Admin Skills and Basic MFCOM experience in VB script.
Here is the rough agenda for the webinar
Powershell Basics (about 20 mins)
Object Based
Self Teaching Get-Help , Get-Command, Get-Member
- Properties
- Methods
New-Object - ComObject
- .NET Class
Managing Citrix Servers via PowerShell and MFCOM (about 20 mins)
Most Properties Return Objects (like Servers, Applications, Sessions)
Creating MFCOM object in Powershell
$variable = New-Object -com <MFCOM COM Name>
Examples
$mfobject = New-object -com 'MetaframeCOM.MetaFrameFarm'
$mfobject.Initialize(<int parameters>)
With just these two lines you can start exploring you Citrix Environment
$mfFarm = New-object -com 'MetaframeCOM.MetaFrameFarm'
$mfFarm.Initialize(1)
Getting Key Info To get From Farm Object
$mfFarm | Get-Member -MemberType Property # Gets just Properties
Admins
Applications
FarmName
Servers
Sessions
LicenseServer
Printers
Zones
Space is limited
Reserve your Webinar seat now at:
https://www1.gotomeeting.com/register/114744868
Citrix SDK guru's have converted more top downloaded MFCOM VB scripts to PowerShell-MFCOM Scripts. Bradon Shell has created 3 more PowerShell Scripts which are really useful.
*[Get-CitrixApplication.ps1 (Powershell)]
Returns Citrix Application Objects for AppName passed or RegEx
*[Set-CitrixServerLogon.ps1 (Powershell)]
Sets the Server to Enable or Disable Logons
*[Get-CitrixAppServer.ps1 (Powershell)]
Gets All the Servers for Specific App
If you are learning PowerShell then I highly recommend subscribing to his blog at http://bsonposh.com/.
Jason Conger one of the Citrix SDK guru's has also contributed a really cool MFCOM-PowerShell script.
Here is a description of the script
"If you have a lot of published applications in several nested folders, it can be a challenge to locate exactly which particular folder contains a particular application. This script takes a parameter as a search pattern. The script then searches the published application directory structure and returns the full path to all applications that match the search pattern parameter. This saves time clicking through all the folders trying to find a published application."
If you are a Citrix SDK guru then feel free to contact me via comments or email. I would love to hear your experiences with our SDKs.
Brandon Shell (MVP) has done an awesome job and converted top 5 MFCOM VB Scripts to PowerShell. Here is a list of scripts he has contributed
- [Find-CitrixUser.ps1 (Powershell)]
- [Get-CitrixPrinterInfo.ps1 (Powershell)]
- [Find-CitrixIdleUser.ps1 (Powershell)]
- [Get-CitrixSessionUser.ps1 (Powershell)]
- [Set-CitrixPSVersion.ps1 (Powershell)]
If you are new to PowerShell then I would highly recommend visiting his site and learning more about Citrix and PowerShell samples. You can visit him at http://bsonposh.com/
Brandon and I are also planning to do a series of Webinar on MFCOM and PowerShell. I will post more information on signup and date tomorrow.
please let us know via comments what PowerShell scripts you would like to see on Script Exchange and we will try our best to get those samples out there.
UPDATE: I had couple of emails asking me on how to contribute to Script Exchange and share with the community. Watch this video to see how easy and simple it is to contribute.
Stay tuned
Vishal Ganeriwala
http://community.citrix.com/cdn
Have you ever tried to get the Client IP address for a Citrix or terminal services session and got stuck? I have had several emails asking me on how to do it. Well I thought I might just blog about it. I can think four ways to do it and if you can add to the list then please do via comments. So let's get to the business right away.
1. The simplest way is to use the MFCOM API to get a list of session and enumerate each session to get username and the Client IP address. Here is a code snippet.
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm") objFarm.Initialize(1) For Each objSession In objFarm.Sessions WScript.Echo "User name : " & objSession.UserName WScript.Echo "IP Address: " & objSession.ClientAddress Next
You need to be an admin on XenApp (Formerly known as Presentation Sever) Farm to run MFCOM queries. You can read more and download the MFCOM example here.
2. Use WFAPI SDK WFEnumerateSessions method to get a list of all the sessions on a server and then use WFQuerySessionInformation to extract Client IP for each session on the server I have written a Sample program on how to do it. Follow this link to download WFAPI and Csharp .Net program which enumerates all sessions on a server and their Client IP address.
3. Use native terminal Services API. Similar to WFAPI use TSEnumerateSessions to get a list of sessions on a server and then use TSQuerySessionInformation to extract Client IP address each session on the server. To read more follow this link to download Terminal Services API sample example written in Csharp .Net.
4. You can also use ICO SDK and GetClientAddress API to get client IP within a ICO session The ICA Client Object is the framework that exposes the functionality of the Citrix ICA Win32 Client to third party applications. The ICA Client Object (ICO) SDK enables developers and administrators to modify the behavior and appearance of a Windows 32-bit Citrix ICA client. The SDK is a series of documents that detail available application programming interface (API) in the Citrix ICA client Follow this link to download an ICO example which illustrates the use of methods and properties available to get client network name and IP address information using Citrix ICO SDK.
Code snippet for ICO in JavaScript
function GetClientNetworkName(form)
{
form.netname.value = document.ICO1.GetClientNetworkName()
}
function GetAddrCnt(form)
{
form.addrcnt.value = document.ICO1.GetClientAddressCount()
}
function GetAddr(form)
{
form.addr.value = document.ICO1.GetClientAddress(0)
}
Here is a high level architecture diagram of MFCOM SDK and how the it work.

