I notice there was entry on Brian Madden forums about creating Citrix Policies. http://www.brianmadden.com/Forum/Topic/97139
I decided to spend a little time looking at this from a script perspective and here are some examples of dealing with Citrix Policies that I came up with.
Just a FYI
I hear tell there will be some Citrix CMDLets coming very soon that will make working with Citrix amazingly simple (which will include an import/export Citrix policy cmdlets.) I cannot tell you how revolutionary this will be for your typical Citrix Admin.
You can find the Citrix Enums here
http://bsonposh.com/modules/wordpress/?p=62
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()}
}
tshell :: Mar.25.2008 ::
Citrix, HowTo, Powershell, Scripting ::
2 Comments »