![공유 프린터가 있는 경우 제거하는 powershell 스크립트](https://rvso.com/image/789283/%EA%B3%B5%EC%9C%A0%20%ED%94%84%EB%A6%B0%ED%84%B0%EA%B0%80%20%EC%9E%88%EB%8A%94%20%EA%B2%BD%EC%9A%B0%20%EC%A0%9C%EA%B1%B0%ED%95%98%EB%8A%94%20powershell%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8.png)
물어봐서 미안하지만 이걸 얻으려면 도움이 필요해요. \server\printer와 같은 많은 컴퓨터에 일부 프린터가 설치되어 있습니다. Powershell 스크립트로 제거하려고 생각했지만 완료할 수 없습니다. 나는 다음과 같이 생각하고있었습니다.
$printers=Get-Printer | where { $_.Type -eq 'Connection'} | select name /* this part show me only \\server\printers */
$printers | ForEach-Object {
if ($printers) {
Remove-Printer -Name $printers -Confirm:$false
}
}
모두에게 감사드립니다.
답변1
이는 전체 프린터 목록을 Remove-Printer cmdlet에 제공하기 때문입니다. 한 번에 하나의 프린터를 제공해야 합니다.
[...]
Remove-Printer -Name $printers -Confirm:$false
# Error here------------/\
[...]
foreach 루프 내부에 있으면 $PSItem
또는 짧은 별칭을 사용하여 현재 프린터를 가져올 수 있습니다 $_
.
$PSItem
(및 $_
)는 "ForEach 루프의 현재 개체"를 의미합니다.
이것은 작동합니다:
$printers=Get-Printer | where { $_.Type -eq 'Connection'} | select name /* this part show me only \\server\printers */
$printers | ForEach-Object {
if ($_) {
Remove-Printer -Name $_.Name -Confirm:$false
}
}