0

I've been trying to call a Powershell script with multi params from an C# ASP.NET file in the following way.

string exe = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe";
string template = @"-File {0} -macList{1} -version {2} -server {3}";
string file = @" E:\TestmanagerFor3.7.ps1";
string maclist = "MAC1,MAC2";
string version = "4.0";
string server = "xxx.xxx.xxx.xx";
string parameters = String.Format(template, file, macList, version, server);
Process.Start(exe, parameters);

(Please note that here I have two inputs for the macList)

But while running, this is taking MAC1,MAC2 as a single param only. Here's the parameter list of Testman.ps1:

Param
(
[Parameter(Mandatory=$True,Position=1)]
[String[]]$macList,
[Parameter(Mandatory=$True,Position=2)]
[String]$version,
[Parameter(Mandatory=$True,Position=3)]
[String]$server
) 

Please help me fixing this issue.

Thanks in advance,

/Aravind

1 Answer 1

1

Take a look at the answer to this question: Scheduled Task for PowerShell Script with String Array Parameter

It suggests changing using the -Command switch instead of the -File switch, and then use the invocation operator '&'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.