Citrix, Citrix, and more Citrix!
It has been a while since I dove into the MFCom pool. Most of the Citrix functions I wrote where at the very beggining of my Powershell Adventure. I decided to go through and rewrite some of them and post the others.
So… here you go.
I broke these down into three sections
- Citrix Farm Functions
- Citrix App Functions
- Citrix Server Functions
If you get a chance to use these let me know if you run into any troubles… I did test them thoroughly.. but you never know.
Other than Publish/Unpublish/Remove they shouldn’t change anything.
UPDATED: I added information about functions before each section. And a list at the bottom!
Farm functions
————–
# Returns Farm Object.
# -Server: Any PS should do.. I recommend ZDC though) !!REQ!!
Get-CitrixFarm
# Returns a collection of Server Objects
# -zone= This will be the zone name (normally the subnet i.e. 10.1.1.0) !!REQ!!
Get-CitrixOnline
# Returns Load Evaluators Information
# -Server: Any PS should do.. I recommend ZDC though) !!REQ!!
Get-CitrixLE
# Returns Printer Drivers install in Farm
# -Server: Any PS should do.. I recommend ZDC though) !!REQ!!
# This can take a REAL long time
Get-CitrixPrintDrivers
# Returns Polices in the Farm
# -Server !!REQ!! (any PS should do.. I recommend ZDC though)
Get-CitrixPolicies
#### Citrix Farm Functions ####
#########################################
# Get Citrix Farm
function Get-CitrixFarm{
param($Server)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$Server)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
# Get Online Servers by Zone
function Get-CitrixOnline {
Param($zone)
$mfzone = New-Object -ComObject MetaFrameCOM.MetaFrameZone
$mfzone.Initialize($zone)
$servers = $mfzone.OnlineServers
$servers
}
# Get Citrix Load Evaluators (only 4.0/4.5)
function Get-CitrixLE{
Param($server=$(throw "Server is Required"))
function Load-Farm{
param($srv)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
$Farm = load-farm $server
if($Farm.LoadEvaluators){
foreach($eval in $Farm.LoadEvaluators)
{
$eval.loadData(1)
"+ Load Evaluator: {0}" -f $eval.LEName
$servers = $eval.AttachedServers(1)
if($servers.count -ne 0)
{
" + Servers"
$servers | %{" - {0}" -f $_.ServerName}
}
$rules = $eval.rules | Select-Object RuleType,HWM,LWM,Schedules
if($rules.count -ne 0)
{
" + Rules"
foreach($rule in $rules)
{
" - {0}" -f $rule
}
}
}
}
}
# Gets the Citrix Printer Drivers for the Farm (Can be REAL slow)
function Get-CitrixPrintDrivers{
Param($server=$(throw "Server is Required"))
function Load-Farm{
param($srv)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
$farm = Load-Farm $Server
$farm.Drivers
}
# Gets Citrix Policies
function Get-CitrixPolicies{
param($Server)
function Load-Farm{
param($srv)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
$farm = Load-Farm $server
$type = [System.Type]::GetTypeFromProgID("MetaFrameCOM.MetaFrameUserPolicy")
foreach($pol in $Farm.policies($type))
{
$pol.loadData(1)
"+ Name: {0}" -f $pol.Name
" - Description: {0}" -f $pol.Description
" - Enabled: {0}" -f $pol.Enabled
if($pol.AllowedAccounts)
{
" + AllowedAccounts"
foreach($aa in $pol.AllowedAccounts)
{
" - {0}" -f $aa.AccountName
}
}
if($pol.UserPolicy2)
{
" + UserPolicy"
$props = $pol.UserPolicy2 | Get-Member -membertype Property | %{$_.Name} | Sort-Object Name
foreach($prop in $props)
{
if(($pol.UserPolicy2.$prop -match "\d") -and ($pol.UserPolicy2.$prop -ne 0))
{
" - {0}:{1}" -f $prop,$pol.UserPolicy2.$prop
}
}
}
write-Output " "
}
}
App functions
————–
# Returns User Count for an App or All Apps
# -FarmServer !!REQ!! (any PS should do.. I recommend ZDC though)
# -app: Name of Application
# This loops CTRL+C to break
Get-ApplicationUserCount
# Returns Server(s) user is logged into via Citrix
# -LoginName: Login Name of user (Domain\User) !!REQ!!
# -Verbose: Details about User
Find-CitrixUser
# Returns Servers published for Application or just Count
# -app: Name of Application !!REQ!!
# -count: Switch… if set just returns count of servers
Get-CitrixServers
# Returns Users currently using APP
# -app: !!REQ!!
# -count: Switch… if set just returns count of servers
Get-CitrixAppUsers
#### Citrix App Functions ####
#########################################
# Outputs the number of Users using a Citrix App or Apps
function Get-ApplicationUserCount {
Param([string]$app,[string]$farmServer = $(throw ‘$FarmServer is Required’))
function List-AllCitrixApps{
Param($mFarm)
ForEach($app in $mFarm.Applications)
{
$name = $app.BrowserName.PadRight(25)
$count = "$($app.Sessions.Count)"
$count = $count.PadRight(10)
Write-Host "$name $count"
}
}
function List-App{
param($mApp,$mfFarm)
ForEach($app in $mfFarm.Applications)
{
if($app.BrowserName -eq "$mApp")
{
$name = $app.BrowserName.PadRight(25)
$count = "$(($app.Sessions | ?{$_.SessionState -eq 1}).Count)"
$count = $count.PadRight(10)
Write-Host "$name $count"
}
}
}
function Load-Farm{
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeFarm",$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
Write-Host
$title1 = "Application".PadRight(25)
$title2 = "===========".PadRight(25)
Write-Host "$title1 User Count" -ForegroundColor White
Write-Host "$title2 ==========" -ForegroundColor Red
$mf = Load-Farm $farmServer
While($true)
{
$oldpos = $host.UI.RawUI.CursorPosition
If($app)
{
List-App $app $mf
}
else
{
List-AllCitrixApps $mf
}
sleep(5)
$host.UI.RawUI.CursorPosition = $oldpos
}
Write-Host ""
}
# Finds what Server a User is on
function Find-CitrixUser {
Param([string]$LoginName,[switch]$verbose)
$user = $LoginName.Split("\")[1]
$Domain = $LoginName.Split("\")[0]
$mfuser = New-Object -ComObject MetaframeCOM.MetaframeUser
$mfuser.Initialize(1,$Domain,1,$user)
Write-Host
Write-Host "User: $($mfuser.UserName) found on the Following:"
foreach ($s in $mfuser.Sessions)
{
if($verbose)
{
Write-Host
Write-Host "$($s.ServerName)"
Write-Host "-=-=-=-=-=-"
Write-Host "AppName : $($s.AppName)" -foregroundcolor yellow
Write-Host "SessionName : $($s.SessionName)" -foregroundcolor yellow
Write-Host "SessionID : $($s.SessionID)" -foregroundcolor yellow
Write-Host "ClientAddress : $($s.ClientAddress)" -foregroundcolor yellow
Write-Host "ClientEncryption : $($s.ClientEncryption)" -foregroundcolor yellow
Write-Host
Write-Host "Processes"
Write-Host "========="
foreach ($proc in $s.Processes)
{
Write-Host $proc.ProcessName -foregroundcolor Green
}
Write-host
}
else
{
write-Host " -> $($s.ServerName)"
}
}
}
# Gets Servers Published for specified App (or just returns count)
function Get-CitrixServers {
Param($app = $(throw ‘$app is required’),[switch]$count)
$mfm = New-Object -com MetaFrameCOM.MetaFrameFarm
$mfm.Initialize(1)
$servers = $mfm.Applications | ?{$_.AppName -eq $app}
$servers = $servers.Servers | sort -Property ServerName
if($count)
{
Write-Host
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
Write-Host
}
else
{
Write-Host ""
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
Write-Host "———————————————–" -ForegroundColor gray
foreach($server in $servers){Write-Host "$($server.ServerName)" -ForegroundColor Green}
Write-Host "———————————————–" -ForegroundColor gray
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
Write-Host ""
}
}
# Returns Users currently using Citrix App
function Get-CitrixAppUsers {
Param($app = $(throw ‘$app is required’),[switch]$count)
$ErrorActionPreference = "SilentlyContinue"
Write-host
$mfm = New-Object -com MetaFrameCOM.MetaFrameFarm
$mfm.Initialize(1)
$users = $mfm.Applications | ?{$_.AppName -eq $app}
$Users = $users.Sessions | sort -Property UserName
if($count){
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
Write-Host
}
else{
Write-Host ""
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
Write-Host "—————————————————–" -ForegroundColor gray
foreach($user in $Users){
If($User.SessionState -eq 1){
Write-Host ($User.UserName).PadRight(10) -ForegroundColor Green -NoNewline
}
else{
Write-Host ($User.UserName).PadRight(10) -ForegroundColor yellow -NoNewline
}
}
Write-Host
Write-Host "—————————————————–" -ForegroundColor gray
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
Write-Host
}
}
Server functions
————–
# Returns A Server Object
# -Server: Name of the Server !!REQ!!
Get-CitrixServer
# Publishes Application to Server(s)
# -app: !!REQ!!
# -Server: Name of Server
# PIPED: It will take Servers via Pipe. It expects a list or Citrix Server Object
Publish-CitrixApplication
# UnPublishes ALL Application from Server(s)
# -Server: Name of Server
# PIPED: It will take Servers via Pipe. It expects a list or Citrix Server Object
UnPublish-CitrixServer
# Remove Specific Application from Server(s)
# -app: !!REQ!!
# -Server: Name of Server
# PIPED: It will take Servers via Pipe. It expects a list or Citrix Server Object
Remove-CitrixApplication
# Gets Published Applications from Server(s)
# -Server: Name of Server
# PIPED: It will take Servers via Pipe. It expects a list or Citrix Server Object
Get-CitrixApplications
# Returns Count of Logged on Users from Server(s)
# -Server: Name of Server
# PIPED: It will take Servers via Pipe. It expects a list or Citrix Server Object
Get-TSUserCount
#### Citrix Server Functions ####
##########################################
# Get a Citrix Server Object
function Get-CitrixServer{
Param($Server)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeServer",$Server)
$mfServer = [system.Activator]::CreateInstance($type)
$mfServer.Initialize(6,$Server)
$mfServer
}
# Publish Application to Server(s)
function Publish-CitrixApplication{
Param([string]$server,[string]$app)
Begin{
Write-Host
function cPublish {
Param([string]$Srv,[string]$myapp)
$Srv = $Srv.toUpper()
$mfSrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
$mfSrv.Initialize(6,"$Srv")
$mfApp = New-Object -ComObject MetaFrameCOM.MetaFrameApplication
$mfApp.Initialize(3,"Applications\$myapp")
$mfApp.LoadData($true)
$mfAppBinding = New-Object -ComObject MetaFrameCOM.MetaFrameAppSrvBinding
$mfAppBinding.Initialize(6,$Srv,"Applications\$app")
if($mfAppBinding)
{
Write-Host "Publishing App[$myapp] on Server [$Srv]" -ForegroundColor Green
$mfApp.AddServer($mfAppBinding)
$mfApp.SaveData()
}
else
{
Write-Host "Unable To Create App Binding" -ForegroundColor Red
}
}
$process = @()
}
Process{
if($_){
if($_.ServerName){
$process += $_.ServerName
}
else{
$process += $_
}
}
}
End{
if($Server){$Process += $Server}
foreach($s in $process){
cPublish -srv $s -myapp $app
Write-Host
}
}
}
# UnPublish All Application from Server(s)
function UnPublish-CitrixServer{
Param([string]$server)
Begin{
function cUnPublish {
Param([string]$Srv)
$Srv = $Srv.toUpper()
$mfSrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
$mfSrv.Initialize(6,"$Srv")
If($mfSrv.Applications.Count -gt 0)
{
Write-Host "Removing All Published Applications from $Srv" -ForegroundColor Red
Write-Host "===================================================" -ForegroundColor Green
ForEach($a in $mfSrv.Applications)
{
$myApp = $a.AppName
$a.LoadData(1)
Write-Host "Removing App [$myApp] from Server [$Srv]" -ForegroundColor White
$a.RemoveServer($Srv)
$a.SaveData()
}
}
else
{
Write-Host "No Published Applications for $Srv" -ForegroundColor Red
}
}
Write-Host
$process = @()
}
Process{
if($_){
if($_.ServerName)
{
$process += $_.ServerName
}
else
{
$process += $_
}
}
}
End{
if($Server){$Process += $Server}
foreach($s in $process){
cUnPublish $s
Write-Host
}
}
}
# Remove a Citrix App from Server
function Remove-CitrixApplication {
Param([string]$server,[string]$app)
Begin{
function RemoveApp {
Param([string]$Srv,[string]$myapp)
$AppRemoved = $false
$Srv = $Srv.toUpper()
$mfSrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
$mfSrv.Initialize(6,"$Srv")
If($mfSrv.Applications.Count -gt 0)
{
ForEach($a in $mfSrv.Applications)
{
If($a.AppName -eq "$myapp")
{
Write-Host "Removing App [$myApp] from Server [$Srv]" -ForegroundColor Green
$a.RemoveServer($Srv)
$a.SaveData()
$AppRemoved = $true
}
}
}
else
{
Write-Host "No Applications Published for $Srv" -ForegroundColor Red
$AppRemoved = $true
}
If($AppRemoved -eq $false)
{
Write-Host "This Application not Published for $Srv" -ForegroundColor Red
}
}
Write-Host
$process = @()
}
Process{
if($_)
{
if($_.ServerName){
$process += $_.ServerName
}
else
{
$process += $_
}
}
}
End{
if($Server){$Process += $Server}
if($process.Length -eq 0){$Process += get-content env:COMPUTERNAME}
foreach($s in $process)
{
RemoveApp -Srv $s -myapp $app
Write-Host
}
}
}
# List Citrix Apps Published to Server
function Get-CitrixApplications {
Param([string]$Server)
Begin {
Write-Host
function cGetApps {
param([string]$srv)
$srv = $srv.ToUpper()
$mfsrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
$mfsrv.Initialize(6,"$srv")
Write-Host "SERVER $srv" -foregroundcolor Red
Write-Host "==================" -ForegroundColor Green
If($mfSrv.Applications.Count -gt 0) {
$mfSrv.Applications | %{Write-Host "Published: $($_.AppName.ToUpper())"}
}
else {
Write-Host "No Applications Published for $srv" -foregroundcolor white
}
}
$process = @()
}
Process{
if($_){
if($_.ServerName){
$process += $_.ServerName
}
else{
$process += $_
}
}
}
End {
if($Server){$Process += $Server}
foreach($s in $process){
cGetApps $s
Write-Host
}
}
}
# Return Current Terminal Server User Count
function Get-TSUserCount {
Param([string]$Server)
Begin{
function TsUserCount {
param([string]$srv)
$msg = "Checking For Users on Server [$srv]"
$msg = $msg.PadRight($pad)
Write-host $msg -ForegroundColor White
$msg = "==========================================="
$msg = $msg.PadRight($pad)
Write-host $msg -ForegroundColor gray
$msg = "Terminal Server User Count on Server "
$msg1 = "[$srv]"
$msg1 = $msg1.PadRight($pad)
$ts = Get-WmiObject Win32_PerfFormattedData_TermService_TerminalServices -ComputerName $srv
$count = $ts.activeSessions
If($count -eq 0)
{
Write-host "$msg [Users:$count]" -ForegroundColor Green
}
else
{
Write-host "$msg [Users:$count]" -ForegroundColor Yellow
}
}
$process = @()
}
Process{
if($_){
if($_.ServerName)
{
$process += $_.ServerName
}
else
{
$process += $_
}
}
}
End{
if($Server){$Process += $Server}
if($process.Length -eq 0){$Process += get-content env:COMPUTERNAME}
foreach($s in $process)
{
TSUserCount $s
Write-Host
}
}
}
Farm functions
————–
Get-CitrixFarm
Get-CitrixOnline
Get-CitrixLE
Get-CitrixPrintDrivers
Get-CitrixPolicies
App functions
————–
Get-ApplicationUserCount
Find-CitrixUser
Get-CitrixServers
Get-CitrixAppUsers
Server functions
————–
Get-CitrixServer
Publish-CitrixApplication
UnPublish-CitrixServer
Remove-CitrixApplication
Get-CitrixApplications
Get-TSUserCount
tshell :: Sep.27.2007 :: All, Citrix, HowTo, Powershell, Scripting, functions :: 14 Comments »

[...] http://bsonposh.com/modules/wordpress/?p=47 Enjoy ! [...]
[...] Citrix, Citrix, and more Citrix! Brandon Shell has gifted us with a veritable cornucopia of sixteen (16!) Citrix management functions such as: [...]
I’ve been trying to get the unpublish-citrix server function to work. I have the code above exactly as written but I always get an error when it gets to $a.RemoveServer($Srv). I’ve looked at all the blogs and I can find no solutions that work! Any suggestions?
I would glad to help. Can you provide the error? If you would like you could PM me and we can take the problem offline. I will post our results in a new post.
I bashed my head on unpublish-citrix for a while, then discovered a missing $a.LoadData(1) while stepping through the code in Powershell. Thanks for the great scripts!
I apologize for that. I have some later post that address that, but I did not back port that. It is a 3.0+ issue.
Hi
I’m interested to manage Citrix session policies with Powershell, but I’m a donkey on script and powershell ( as in english ), so be patient.
I want to list all session printers , linked to a session policy, but the best that I did was the list of policy name, starting from one of your script. Yes is not so much!
I tried to use sessionpolicies2, sessionpolicies3 , but nothing is shown.
How I can exctract sesion printers informations from a session printer policies ?
Thank’s
#
#
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)
#
$pol | %{$_.LoadData($true)}
#
Try something like this
$mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy}
Great , with this I ‘ve the value of “Prinetrconnections” with the Session Printer name, used by the session printer policy.
So …
Policy is a property of Farm object . SessionPolicy is a property of Policy object, and is a system object so I ‘ve to load data of this property to show the content, correct ?
But now how can I put everything together ? I want to list for every session policy with the linked “Prinetrconnections” and other information.
How can I link the policy with the related Printerconnections ?
Thanks 10000
I am not sure I follow you completely, but it sounds correct.
“But now how can I put everything together ?”
I think you could do a simple where-object and foreach loop for this.
$mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy} | where{$_.Prinetrconnections}
First of all, thanks for your attention and patience !
The problem is:
If I executed the script ( see below ) nothing is displayed.
If I change this line
$mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy} | where{$_.Prinetrconnections}
in $mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy} | select Prinetrconnections
I obtain the list of Printerconnections
PrinterConnections
——————
{SPAN147}
{SPAN155}
{SPBO064}
{SPAN148}
{SPAN156}
{PR_CO02}
{PR_CO05}
{SPCO082}
{PR_GE02}
If I change the line
$mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy} | where{$_.Prinetrconnections}
in $pol | select name, description, allowedaccounts
I obtain the list of policies with the properties requested ( name,description,allowed accounts)
name Description AllowedAccounts printer
—- ———– —————
\\PRINT01\SPAN147 Printers Promoted:\\PRINT01\SPAN147 {SPAN147}
\\PRINT01\SPAN155 Printers Promoted:\\PRINT01\SPAN155 {SPAN155}
\\PRINT01\SPBO064 Printers Promoted:\\PRINT01\SPBO064 {SPBO064}
\\PRINT02\SPAN148 Printers Promoted:\\PRINT02\SPAN148 {SPAN148}
\\PRINT02\SPAN156 Printers Promoted:\\PRINT02\SPAN156 {SPAN156}
\\PRINT02\PR_CO02 Printers Promoted:\\PRINT02\PR_CO02 {PR_CO02}
\\PRINT02\PR_CO05 Printers Promoted:\\PRINT02\PR_CO05 {PR_CO05}
\\PRINT02\SPCO082 Printers Promoted:\\PRINT02\SPCO082 {SPCO082}
\\PRINT02\PR_GE02 Printers Promoted:\\PRINT02\PR_GE02 {PR_GE02}
What I need is a list of policies with some properties (name, description, allowedaccounts ) AND the related printerconnetions for each policy
Like this
name Description AllowedAccounts printercon
\\PRINT01\SPAN147 Printers Promoted:\\PRINT01\SPAN147 {SPAN147} XXXXXX
\\PRINT01\SPAN155 Printers Promoted:\\PRINT01\SPAN155 {SPAN155} XXXXXX
\\PRINT01\SPBO064 Printers Promoted:\\PRINT01\SPBO064 {SPBO064} XXXXXX
\\PRINT02\SPAN148 Printers Promoted:\\PRINT02\SPAN148 {SPAN148} xXXXXX
\\PRINT02\SPAN156 Printers Promoted:\\PRINT02\SPAN156 {SPAN156} XXXXXX
\\PRINT02\PR_CO02 Printers Promoted:\\PRINT02\PR_CO02 {PR_CO02} XXXXXX
\\PRINT02\PR_CO05 Printers Promoted:\\PRINT02\PR_CO05 {PR_CO05} XXXXXX
\\PRINT02\SPCO082 Printers Promoted:\\PRINT02\SPCO082 {SPCO082} XXXXXX
\\PRINT02\PR_GE02 Printers Promoted:\\PRINT02\PR_GE02 {PR_GE02} XXXXXX
———————————————-
script brutally copied from blog
———————————————-
#
# 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)
$pol | %{$_.LoadData($true)}
$mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy} | where{$_.Prinetrconnections}
“I think you could do a simple where-object and foreach loop for this.”
simple for you but …. not for me
I tried to build a foreach loopo starting from one of your scripts. I obtained the script below, but the result was not exactly I need.
+ Name: \\PRINT01\SPAN147
- Description: Printers Promoted:\\PRINT01\SPAN147
- accounts: SPAN147
- Printer: System.__ComObject
+ Name: \\PRINT01\SPAN155
- Description: Printers Promoted:\\PRINT01\SPAN155
- accounts: SPAN155
- Printer: System.__ComObject
+ Name: \\PRINT01\SPBO064
- Description: Printers Promoted:\\PRINT01\SPBO064
- accounts: SPBO064
- Printer: System.__ComObject
———————————————- the script —————————————–
$MetaFrameUnknownObject = 0
#
$MetaFrameWinFarmObject = 1
#
# param($Server)
function Load-Farm{
param($srv)
$type = [System.Type]::GetTypeFromProgID(”MetaframeCOM.MetaframeFarm”,$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
$farm = Load-Farm $server
$type = [System.Type]::GetTypeFromProgID(”MetaFrameCOM.MetaFrameUserPolicy”)
#$type = [System.Type]::GetTypeFromProgID(”MetaframeCOM.MetaframeFarm”,$Server)
foreach($pol in $Farm.policies($type))
{
$pol.loadData(1)
# $mfarm.Policies(0) | %{$_.LoadData(1);$_.SessionPolicy}
“+ Name: {0}” -f $pol.Name
” - Description: {0}” -f $pol.Description
if($pol.AllowedAccounts)
{
foreach($aa in $pol.AllowedAccounts)
{
” - accounts: {0}” -f $aa.AccountName
}
}
foreach($aa in $pol.SessionPolicy)
{
” - Printer: {0}” -f $aa.printerconnections
}
}
Does this get you want your looking for?
$MetaFrameUnknownObject = 0
$MetaFrameWinFarmObject = 1
function Load-Farm{
param($srv)
$type = [System.Type]::GetTypeFromProgID(”MetaframeCOM.MetaframeFarm”,$srv)
$mfarm = [system.Activator]::CreateInstance($type)
$mfarm.Initialize(1)
return $mFarm
}
$farm = Load-Farm $server
$type = [System.Type]::GetTypeFromProgID(”MetaFrameCOM.MetaFrameUserPolicy”)
foreach($pol in $Farm.policies($type))
{
$pol.loadData(1)
“+ Name: {0}” -f $pol.Name
” - Description: {0}” -f $pol.Description
if($pol.AllowedAccounts)
{
foreach($aa in $pol.AllowedAccounts)
{
” - accounts: {0}” -f $aa.AccountName
}
}
foreach($aa in $pol.SessionPolicy)
{
$value = $aa.printerconnections
” - Printer: {0}” -f ($aa.PrinterConnections | %{$_.PrinterName})
}
}
Oooh yess
Exactly . Many Thanks!
Thank you for your patience