Solved

How to call a function taking two string parameters

Posted on 2011-03-05
3
773 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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