• Profile picture of Curtis Smith

    Curtis Smith replied to the topic -websession in the forum General PowerShell Q&A 1 week ago

    Here is a more complete example using two functions.  The variable gets set in one function and is returned to the script.  The script then passes the returned value into the second function as a parameter.
    Function e {
    $evar = “Variable Set in Function E”
    “`$evar inside of Function E: $evar” | Out-Host
    $evar
    }

    Function f {
    Par…[Read more]

  • Profile picture of Curtis Smith

    Curtis Smith replied to the topic -websession in the forum General PowerShell Q&A 1 week ago

    Here is a sample of the problem

    Function a {
    $aVar = “FunctionA”
    “Output in function: $avar” | Out-Host
    }

    a

    “Output outside of function: $avar” | Out-Host

    Results:
    Output in function: FunctionA
    Output outside of function:

    The most appropriate way to handle it is to return the value from the function.

    Function b {
    $bVar =…[Read more]

  • Profile picture of Curtis Smith

    Curtis Smith replied to the topic -websession in the forum General PowerShell Q&A 1 week, 1 day ago

    It’s a variable scoping issue.  Your login variable only exists within the loginToRAPID() function.  It is not returned, and it is does not have a global or script scope, so when the loginToRAPID() function ends, the $login variable that was set within the function goes away.  When you subsequently call the uploadXML() function and try to use t…[Read more]