VMware Cloud Community
hansis
Contributor
Contributor
Jump to solution

start batch with parameters

Hello!

This is my first powerCLI-Script.

I want to start a powerCLI-Script from Windows-Batch. And I have to commit the Skript a parameter ("1" or "0").

My test.bat-File:

%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Programme\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{C:\bat\USV\vmware\test.ps1}"

In test.ps1 I want to manage the commited parameters "0" and "1". But I don't know how.

Where can I set the parameters I want to commit?

Is this correct?

%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe  -PSConsoleFile "C:\Programme\VMware\Infrastructure\vSphere  PowerCLI\vim.psc1" -command "&{C:\bat\USV\vmware\test.ps1 parameter}"

thx

hansis

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Pass the parameters to the .ps1 file as you did in the 2nd line.

In the .ps1 file you can access the parameters in the $args array, i.e. $args[0], $args[1]...

Or you can have a Param statement at the beginning of your script and work with named parameters.

Param($argument1,$argument2)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Pass the parameters to the .ps1 file as you did in the 2nd line.

In the .ps1 file you can access the parameters in the $args array, i.e. $args[0], $args[1]...

Or you can have a Param statement at the beginning of your script and work with named parameters.

Param($argument1,$argument2)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
hansis
Contributor
Contributor
Jump to solution

thx.

hansi

0 Kudos