Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am updating an old DOS script which is used to open a Windows PPTP VPN connection between two server, copy some files, then close the connection. I am wanting to rewrite the script in powershell, so I will be able to send an e-mail to notify users if anything goes wrong with the copy.

The current code is as follows

rasdial connectionName UserName Password
if not %errorlevel% == 0 goto vpn

When I try to use rasdial in powershell, it opens a new window, and powershell doesn't have access to %errorlevel% or $lastexitcode.

Is there a way to have powershell open rasdial in the same window? If not, is there a different utility I can use to open a VPN connection?

Thank you

share|improve this question
up vote 5 down vote accepted

This is how you get the exit code:

(Start-Process rasdial -NoNewWindow -ArgumentList "connectionName UserName Password" -PassThru -Wait).ExitCode
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.