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
taarteroAsked:
Who is Participating?
 
merowingerCommented:
if you execute wscript.quit(X) where X is the error return code you can send an error code back
e.g.

cscript.exe myscript.vbs
echo %ERRORLEVEL%
0
 
taarteroAuthor Commented:
does SCCM pick all those up, or does SCCM only recognize certain numbers?
0
 
merowingerCommented:
as i know everything except of 0 is an error when not executing a msi package
0
 
JonLambertCommented:
One old-school way to get custom status reporting of SCCM packages/programs is to uses Status MIF files (they still work in SCCM) .. Otherwise if the VB Script returns any value except 0, it will be considered to have failed.

http://technet.microsoft.com/en-us/library/cc180410.aspx
0
 
taarteroAuthor Commented:
Seems like a code limitation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.