I've been trying to run Windows PowerShell scripts from a CMD with some parameters.
I've tried things like:
powershell -c ".\Test-Param.ps1 param1 param2"
powershell -c ".\Test-Param.ps1 -P1 param1 -P2 param2"
powershell -File ".\Test-Param.ps1 param1 param2"
This is the code I want to execute:
function Test-Param
{
[CmdletBinding()] Param(
[Parameter(Position = 0, Mandatory = $True)]
[String]
$P1,
[Parameter(Position = 1, Mandatory = $True)]
[String]
$P2
)
echo "Script has been executed!!!"
echo "Params: $P1,$P2\n"
}
I expect (P1="apple", P2="cherry"):
Script has been executed!!!
Params: apple,cherry