Here is my scenario.
I have a main script we will call “Main.PS1”
This script loads a module we will call “Functions.PSM1”
Main.PS1 calls a function in Functions.PSM1 called “function get-stuff()”
The Get-Stuff function then calls a third party powershell scirpt and provides parameters through a hash table. Here is the sanitized relevent code:
$ExternalScript = 'C:\Path\To\ExternalScript.ps1'
$PSExe = (Get-Process -Id $pid).Path
$ScriptArgs = @{
'Arg1' = "Console"
'Arg2' = $Stuff
'Arg3' = 0
'Arg4' = 'YadaYada'
'Arg5' = $MoreStuff
}
I then call the script as follows:
$objExternalStuff = & $PSExe -Command $ExternaScript @ScriptArgs
This all works just fine, no errors and $ExternalScript runs fine with the arguments provided and generates the expected external output. However, $ExternalScript ALSO returns a dictionary object that I can use/parse in function Get-STuff(), however $objExternalStuff does not contain any useful data. I have NO control over $ExternalScript. If I create a simple Script.PS1 with the relevant code, all is well with both the external output and dictionary object returned from $ExternalScript so somehow my scoping is messed up which leads me to believe there is a correct way to do this. I have asked AI and nothing it provided worked.
If i do a simple test:
if($objExternalStuff -is [System.Object]) {Write-Host "I am an object"}
It reports that it is indeed an object. But when I try to parse the keys in the dictionary object, I get nothing.
Any help is appreciated. I hope I have explained this with enough detail.