I have this in a powershell
if (Test-Path env:\names)
{
[string[]] $names= (dir env:\names).Value.Split(",") | % { $_.Trim() }
} else {
[string[]] $names= "peter","mikael","Anders","William"
}
Write-Host -n "names: " ; [string]$names
If I would like to call it from command prompt is that possible?
I have tried this:
powershell -ExecutionPolicy RemoteSigned -File MainScript.ps1 -PARAM "Peter,Mikael"
I do understand that wont work since I am looking for a env:names but how can I make it work? What I am after is that I would like to send in a parameter with names and that should be caught in something like the code above.
You have a complete mess here. First
env:namesmeans value of environment variablenames, there shouldn’t be\.Then, if you want you script to accept parameters – just add
param(string[] $names)as first line of your scriptIf you want to run your script with parameters – just start powershell and type:
full_path_to_script Peter,Mikael