Jason Conger Blog RSS

All Blogs  »  Jason Conger Blog  »  News SBC Tips and Tools  »  Blog article: Using PowerShell with Citrix Policies

Using PowerShell with Citrix Policies

PowerShell has quickly become one of my favorite scripting interfaces. One of the cool things about PowerShell is its object oriented design and use. This makes it easy to blend command line scripting with Citrix objects exposed via MFCOM. Brandon Shell has posted a nice example of manipulating Citrix policies using PowerShell. Check out Brandon’s Citrix policy PowerShell functions:

Script To Get Citrix Policy

# Get-CitrixPolicy.ps1
Param($Server,$PolicyName = ".*")

# Enums in Use
$MetaFrameUnknownObject = 0
$MetaFrameWinFarmObject = 1

# Getting Farm Object
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$Server)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize($MetaFrameWinFarmObject)

# Getting Policies that Match Name and Loading Data
$pol = $mfarm.policies($MetaFrameUnknownObject) | ?{$_.Name -match $PolicyName}
$pol | %{$_.LoadData($true)}
$pol

Script To Create a New Citrix Policy

# New-CitrixPolicy.ps1
Param($Server,$PolicyName,$PolicyDescription)
if(!$PolicyDescription){$PolicyDescription=$PolicyName)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$Server)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
$NewPolicy = $mfarm.CreatePolicy(19,$PolicyName,$PolicyDescription)

Script To Remove a Citrix Policy

# Remove-CitrixPolicy.ps1
Param($Server,$PolicyName = $(throw '$PolicyName is Required'),[switch]$whatif)

# Enums in Use
$MetaFrameUnknownObject = 0
$MetaFrameWinFarmObject = 1

# Getting Farm Object
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$Server)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize($MetaFrameWinFarmObject)

# Getting Policies that Match Name and Loading Data
$policies = $mfarm.policies($MetaFrameUnknownObject) | ?{$_.Name -eq $PolicyName}
foreach($pol in $policies)
{
    if($whatif){Write-Host " What if: Performing operation `"Delete`" on Target `"$($pol.Name)`". " -foreground yellow}
    else{Write-Host " - Deleting $($pol.Name)";$pol.Delete()}
}

Continue at source…

Be sure to check out some of the other PowerShell resources available on MSTerminalServices.org:

Using PowerShell to Manage Terminal Services Attributes

Using PowerShell in Your Environment


Technorati : , , , ,
Del.icio.us : , , , ,
Ice Rocket : , , , ,

2 Responses to “Using PowerShell with Citrix Policies”

  1. Brandon Says:

    March 30th, 2008 at 9:45 am

    Thanks for the cross post :) I truly love Powershell as well. It makes complex task in Batch and Vbscript trivial.

    Note: It looks like you have the Get and New mixed up in your post.

  2. Jason Says:

    March 30th, 2008 at 7:21 pm

    Thanks for pointing out the mix up. I corrected the post.

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 6 chars within 0..9 and A..F, and submit the form.

  

If CAPTCHA image is missing or you cannot read the characters above, please generate a




Receive all the latest articles by email!

Receive Real-Time & Monthly VirtualizationAdmin.com article updates in your mailbox. Enter your email below!

Become a VirtualizationAdmin.com member!

Discuss all your Virtualization issues with thousands of other experts. Click here to join!

Solution Center