Solved

How to call a function taking two string parameters

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now