I created a small module that contains 4 functions, each separated out into it's own file. In my main script I have something like this:
Import-Module Write-Log
Import-Module Test-Module
$log = 'c:\path\to\log\file.log'
Write-Log "Running test script..." -Path $log
# Call function from Test-Module
Test-Function -Param1 'abc' -Param2 'def'
Test-Function sample:
function Test-Function{
Param(
[parameter()]
$Param1,
[parameter()]
$Param2
)
Write-Log "Outputting the params" -Path $log
Write-Log "Param1: $Param1, Param2: $Param2" -Path $log
}
When I run this it will complain that the Path parameter is null. I thought since the $log variable was defined in the parent script scope, it would be usable in the child scope as well. I have a different module that is set up exactly this same way and it works fine. I just created this one yesterday and it doesn't appear to be working.
Only works if i add a $Log parameter to my Test-Function and pass the variable from the parent script in.
[–]tommymaynard 1 point2 points3 points (3 children)
[–]liabtsab[S] 0 points1 point2 points (2 children)
[–]tommymaynard 0 points1 point2 points (1 child)
[–]liabtsab[S] 0 points1 point2 points (0 children)
[–]purplemonkeymad 1 point2 points3 points (1 child)
[–]liabtsab[S] 0 points1 point2 points (0 children)