I have a script that is running in PowerShell 7 (for better Unicode support) and I need to run a certain batch of commands in PowerShell 5 due to some DLL incompatibility. This means (afaik) I can't use dot sourcing.
PowerShell 7 calling code: `
$files = powershell.exe -ExecutionPolicy Bypass -File "$PSScriptRoot\FileInfo.ps1" -Path $FolderToProcess -Title $moduleTitle -GUID $guid
FileInfo.ps1
loops through a set of files and returns an array of PSCustomObject
$arr = @()
foreach ($file in $finalFiles) {
$item = [PSCustomObject]@{
i = $file.i
j = $file.j
k = $file.k
}
$arr += $item
}
return $arr
However, what happens when I try to use the $files
variable in the calling script, is that the result of the called script is actually an array of strings and is useless.
How do I either:
A) Tell the calling script that the result of the script should be an array; or
B) Have the 'sending' script not process the result as a string and pass back an array as expected?