1

I'm running a powershell script that has a mandatory variable from within another powershell script.

The script starts with:

function functionName([Parameter(Mandatory=$true)] [string] $deployVM

So when running this script on it's own I get prompted for the $deployVM parameter.

When I run this script from within another script and can't figure out how to pass this in automatically so that I don't get prompted. I've tried many ways (a few examples below) but get prompted every time:

./script.ps1 -deployVM "vmname"

./script.ps1 "vmname"

./script.ps1 -deployVM vmname

./script.ps1 vmname

Invoke-Expression -Command script.ps1 vmname

Invoke-Expression -Command script.ps1 "vmname"

Does anybody have any suggestions as to what i'm doing wrong?

Many thanks

darren25
  • 275
  • 1
  • 5
  • 16
  • Your script defines function with parameters, but you call script not function. At least, show how function called. – user4003407 May 11 '16 at 12:43
  • The function is called by adding the function name to the bottom of the script. I've also tried putting the variable name next to this so that it is passed in to the function but I still get prompted. – darren25 May 11 '16 at 12:52

0 Answers0