VMware Cloud Community
jconry
Contributor
Contributor
Jump to solution

Run PowerShell script from cmd

Hi there,

I'm trying to run a powershell script from a cmd file with the VMware snapin added. Here's what I'm trying to run:

PowerShell.exe -noexit Add-PSSnapin VMware.VimAutomation.Core | k:\work\DeployVM.ps1

It adds the snapin, but then launches the ps1 in notepad which is obviously not what I'm after. I'm sure it's something simple that I'm missing, but I just can't get it. The reason why I want to run it this way is to associate it with a vb button, I've got everything else sorted, just this last bit I need to finish it off.

Cheers,

Josh

0 Kudos
1 Solution

Accepted Solutions
alanrenouf
VMware Employee
VMware Employee
Jump to solution

If there is a reason you are not adding the Add-PSSnapin VMware.VimAutomation.Core as the first line of your script then you can run it as below:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" " & "C:\MyScript.ps1

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

http://virtu-al.net

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com

View solution in original post

0 Kudos
2 Replies
alanrenouf
VMware Employee
VMware Employee
Jump to solution

If there is a reason you are not adding the Add-PSSnapin VMware.VimAutomation.Core as the first line of your script then you can run it as below:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" " & "C:\MyScript.ps1

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

http://virtu-al.net

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
jconry
Contributor
Contributor
Jump to solution

Worked like a charm.

Thanks for that.

0 Kudos