#Help Logging Script Result

4 messages · Page 1 of 1 (latest)

austere maple
#

Hello, I hope one of you may be able to help me record the status of some of the functions.

So I essentially have the function test do something like add a user, depending on the result ie exception or nothing then the script updates the value of $Test_result under the $result object.

However when running $print_results the output is just the array and empty strings.

Should I just do $result.Test_Result = “success” to update it?

Function print_results{
Write-Host $result

}

function Test{

Try{
Some code
$Script:Test_Result = “Success”
}
Catch{
Some code
$Script:Test_Result = “Failure”

}

}

$result = [PSCustomObject]@{‘Test’ = $Test_Result;}

gusty flicker
#

The question is a little unclear but I think what you're looking for is for the test function to return back to the primary. I took what you had and did a little scratch refactor to demonstrate both paths. There are other cheeky shortcut ways to get returns back but I prefer to be explicit

austere maple
#

Thank you very much

fair stump