I was also able to find a script that would loop through the printers and display the Port IP, which provides me with the data I need (printer port IP_192.168.1.44), but I was unable to figure out a way to extract this information to use for an if then statement to see if the ip port is mapped.
Set WshNetwork = CreateObject("WScript.Network") Set WSHPrinters = WSHNetwork.EnumPrinterConnections PrinterPath = "\\srv-04\HP4525" PrinterExists = False For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2 If WSHPrinters.Item(LOOP_COUNTER +1) = PrinterPath Then PrinterExists = True End If Next If PrinterExists = True Then WshNetwork.RemovePrinterConnection "\\srv-04\HP4525" End IF
Ideally I would be able to provide a variable for the printer port IP for the script to check against it and delete the printer or do nothing if it does not exist.
Set WshNetwork = WScript.CreateObject("WScript.Network") Set oDrives = WshNetwork.EnumNetworkDrives Set oPrinters = WshNetwork.EnumPrinterConnections WScript.Echo "Network drive mappings:" For i = 0 to oDrives.Count - 1 Step 2 WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) Next WScript.Echo WScript.Echo "Network printer mappings:" For i = 0 to oPrinters.Count - 1 Step 2 WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1) Next
From novice to tech pro — start learning today.