Author Posts

March 12, 2018 at 8:39 pm

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"


2) 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 "

March 12, 2018 at 8:42 pm

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.

March 12, 2018 at 9:55 pm

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?

March 12, 2018 at 10:03 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!

March 12, 2018 at 10:06 pm

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

March 12, 2018 at 10:07 pm

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, if you need to send something that you don't want to be public, provided it isn't a technical assistance issue.

March 12, 2018 at 10:08 pm

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