Solved

How to call a function taking two string parameters

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

12 Experts available now in Live!

Get 1:1 Help Now