我有一臺打印服務器,大約有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