powershell & citrix printer policy creation...

Status
Not open for further replies.

Mike Bridge

Ars Praefectus
3,748
Subscriptor++
i'm setting up our new citrix 6.5 enviroment (6.5 w/ rollup pack 1). of course, we need printer policies for the users. after our internal discussions, we're setting up 1 policy per printer (for each printer that has a matching security group in AD, 599 policies to be created*), and 1 policy per remote subnet (main office locations exempted, 188 total policies to create), so users at remote subnets will get their 'local' printers no matter what site they are at each day, and we can also guarantee certain printers are always available to certain users (check printers for AP, private printers for HR, etc). This is far too many policies to create by hand, so scripting via powershell will reduce the time required & risk of input errors.

I exported a list of print queue's from one of the load balanced print servers, used dsquery to confirm which printers had matching security groups, and then generated the powershell for each printer via an excel spreadsheet (yes, it could be done via a loop with an imported csv, but i wanted the individual lines available for documentation in the project folder).

setting up the policies for the individual printers filtered by security group is easy via citrix's powershell extension, these lines create the policy, apply a security group filter, and set the policies properties.
Code:
new-item LocalFarmGPO:\User\POLICYNAME
New-Item LocalFarmGpo:\User\POLICYNAME\Filters\User\SECURITYGROUP@DOMAIN
set-itemproperty LocalFarmGPO:\User\POLICYNAME\Settings\ICA\Printing\SessionPrinters -name values "\\PRINTSERVER\PRINTQUEUE"

removing the entire policy is also easy:
Code:
remove-item LocalFarmGPO:\User\POLICYNAME -recurse -Confirm:$false

if you are creating/modifying a lot of policies, executing
Code:
(Get-PSDrive LocalFarmGpo).AutoWriteBack = $false
before you interact with the policies and running
Code:
(Get-PSDrive LocalFarmGpo).Save()
(Get-PSDrive LocalFarmGpo).AutoWriteBack = $true
afterwards significantly improves the speed of execution & eliminates a nasty memory leak.

to setup the subnet based ones, a little bit of shenanigans are required, since a particular subnet (and thus a policy) might need more than 1 printer.

again, create the policy, set a subnet filter, but then store the current value of the session printers to a variable, append the new printer to the variable, and then set the value which will overwrite the current policy value with the updated value of the variable.
Code:
New-Item LocalFarmGPO:\User\POLICYNAME
New-Item LocalFarmGPO:\User\POLICYNAME\Filters\ClientIP\FILTERNAME -Value NETWORK/CIDR
$CurrentPolicyPrinters = Get-ItemProperty LocalFarmGPO:\User\POLICYNAME\Settings\ICA\Printing\SessionPrinters
$CurrentPolicyPrinters.Values += "\\PRINTSERVER\PRINTQUEUE"
Set-ItemProperty LocalFarmGPO:\User\POLICYNAME\Settings\ICA\Printing\SessionPrinters -name values $CurrentPolicyPrinters.Values

now if i could just figure out how to adjust policy priority via powershell instead of the GUI.

*we needed to apply GPCSExt170W2K8R2X64001 after creating this many policies, otherwise user sessions would time out during login, issue w/ Citrix CSE using excessive CPU when processing policies.
 

wseaton

Ars Scholae Palatinae
653
I know Mike is doing something cool here, just haven't quite put my head around it.

- why not just default the Citrix session to use the local Auto Created printer no matter what it is?

- how does one 'load balance' a print server, and why? Print Servers in a Citrix environment tend to be in one of two states; working fine, or pegging the CPU via spooler.exe because of driver issues. I don't even bother trying to load balance XenApp servers anymore via anything other than round robin, or maybe memory. Same with Terminal Server, which we all know Xenapp is 99% under the hood.

- Citrix UPD's work fine on paper, until the user can't get a function to work on their printer; duplex, color, stapling, etc. At that point you don't have many options other than use a dedicated driver.
 

afidel

Ars Legatus Legionis
18,433
Subscriptor
[url=http:/civis/viewtopic.php?p=24878351#p24878351:3nqhi8jb said:
wseaton[/url]":3nqhi8jb]I know Mike is doing something cool here, just haven't quite put my head around it.

- why not just default the Citrix session to use the local Auto Created printer no matter what it is?

- how does one 'load balance' a print server, and why? Print Servers in a Citrix environment tend to be in one of two states; working fine, or pegging the CPU via spooler.exe because of driver issues. I don't even bother trying to load balance XenApp servers anymore via anything other than round robin, or maybe memory. Same with Terminal Server, which we all know Xenapp is 99% under the hood.

- Citrix UPD's work fine on paper, until the user can't get a function to work on their printer; duplex, color, stapling, etc. At that point you don't have many options other than use a dedicated driver.
The client UPD allows any function the client can use because all it does is grab the EMF data from the app, compress it, and inject it into the clients print processor. Only a few percentage of printers don't work with it due to poor drivers and there's a workaround via registry to tell the client to submit the job as a new print job instead of skipping the first part of the print process like normal. Because it involves no driver code it means your servers spooler process never crashes or uses excessive cpu and you run no risk of crashing the box due to bad drivers. I've had essentially zero print issues on my fairly large xa 6 farm since we went all upd from the start with no addon drivers added.
 
[url=http:/civis/viewtopic.php?p=24878559#p24878559:1ckbfbg5 said:
afidel[/url]":1ckbfbg5]
[url=http:/civis/viewtopic.php?p=24878351#p24878351:1ckbfbg5 said:
wseaton[/url]":1ckbfbg5]I know Mike is doing something cool here, just haven't quite put my head around it.

- why not just default the Citrix session to use the local Auto Created printer no matter what it is?

- how does one 'load balance' a print server, and why? Print Servers in a Citrix environment tend to be in one of two states; working fine, or pegging the CPU via spooler.exe because of driver issues. I don't even bother trying to load balance XenApp servers anymore via anything other than round robin, or maybe memory. Same with Terminal Server, which we all know Xenapp is 99% under the hood.

- Citrix UPD's work fine on paper, until the user can't get a function to work on their printer; duplex, color, stapling, etc. At that point you don't have many options other than use a dedicated driver.
The client UPD allows any function the client can use because all it does is grab the EMF data from the app, compress it, and inject it into the clients print processor. Only a few percentage of printers don't work with it due to poor drivers and there's a workaround via registry to tell the client to submit the job as a new print job instead of skipping the first part of the print process like normal. Because it involves no driver code it means your servers spooler process never crashes or uses excessive cpu and you run no risk of crashing the box due to bad drivers. I've had essentially zero print issues on my fairly large xa 6 farm since we went all upd from the start with no addon drivers added.
Same here. We still have a decent sized 4.5 farm (~100 servers), and a small but growing 6.5 farm, but using 100% UPD and our amount of printing related issues has decreased dramatically.
 

afidel

Ars Legatus Legionis
18,433
Subscriptor
[url=http:/civis/viewtopic.php?p=24890197#p24890197:1tow3vbn said:
Mike Bridge[/url]":1tow3vbn]
[url=http:/civis/viewtopic.php?p=24874981#p24874981:1tow3vbn said:
afidel[/url]":1tow3vbn]Why?!? Use the client UPD!

thin clients & iPad's that travel to different locations each day?
For thin clients use the windows embedded ones, ipads is tougher but in my organization none of the ipad users has ever asked me for the ability to print.
 

Mike Bridge

Ars Praefectus
3,748
Subscriptor++
[url=http:/civis/viewtopic.php?p=24890457#p24890457:2r6r5czi said:
afidel[/url]":2r6r5czi]
[url=http:/civis/viewtopic.php?p=24890197#p24890197:2r6r5czi said:
Mike Bridge[/url]":2r6r5czi]
[url=http:/civis/viewtopic.php?p=24874981#p24874981:2r6r5czi said:
afidel[/url]":2r6r5czi]Why?!? Use the client UPD!

thin clients & iPad's that travel to different locations each day?
For thin clients use the windows embedded ones, ipads is tougher but in my organization none of the ipad users has ever asked me for the ability to print.

we're using linux based thin clients. the sales people have ipad's and need to print stuff.
 

ZPrime

Ars Legatus Legionis
18,847
Subscriptor++
[url=http:/civis/viewtopic.php?p=24890609#p24890609:ygv9wmy3 said:
Mike Bridge[/url]":ygv9wmy3]
we're using linux based thin clients.
This is a perfect example of cutting off your nose to spite your face... People try to "save money" and go cheap with Linux thin clients, but the tradeoff in CX/Win environment is that you end up fighting with shit like printers. Very happy that we have spent the money to do Win-Embedded thins instead.

the sales people have ipad's and need to print stuff.
I'm surprised you can trust sales people to even figure out an iPad... And they don't want to throw it through a window trying to use Citrix on it? I avoid trying to do anything more advanced than "Disable user X" with an iPad.
 

rfriesen

Seniorius Lurkius
1
Hi, Mike:

Thanks for posting this. I know it's a little old, but I hope you still watch this forum.

I'm trying to figure out how to set Citrix Printer Assignment policies. They are not like other policies. The path is:
\Settings\ICA\Printing\PrinterAssignments\Assignments

Then under that are objects numbers, so 1, 2, 3, etc.

And each of those has a Session Printers object and a Filters object. If you go into one of those (CD), you see it too has an index.
The SessionPrinters object there has properties for Path (e.g. \\printserver\printer) and model (print driver name). I have been unable to find a way to set those.

I can set the Filters (which are subnets masks or computer names with wildcards). Here is an example of how to set the value for a filter:
(get-item $index).value = "10.221.35.0/23"

The same thing for SessionPrinters usually gets some like "printer is not a valid printer UNC path." or "Could not find PSDrive for \\printserver"

I have tried using New-item. I have tried to create objects like you did above, but the objects won't let me change the values.
I have tried using something in this format: ("Path=\\printserver\printer,model=HP Universal Printing PCL 6 (v6.2.1),Location=")

BTW, the reason I am looking at this is the user interface for creating these is just stupidly bad.

I made a script that reads Printer Assignment policies (it finds any policy that has "print" in the name and checks for Printer Assignments):

asnp citrix*

Function Split-array ($Array, $hash, $Name)
{
#When WMI returns an array for a value, this splits into multiple single values so converting to CSV works
$i=1
$Array | %{
$NewValue = $Name+$i
$hash[$NewValue] = $_
$i++
}
$hash
}


#Connect PowerShell drive to Citrix domain GPO
New-PSDrive Site -PSProvider CitrixGroupPolicy -Root \ -Controller dpv-xen7ddc1 >null
cd 'Site:\user'

ls | where {$_.name -match "print"} | %{
(get-childitem ".\$($_.name)\Settings\ICA\printing\PrinterAssignments").contents
} | sort filters | %{
$hash =[ordered]@{}
$hash = Split-array $_.filters $hash "Filter"
$hash = Split-array ($_.Sessionprinters).path $hash "Printer"

$obj = New-Object -TypeName psobject -Property $hash
$obj | select filter1, filter2, printer1, printer2, printer3, printer4, printer5
}
 
Status
Not open for further replies.