Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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'm trying to make a PowerShell script to launch programs after I boot up my machine. I'm taking things out of the registry's "run" area and putting them in the script in the order that I want and after inserting some delays for items that are not important to run immediately. This is the code to start Outlook for instance:

# Outlook
Start-Sleep -s 10
Invoke-Item "c:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"

That works for paths that do not have a switch, but I can't get it to work if there is a switch involved. For example this is the launch command for Windows Live Messenger:

c:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe /background

So the spaces also cause some problems. I've tried this:

#Start-Sleep -s 10
$test= {"c:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe"}
Invoke-Item $test /background

but that doesn't work either.

Any ideas?

share|improve this question
up vote 0 down vote accepted

Use Invoke-Expression :

#Start-Sleep -s 10
$test= "c:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe /background"
Invoke-Expression $test 
share|improve this answer

Hi someone on Twitter helped me find the solution.

I don't need the Invoke-Item command at all and I did try without it at first, but starting with an ampersand worked. So, my line should have been:

& 'c:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe' /background

Hope that helps someone else in future as I couldn't find much online.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .