Hi,
I am working with an external scheduling application. It allows launching command line scripts. I have written a ps1 script which creates a new VM Guest. I would like to be able to call this script - CreateVM.ps1 from the scheduling application however I am not sure of the command line to use. Launching Powershell is not a problem, however this will lauch the normal Powershell which does not give me access to the PowerCLI commands. Does anyone know how to launch a PowerCLI ps1 script from a DOS prompt of from a BAT file?
Many thanks,
Ben
You can either add the snapin on the first line of the script:
Add-PSSnapin VMware.VimAutomation.Core
or use the following to run your script:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" " & "C:\CreateVM.ps1
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
You can either add the snapin on the first line of the script:
Add-PSSnapin VMware.VimAutomation.Core
or use the following to run your script:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" " & "C:\CreateVM.ps1
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
Hi Alan,
thanks for the swift answer. I've chosen to use Add-PSSnapin VMware.VimAutomation.Core
Regards,
Ben
many thanks for the command line info - of course, now that Vmware has rebranded PowerCLI as part of vSphere the command line should read:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" " & "C:\somescript.ps1
Regards, Roger
http://[www.thehypervisor.com|http://www.thehypervisor.com]
Hi alan
I am sorry but i am new with PowerCLI
I am trying and trying again and again the 2 ways you suggested and nothing happens, i am getting an error that "Add-PSSnapin VMware.VimAutomation.Core" is not familiar command.i want to run the script i wrote for reverting a snapshot and it's working great when i run it from sphere powerCLI manually, but i want to run it with batch file, i have tried the second way
"C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile
"C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" " & "C:\CreateVM.ps1
"VIToolkitForWindows" this folder does not exist on my system so i switched it with "vSphere PowerCLI" and i get an error: see attached file
I dont know what to do please advise me what next?!
Thank you
Haim
Hi Haim,
Running your script from a batch file should work with the next commandline:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{c:\CreateVM.ps1}"
Regards, Robert
The Get-VIServer cmdlet is an old alias that is not present in PowerCLI 4.1.
Replace it with a Connect-VIServer cmdlet.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD
I use PowerCLI 4.0 but for some reason your suggestion work for me, thank you very much i really appreciate your help
Thanks
Haim
The Get-VIServer alias was already gone in PowerCLI 4
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am also new to PowerCLI. I've written some commands that work fine from the PowerCLI window interactively, but not from a .cmd file. This thread has helped to point me in the right direction.
Rather than using the -command switch, mine worked when I used the -file switch.
I found this by going to "C\Windows\System32\WindowsPowershell\v1.0 and running powershell.exe /? > textfile.txt
This produced a text file with all of the switches.
Hope this helps. Thanks again for all of the contributors. I've looked at some of the books available, but couldn't find any that dealt with the basics like getting stuff to work from the command line. They seem to all dive right into scripts and functions.