[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 808
  • Last Modified:

How to call a function taking two string parameters

When I try to call the Do-Something function with two string arguments, both arguments are passed to the first parameter as an array.

What am I doing wrong?
param( [String[]]$names )

function Main {
    foreach ($n in $names) {
	Do-Something $n, "asdfa"
    }
}

function Do-Something([string]$param1,$param2) {
    $param1
}

. Main

Open in new window

0
jmdion
Asked:
jmdion
  • 2
1 Solution
 
sjklein42Commented:
Nix the comma

	Do-Something $n "asdfa"

Open in new window

0
 
KenMcFCommented:
Try this

Do-Something "$($n), asdfa"

Or if you need the quotes around asdfa try this

$ch34 = [CHAR]34
Do-Something "$n, $($ch34)asdfa$($ch34)"  
 
0
 
sjklein42Commented:
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now