0

尝试在 VDI 环境中为基于位置的打印编写脚本。登录到 VDI 会话后,网络打印机将根据客户端(瘦/零客户端)IP(使用 GPO)进行映射。根据该打印机名称(即“PRN-Printer1”),我需要将文件从共享(\Server\share\printer1)复制到本地 c:\drive\location。对于“PRN-Printer2”,它将从\Server\share\printer2 等复制。

我找到了一些用于检查 reg 密钥的脚本和另一个用于复制文件的脚本,但我需要一些帮助来将它们放在一起。我不是脚本专家,但我可以通过一些衬里摸索。

任何帮助将不胜感激!!!

这是我到目前为止...

检查注册表(不确定这是查找密钥的最佳方式)

reg query HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers  /f "PRN-" /t REG_SZ /s /k  | find "Name"

或者

pushd;sl HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers; if(test-path PRN-){--???--}ELSE{"Printer does not exist"};popd

复制文件:

ls "C:\drive\location" -r -i * | % {cp -force $_ ($_ -replace "c:\\drive\\location", "\\Server\share1")}

或者

Copy-Item \\Server\Share\printer1\* C:\drive\location\

不确定如何将此逻辑放在一起或在注册表中检查此打印机的最佳方式,因为 VDI 会话中可能有多个打印机。

基本上,我需要一些东西:

如果 reg key (HCLM..) 是“PRN-printer1”,则将文件 \Server\share\printer1 复制到 c:\drive\location else... 检查打印机 2....printer3...等。 ..

请帮忙!谢谢!

4

1 回答 1

0

You can use Get-Item to get list of all printers and store it in a variable $printername

$printername=(Get-Item "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Printers\*").pschildname

Heres what you will have in $printername

PRN-printer1
PRN-printer2
PRN-printer3

Now for each $printer in $printername you can execute below script to copy files based on printer

ForEach($printer in $printername) {

if ($p -match  "PRN-printer1")

{
Copy-Item "\\Server\Share\printer1\*" "C:\drive\location"

}

elseif ($p -match  "PRN-printer1")

{

Copy-Item "\\Server\Share\printer2\*" "C:\drive\location"

}

elseif ($p -match  "PRN-printer1")

{

Copy-Item "\\Server\Share\printer2\*" "C:\drive\location"

}

}
于 2012-11-12T13:34:56.313 回答