2

I am an administrator and learning about scripts but was trying to create a script to open multiple programs as another user (my admin password)

The following script runs well when run from powershell ise but won't run properly when right clicking and selecting "run with powershell"

Start-Process -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Credential "domain\userid"

When run it prompts for password but doesn't bring up google chrome. It works OK when run from Powershell ISE and I get error "The directory name is invalid" when running the script from Powershell.exe (not the ISE environment).

6
  • unable to reproduce the issue on my windows server 2012 with powershell 4.0. The command works the same in my powershell console & powershell ISE Commented Apr 22, 2016 at 16:43
  • If you run start-process -filepath c:\asdfasdf\asdf.exe the error which comes back is "This command cannot be run due to the error: The system cannot find the file specified", not "The directory name is invalid". I guess this is either in the configuration of your context menu "Run with PowerShell", maybe it has an invalid path to the PowerShell interpreter, or the PowerShell.exe process can't read the path to your script (but I can't reproduce that error here with some quick testing). Is the error a PowerShell exception or an Explorer dialog box? Commented Apr 22, 2016 at 18:04
  • What if you were to execute it in this fashion from the RUN menu or even a cmd prompt? Same directory name is invalid message? powershell.exe -nop "C:\path to your script.ps1" Commented Apr 22, 2016 at 18:56
  • ssaviers - that worked but ideally I would to be able to double click a batch file or just right click on the powershell file and run the file. Tessheck - it's that full error message you suggested, tried to screenshot but don't think you can on this forum, it shows this on powershell when I tried to run it from there:- I did this to troubleshoot it further but don't understand why I'm getting this error when directory is correct and tried running with policy unrestricted and remote signed. Commented Apr 24, 2016 at 11:51
  • Seems to have something to do with my admin rights, cmd as admin worked ok but issue replicated when i run it in command prompt without admin Commented Apr 24, 2016 at 11:58

1 Answer 1

5

Add the working directory:

Start-Process `
    -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" `
    -Credential "domain\userid" `
    -WorkingDirectory "C:\Program Files (x86)\Google\Chrome\Application\"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.