learning the "param" - i dont get it

i’ve tried to learn it already two days and unfotinatly, i’m not getting something write

i watched lots of videos and read lots of articales and still don’t get it

so i need your help

i’ve tried two difreint scripts through the “function” parameter

first is a very very basic and the second one is abit less basic and i dont’ understand what is the problem

  1. script which is worked:
function my-test {
    write-host "i did a $test"

  1. second script which is not working:
function net-test {
    $levspc = "computername"

    Read-Host "what is the computer name?"

    param (Test-Connection -computername $levspc -Count 1)

    write-host "the $levspc is alive "

It might be worth reading something like “Learn PowerShell Scripting in a Month of Lunches,” which goes over this in pretty gory detail.

Param() blocks must be the first thing defined inside the function. In the second example, you didn’t do that, and so the block is ignored.


param (Test-Connection -computername $levspc -Count 1)

That is not a parameter definition. That is executable code. A parameter is a “placeholder” (a variable, really) for a piece of information that you want input into your script or function. That’s not what you’ve done here. Aside from a ValidationScript(), which is a bit of a more advanced topic, parameter blocks aren’t executable code. They’re definitions, or declarations, of inputs that the script or function can accept.

i got it !!

function net-test {

    param ($computername1,
    $computername2 )

    Test-Connection $computername1, $computername2 |Format-Table -AutoSize

Thanks alot !
PS: is there any way to send you a PM?

We don’t support private messaging on the site; it’s been a problem in the past what with spammers and all. And, because of my job, I’m not allowed to provide private consulting or assistance, so it’s easier to have that turned off for me.

Glad you got it working!

it’s not for assistance or support
if you will read this post and delete it, i will gladly write it here

Sure, but Google hits our site almost constantly, so I can’t guarantee that a post will be deleted before they cache it. You can also use the “HMU” menu item on DonJones.com, if you need to send something that you don’t want to be public, provided it isn’t a technical assistance issue.

ok, you’ll get it there in a few minutes