Answered $variable.Start()

  • Tuesday, January 29, 2013 11:05 PM
     
     

    I am new to scripting and to Windows Powershell, but I really want to learn about it.

    Since I am trying to get a particular job done for my employer, I don't have time to currently plow through all of the tutorials and basics. I will do that at a later time.

    I'm trying to simplify an excessively complex script to handle my specific task. Right now the script tries to do just about everything except brew the coffee.

    I've been able to isolate a function that I believe has all of what I need to accomplish, and way more.

    At the last lines of the function it has:

    $variable = <functionname> and then a list of parameters that are used by the function

    $ReturnValue = $variable.Start()

    I get an error in ISE that states: "You cannot call a method on a null-valued expression."

    I can see that there is nothing between the parentheses, but this is in the original code. I've been googling all day and have not been able to find an explanation for the $variable.Start().

    Am I missing something that should have been included in the code before this line?

    I understand what a function is. In the really-old days we used to call them subroutines. They are very powerful for accomplishing repetitive tasks.

    I've also seen other statements that include $variable.<something>, and I'm confused about what that is about.

    I hope that you will all take pity on this lowly newbie. I'm desparately trying to figure this out. But, alas, I need some help.

    TIA for your assistance.

    Nadine H

All Replies

  • Tuesday, January 29, 2013 11:08 PM
    Moderator
     
     Proposed

    Hi,

    $variable.Start() means "for the object stored in $variable, invoke its Start method."

    If $variable is $NULL, you will see the error message "You cannot call a method on a null-valued expression."

    Bill

  • Tuesday, January 29, 2013 11:21 PM
     
     

    Okay, I don't see how it can be null. The line before it sets it equal to the function with all it parameters.

    $variable = <functionname> and its list of parameters

    Is this not the way to call the function?

    Does that mean that the function is not "functioning?" ie not returning a value to $variable?

    Nadine H

  • Wednesday, January 30, 2013 12:35 AM
    Moderator
     
     

    It's impossible to guess what the code is doing without seeing it.

    Bill

  • Tuesday, February 12, 2013 1:57 PM
    Moderator
     
     Answered

    Okay, I don't see how it can be null. The line before it sets it equal to the function with all it parameters.

    $variable = <functionname> and its list of parameters

    Is this not the way to call the function?

    Does that mean that the function is not "functioning?" ie not returning a value to $variable?

    Nadine H

    It appears that the function name is not working right.  If you have:

    $variable = functionname  <parameters>

    Try try avoiding the variable and just type:

    functionname  <parameters> and

    functionname  <parameters> | Get-Member

    That helps tell what the function is doing (or not doing).


    Thomas Lee <DoctorDNS@Gmail.Com>