Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to call a function taking two string parameters

Posted on 2011-03-05
3
781 Views
Last Modified: 2012-05-11
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
Comment
Question by:jmdion
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 35045026
Nix the comma

	Do-Something $n "asdfa"

Open in new window

0
 
LVL 27

Expert Comment

by:KenMcF
ID: 35045051
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
 
LVL 16

Expert Comment

by:sjklein42
ID: 35045064
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question