2

I am not sure what the heck I am doing wrong here but the code below return the following error message:

The term 'identityTest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Here is my sample/test code:

#Bunch of Global vars
$UrlToUse = identityTest

function identityTest
{
    $internalMatch = ".*inbound"
    $externalMatch = ".*outbound"
    $fqdn = "blahblah_inbound"

    if ( $fqdn -match $internalMatch )
    {
        return "http://in3"
        Write-Host "Inbound Hit"
    }
    if ( $fqdn -match $externalMatch )
    {
        return "http://out"
        Write-Host "Outbond Hit"
    }
    else
    {
        return "http://default"
        write-host "Default Hit"
    }
}    


function sampleTest
{
    write-host "will upload to the following URL: + $UrlToUse
}

Write-Host $UrlToUse

Not sure if I am taking the correct approach here but this is what I am trying to accomplish. I plan to set UrlToUse as a global variable depending on the result of the if statements in the indetityTest function which will determine and return the correct one. From there I will use the same global var throughout the rest of my code. An example that i created would using the same var $UrlToUse within another function, in this case name sampleTest.

I don't understand why this is not working. I come from a Perl background and might be confusing how things work in powershell. Any tips pointer etc would be really really appreciated.

Thanks a bunch!

1
  • Script files are read from top to bottom. Every object/script/function/etc. you reference have to be initialized earlier in the session or in the script. Commented Feb 22, 2013 at 14:44

1 Answer 1

1

Move the function identityTest before it is called. Like this:

function identityTest
{
    $internalMatch = ".*inbound"
    $externalMatch = ".*outbound"
    $fqdn = "blahblah_inbound"

    if ( $fqdn -match $internalMatch )
    {
        return "http://in3"
        Write-Host "Inbound Hit"
    }
    if ( $fqdn -match $externalMatch )
    {
        return "http://out"
        Write-Host "Outbond Hit"
    }
    else
    {
        return "http://default"
        write-host "Default Hit"
    }
}    

#Bunch of Global vars
$UrlToUse = identityTest



function sampleTest
{
    write-host "will upload to the following URL: + $UrlToUse"
}

Write-Host $UrlToUse
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that worked. Didn't realize that the function order mattered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.