我有大约300台非现场PC(Windows 7 PC,Powershell 1.0版 - 所以"删除 - 打印机"不是一个选项),它有许多"复制"打印机(感谢Microsoft在制作" Copy&#34时的无限帮助;每次我的用户更改端口时)我都需要删除。我永远不知道有多少"复制"有打印机,所以到目前为止我已经提出了这个代码来删除除最近的打印机以外的所有打印机(无论有多少"复制"有打印机) -
#GET LIST OF PRINTERS
Get-WMIObject -Class Win32_Printer | Select Name > StorePrinters.txt
#GET ALL "Lexmark" PRINTERS
Select-String StorePrinters.txt -Pattern "Lexmark" | ForEach-Object {$_.Line} > CopyPrinters.txt
#GET ALL "Lexmark Universal v2 PS3" PRINTERS
Select-String CopyPrinters.txt -Pattern "PS3" | ForEach-Object {$_.Line} > CopyLexmarkPrinters.txt
#SORT THE Lexmark Universal v2 PS3" PRINTERS
Get-Content CopyLexmarkPrinters.txt | Sort-Object > LexmarkSorted.txt
#GET NUMBER OF Lexmark PRINTERS, THEN DELETE ALL BUT THE MOST RECENT COPY
$LEXlines = Get-Content LexmarkSorted.txt | Measure-Object -line | Select-Object -expand Lines
Get-Content LexmarkSorted.txt -totalcount ($LEXlines - 1) | ForEach-Object
{
cd C:\Windows\System32\Printing_Admin_Scripts\en-US
Write-Host "cscript prnmngr.vbs -d -p `"$_`""
cmd /c "cscript prnmngr.vbs -d -p `"$_`""
cd \Support
}
当我尝试运行它时,会弹出一个带
的框" cmdlet ForEach-object在命令管道位置2 - 供应值..." (被切断)
"步骤[0]"
并期待投入。我在这里做错了什么?