i understand that the subject line looks too mundane and there are posts addressing many such questions. I did not find what i was exactly looking for and hence this post.
I am invoking a powershell file from machine A to be executed on a remote machine(machine B).
//here is the code snippet:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
string scripttext = "$secpasswd = ConvertTo-SecureString '222_bbbb' -AsPlainText –Force";
string scripttext1 = "$mycreds = New-object -typename System.Management.Automation.PSCredential('TS-TEST-09\\Administrator',$secpasswd)";
string scripttext2 = "$s = New-PSSession -ComputerName TS-TEST-09 -Credential $mycreds";
**string scripttext5 = "Invoke-Command -Session $s -FilePath 'helper.ps1' | out-null";**
pipeline.Commands.AddScript(scripttext);
pipeline.Commands.AddScript(scripttext1);
pipeline.Commands.AddScript(scripttext2);
pipeline.Commands.AddScript(scripttext5);
Collection<PSObject> results = pipeline.Invoke();
now in line string scripttext5 = "Invoke-Command -Session $s -FilePath 'helper.ps1' | out-null"; i have to pass a few parameters(for example, username from c# environment : useralias) to this helper.ps1 file for processing. can any one guide me to a correct method of doing so?
TIA, Manish