简体   繁体   English

从计算机PowerShell列表中获取打印机驱动程序列表

[英]Get List of Printer Drivers from list of Computers PowerShell

I've tried a variety of iterations of this and gotten a range of errors. 我尝试了各种迭代,并遇到了一系列错误。 I'm trying to get aa list of installed drivers off from a list of computers. 我正在尝试从计算机列表中获取已安装的驱动程序列表。 None of the ways I've tried in PowerShell have piped the information into a csv. 我在PowerShell中尝试过的任何方法都没有将信息通过管道传输到csv中。 Here's the current iteration of the script. 这是脚本的当前迭代。

#Load Active Directory 
Import-Module activedirectory
#Load list of computers
$results = @()
$Computer = Get-Content -path 'C:\ScriptResources\computers.txt'

#Check each computer in the list 
foreach($ComputerName in $Computer)
    {
    $results += Get-ADComputer -Filter " Name -Like '*$ComputerName*' " | Get-PrinterDriver; Start-Sleep -milliseconds 500 
    } 

#Export to CSV file
$results | export-csv 'C:\ScriptResults\InstalledPrinters.csv'

I've also used it with just the Get-Printer command and got the following error. 我也仅将它与Get-Printer命令一起使用,并收到以下错误。

Get-Printer : No MSFT_Printer objects found with property 'Name' equal to 'Redacted'.  Verify the value of the
property and retry.

Depending what I've fed the $Computer file I'll get different errors. 根据我给$ Computer文件提供的内容,我将得到不同的错误。 I've also gotten the RPC server is unavailable and Error Spooler Service Not Running. 我还得到了RPC服务器不可用和错误后台处理程序服务未运行的信息。 I have domain wide privileges and I checked the print spooler service and it is running. 我具有域范围的特权,并且我检查了后台打印程序服务,该服务正在运行。

The reason I think this is odd is that I have .bat tool that I use that gets printer info from a singular host and I don't run into any issues. 我认为这很奇怪的原因是,我使用的.bat工具可以从单个主机获取打印机信息,而且不会遇到任何问题。 The reason I'm trying to put this in PowerShell is because 1) I want to do the whole domain and 2) PowerShell formats its outputs in a more useable fashion. 之所以尝试将其放入PowerShell中,是因为1)我想做整个域,以及2)PowerShell以更有用的方式格式化其输出。

wmic /node:%ComputerIP% path win32_printer get deviceid, drivername, portname

Additionally, I've also tried the following in the $results function of the script 此外,我还在脚本的$ results函数中尝试了以下操作

$results += Get-WmiObject -class Win32_printer -ComputerName name, systemName, shareName

This didn't give errors. 这没有给出错误。 What it did instead is that for each computer in the list of computers it checked the computer I was running the script from for its printers and output on each line which printers were installed on my computer. 相反,它对计算机列表中的每台计算机都检查了我正在为其打印机运行脚本的计算机,并在每行上输出了我的计算机上安装了哪些打印机。

I'm at a loss and any help would be appreciated. 我不知所措,任何帮助将不胜感激。 Thanks! 谢谢!

Just so this is closed out. 就是这样,这是封闭的。 Vivek's answer ended up working. Vivek的答案最终奏效了。

$results += Get-WmiObject -class Win32_printer -ComputerName $Computer | Select name, systemName, shareName

The RPC issue I was getting was that the list of computers were all turned off for some reason (remote site + different time zone + doing the testing during second shift). 我遇到的RPC问题是计算机列表由于某种原因(远程站点+不同时区+在第二班期间进行测试)而全部关闭。 Normally, everything remains on though. 通常情况下,一切仍然保持。 So that was just an anomaly. 所以那只是一个异常。

Thanks for the help! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM