0

Powershell script (win10)

function eineFunction($meinHost, $meinPass){  
    Write-Host $meinHost "--"  
    Write-Host $meinPass "--"  
}  

$MeineHosts=(  
    ("host1", "pass1"),  
     ("host2", "pass2")  
   )  
  
clear  
foreach($row in $MeineHosts){  
    Write-Host $row[0]  
    Write-Host $row[1]   
    eineFunction($row[0], $row[1])  
    }  

Output:

host1   
pass1   
host1 pass1 --  
--   
host2   
pass2  
host2 pass2 --  

Output wanted:

host1   
pass1   
host1 --   
pass1 --   
host2   
pass2   
host2 --  
pass2 --  

What am I doing wrong?
Thanks

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented May 5, 2022 at 15:48

1 Answer 1

3

Functions in PowerShell should be called without parens – they behave like commands. For example:

eineFunction $row[0] $row[1]

If you use ($row[0], $row[1]), this actually creates a new 2-item list that'll be passed as the first parameter – and nothing as the second parameter.

2
  • Thanks. Perfectly clear. That did the trick. Commented May 6, 2022 at 6:43
  • The "," has to go. Params should be "space" separated Commented May 6, 2022 at 6:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .