Maybe i need a pair of fresh eyes on that:
i use the following code in a .bat file in order to call a Powershell script which accepts 2 parameters.And i want to pass the same parameters in a function which is the Powershell script.The problem is that i cannot seperate the 2 parameters inside the function.Here is the code inside the .bat file :
@ECHO OFf
Set OUTFILE="C:\users\XXX\desktop\newchangepass\log.txt"
echo user='%1' pass='%2' >> %OUTFILE%
echo %1 %2
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -File "C:\ps\CallMeWithParams.ps1" %1 %2
That's what i give to the command line:
c:\PS>CallMeWithParams.bat Alpha Beta
and here is the code inside the Powershell script:
param ([Parameter (Mandatory)]$param1, [Parameter(Mandatory)]$param2 )
function foo{
param ($fusername,$fpassword)
write-output $fusername
}
foo($param1,$param2)
The output which i receive obviously in CMD is:
c:\PS>CallMeWithParams.bat Alpha Beta
Alpha Beta
Alpha
Beta
i should get only the first parameter....
The code inside the PS script is there for test reasons.I want to be sure that i get the two parameters and that i can seperate them in order to use the second one in an update statement.
Any suggestion would be greatly appreciated. PS1: Yes the CMD arguments will be enclosed in double quotes PS2: atm there is no control on variable types etc. I wanted to keep it simple for debugging reasons.