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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.