PowerCLI

 View Only
  • 1.  How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 03:30 PM

    I'm new to using Powershell and would like to ask a basic question with regards to executing a powershell script. Basically, I've written a batch file as shown below.

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "C:\MyScripts\RunSpanshot.ps1"

    I execute the batch file and nothing seems to happen. What is wrong with trying to execute the RunSpanshot.ps1 script as shown above? - any help is appreciated.

    Thanks



  • 2.  RE: How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 03:43 PM

    Is the PowerC LI snapin loaded ?

    You could do that through one of the profile files.

    You could do a simple test from a CMD window.

    Launch this and check if you get any results

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "Get-ViToolkitVersion"
    

    And I suspect the execution policy is set up correctly in the client.

    Perhaps check with

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "Get-ExecutionPolicy"
    



  • 3.  RE: How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 04:11 PM

    Lucd, the cli is version 4 and the execution policy is remotesigned.

    I've now got the script working so thanks for your help.

    One more question - if the script was moved to a folder such as "c:\my scripts\RunSpanshot.ps1" i.e. with spaces in the path name - what change must be made to the below sting to execute the script?

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "C:\My Scripts\RunSpanshot.ps1"



  • 4.  RE: How to execute a Powershell script via a batch file
    Best Answer

    Posted Oct 02, 2009 04:37 PM

    You could do

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "& 'C:\My Scripts\RunSpanshot.ps1'"
    



  • 5.  RE: How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 04:43 PM

    Lucd, worked like a dream - Thanks.



  • 6.  RE: How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 05:27 PM

    I am having an issue trying to run my script and I keep getting an error. So I saw this and tried it and mine does not work! I get the following error for those two tests;

    Failed to load Windows PowerShell console file "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1". WIN 32 error: The system cannot find the path specified.

    and the samething for the second one as well. Any ideas? Thanks.

    Thank you,

    Express



  • 7.  RE: How to execute a Powershell script via a batch file

    Posted Oct 02, 2009 06:33 PM

    Could you perhaps show us your command itself (or a screenshot of the line) ?