我需要使用以P0开头的打印机名称来命名所有打印机
我是PowerShell的新手,get-printer命令不支持我的过滤语法。我的输出变量为空。
我已经尝试过过滤命令结果,并尝试使用所有打印机过滤results变量的内容,但都没有成功。
$PrinterList = Get-Printer -ComputerName "PrintServer" -Filter {name -like 'P0'}或
$PrinterList = Get-Printer -ComputerName "PrintServer"
$PrinterSort = $PrinterList.Name | Where-Object {$PrinterList.Name -Like "P0"}发布于 2019-05-14 17:27:14
根据另一个答案,您需要在字符串中包含一个或多个wildcard characters (例如,*表示0个或多个字符,?表示单个字符)。
您还可以简化代码,直接在cmdlet的-Name参数中使用通配符:
$PrinterList = Get-Printer -ComputerName "PrintServer" -Name "P0*"发布于 2019-05-14 17:22:56
您的-like需要一个通配符,例如name -like 'P0*'
这应该适用于您的两个解决方案。
https://stackoverflow.com/questions/56126905
复制相似问题