Link to home
Start Free TrialLog in
Avatar of taartero
taartero

asked on

Adding error codes to a VBS that needs to run from SCCM

The script I need help with is below. I am going to create a package that will run while a user is logged on that is a vbs script that will remove printers that match entries in the 'cases' in the script and then add the appropriate printer on a new server.

SCCM will report a successful error code as soon as the script executes. What I need are lines of code in the script that will report if the script actually replaced a printer; or if the script failed to run.

It would be even better if the script code could tell me which printers were replaced as well.


Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
    WScript.Echo oPrinters.Item(i+1)
    Select Case (oPrinters.Item(i+1))


        Case "\\SERVER01\printer01":
            wshnetwork.removeprinterconnection oprinters.item(i+1), true, true

        Case "\\SERVER01\printer02":
            wshnetwork.removeprinterconnection oprinters.item(i+1), true, true
            wshnetwork.addwindowsprinterconnection "\\newSERVER01\printeraa"

        Case "\\SERVER01\printer03":
            wshnetwork.removeprinterconnection oprinters.item(i+1), true, true
            wshnetwork.addwindowsprinterconnection "\\newSERVER01\printerab"
     End Select
Next
ASKER CERTIFIED SOLUTION
Avatar of merowinger
merowinger
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of taartero
taartero

ASKER

does SCCM pick all those up, or does SCCM only recognize certain numbers?
as i know everything except of 0 is an error when not executing a msi package
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems like a code limitation