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

Currently this is my path for launching VMware vSphere PowerCLI command prompt. I wish to run my sample.ps1 script automatically using a batch file. How can I incoporate sample.ps1 into this path and create a batch file?

 -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c 
 ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""
share|improve this question
up vote 2 down vote accepted

What you would want to do is to replace the end of command where it calls out to Initialize-PowerCLIEnvironment.ps1 and replace that with the path to your sample.ps1 file.

You will almost certainly need to have the first line of your sample file be the original reference to Initialize-PowerCLIEnvironment.ps1 such that the initialization code (most likely function/cmdlet definitions) is run prior to any of your code that may depend on it.

For example, the contents of your sample.ps1 file would look something like this:

# source vSphere PowerCLI Environment first
. "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
# custom code follows
$me = "Hello, vSphere and PowerCLI!!!"
share|improve this answer
echo off

Title,Sample Script &color 9e

for /f "usebackq delims=$" %%a in (`cd`) do (
  set SCRIPTDIR=%%a

(Set ScriptFile=%SCRIPTDIR%\Sample.ps1)

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\";%ScriptFile%"
share|improve this answer
While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill Sep 30 '15 at 17:59

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.