Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Win32_printer and cross check with csv file and delete printer Zero clients

$
0
0

I am getting the mac address of the zero client and then importing a csv. from there i filter out all records from the printers list that don't match with the mac address. After the printers are found I match it to the WMI win32_printer query. Then i want to delete the printers that matched but i cannot get it to work right.

#Get the client MAC ADDRESS and assign it to a variable

$NIC = Get-ItemProperty 'HKCU:\Volatile Environment' | Select-Object -ExpandProperty ViewClient_MAC_Address

 

#import the list of computers/printers from the CSV file. Assign it to a variable

$printers = Import-CSV \\vpc275\c$\MyScripts\Printers.csv

 #filter out all records from the printers list that don't match with the MAC

$p = $printers | Where-Object {$_.'MAC' -eq $NIC}

#Delete printers found

$WMI = Get-WMIObject Win32_Printer | where {$_.Name -eq $p.'Printer location'} | foreach{$_.delete()}

I am new to powershell sorry if i do not make sense. Also do yall know any easy way to have error handling, like if the mac address is not found the write to log file what happend or if it cannot remove the printer due to printer in use or something along those lines.

csv headers 

MAC        Printer name     Printer location             DefaultPrinter

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles