Blog posts tagged with 'mfcom'
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: