0
votes

I have a Powershell script that loads some functions that I have created from a .psm1 file. The .psm1 contains functions that should reutrn a value. All of them work fine apaprt from the example below.

The function generates a url and passes it back but it is always null even though the url is being generated correctly when debugging.

An example:

From the main script I import the .psm1 using the import-module cmdlet and call the following function ($environment variable is set):

Get-ApiUrl $environment

The function it calls is:

function Get-ApiUrl ($environment)
{
    $apiUrl = "https://test$environment.example.com/api/"
    return $apiUrl
}

When this runs the $apiUrl is being set correctly but when returned to the script that called the function it is blank. Does anybody understand what i'm doing wrong?

1
You don't appear to be using the return value of Get-ApiUrl (as in, $apiUrl = Get-ApiUrl .... - Jeroen Mostert
Perfect! So if I change the initial call to: $apiUrl = Get-ApiUrl $environment it works. The only strange thing is that I do the same as my original post with the next function and it works perfectly. - darren25

1 Answers

0
votes

Works when changing initial call to $apiUrl = Get-ApiUrl $environment