我有一台打印服务器,大约有50台打印机安装了各种驱动程序,并不是所有配置都设置相同。我正在将打印机转移到基于新IP架构的新IP地址,并且我需要跟踪每台打印机,旧IP和新IP。然后,我需要捕获每个配置的现有配置,以便我可以添加打印机并保持设置与以前相同。PowerShell脚本抛出错误,但仍然产生结果
所以,这是情况。我用下面的:
PS C:\Users\a> Get-Printer | Where-Object -Property Name -match seattle | Get-PrintConfiguration
输出是:
Get-PrintConfiguration : An error occurred while performing the specified operation. See the error details for more information.
At line:1 char:60
+ Get-Printer | Where-Object -Property Name -match seattle | Get-PrintConfiguratio ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration) [Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x8000ffff,Get-PrintConfiguration
Get-PrintConfiguration : An error occurred while performing the specified operation. See the error details for more information.
At line:1 char:60
+ Get-Printer | Where-Object -Property Name -match seattle | Get-PrintConfiguratio ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_PrinterConfiguration:ROOT/StandardCi...erConfiguration) [Get-PrintConfiguration], CimException
+ FullyQualifiedErrorId : HRESULT 0x8000ffff,Get-PrintConfiguration
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
Seattle_Coun... False True OneSided
SeattleWhsLaser True True OneSided
Seattle Ware... False False OneSided
Seattle_Seco... True False OneSided
Seattle_Test... True True OneSided
SeattleCoun True True OneSided
Seattle - SH... True True OneSided
如果我缩短该行:
PS C:\Users\a> Get-Printer | Where-Object -Property Name -match $city
输出是所有9台打印机如我所料:
Name ComputerName Type DriverName PortName Shared Published
---- ------------ ---- ---------- -------- ------ ---------
Seattle_Test_Printer-Seattl... Local HP Universal Printing PS 192.168.100.25 True True
Seattle_Second_Floor Local HP Universal Printing ... IP_192.168.1... True True
Seattle_Counter_Laser Local HP Universal Printing ... IP_192.168.1... True False
SeattleWhsLaser Local HP Universal Printing ... 192.168.100.82 True True
SeattleCoun Local HP Universal Printing ... IP_192.168.1... True True
Seattle Warehouse ZDesigner... Local ZDesigner 110XiIII Plu... 192.168.100.... True True
Seattle Upstairs OKI PCL6 C... Local OKI PCL6 Class Driver 192.168.100.14 True True
Seattle - SHARP MX-5141N PCL6 Local SHARP MX-5141N PCL6 192.168.100.30 True False
Seattle (new) HP LaserJet P... Local HP LaserJet P3011/P301... 192.168.100.25 True True
我应该总共获得9台打印机,但我不明白为什么我得到2台打印机的错误,并为其余的获得好的结果?最终目标是使其自动化并记录所有更改。
当你手动对其中一个运行它时,你能够获得配置设置吗?就像'Get-PrintConfiguration -PrinterName'西雅图(新)HP LaserJet Printer''(您可能需要修复名称,它在您的问题中被截断,所以我刚刚猜到) – TheMadTechnician
实际上没有,但那确实让我发现了我总共有12台打印机,但有9台显示在PS上。在所显示的9个中,缺少的2个似乎错过了他们的驱动程序,因此清除了这些。 (1)我至少有两台打印机没有安装完整的驱动程序(但人们仍然可以打印到它们)(2)我看到12台打印机用于打印此分支mgr(3)失踪3台打印机正常运行。现在我真的很困惑。 @TheMadTechnician – brehma
您可以尝试调用CIM方法直接拉取配置,例如'Get-CimInstance -ClassName MSFT_Printer -Namespace'ROOT/StandardCimv2'|%{Invoke-CimMethod -ClassName MSFT_PrinterConfiguration -Namespace'ROOT/StandardCimv2'-MethodName GetByPrinterName -Arguments @ {'PrinterName'= $ _。Name} |%cmdletOutput}'看看是否有更多的结果。 – TheMadTechnician