LoginSignup
3
9

More than 1 year has passed since last update.

[PowerShell]不要なプリンタの削除

Last updated at Posted at 2017-12-25

[PowerShell]不要なプリンタの削除

経緯

社内の機種がFuji XeroxからRicohへ変更となったたため、不要なプリンタを削除したいのだが、設置場所によってプリンタ名が異なるため、プリンタドライバ名を元にプリンタを削除したかったので作成。

Powershellコマンド

Windows 10


# プリンタドライバ名
$DriverName = "FX ApeosPort-IV C7780"

# プリンタの取得
$List = Get-Printer | Where-Object DriverName -match $DriverName

# 削除するプリンタのドライバ機種のみ削除
foreach($item in $List)
{
    Remove-Printer -Name $item.Name
}

# プリンタドライバ削除
Remove-PrinterDriver -Name $DriverName

# Windowsで通常使うプリンタを管理するのチェックを外す
$RegPath = "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"
$RegKey = "LegacyDefaultPrinterMode"
$RegKeyValue  = 1
Set-ItemProperty $RegPath -name $RegKey -Value $RegKeyValue

今回は、目的がドライバ名なので DriverName を使用していますが、状況によっては、Where-Object の指定を変えてあげれば、良いです。

「Windowsで通常使うプリンタを管理するのチェックを外す」理由としては、チェックオン状態では、最後に使用したプリンタが通常使うプリンタになってしまうためです。

WS000000504.JPG

Windows 8.1以下

# プリンタドライバ名
$DriverName = "FX ApeosPort-IV C7780"

# WMIプリンタオブジェクトのの取得
$List = Get-WmiObject Win32_Printer

# 削除するプリンタのドライバ機種のみを取得
$DeletePrinterList = $List | Where-Object DriverName -match $DriverName

# 削除する対象プリンタの削除
$DeletePrinterList.Delete();

Widows10出なければ、「Windowsで通常使うプリンタを管理する」がないので、レジストリ設定を省きました。
また、 WMIを使用して不要プリンタを削除しています。

3
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
9