Maybe I'm not understanding your problem. Or maybe there's something in the functions' code you haven't disclosed. Either way, I don't experience the problem:
This is how I invoked the function:
# just some dummy tenants for testing
$t = [PSCustomObject]@{Name = '111'},
[PSCustomObject]@{Name = '222'}
. c:\junk\fa.ps1 # dot-source the function
$r = a $t # pass the tenants to function "a"
# walk through the returned hash in the 1st element of the returned array
$r[0].GetEnumerator()|foreach-object{
"Name is: $($_.Key)`tPassword is: $($_.Value)"
}
# Do the same for the returned array in the 2nd position
Foreach ($e in $r[1]){
"Tenant is: $($e.Name)"
}
Here's the function:
function a{
[CmdletBinding()]
param (
[PSCustomObject[]]
$Tenants
)
$UiDict=@{}
$TenantInfo=@()
FOREACH($Tenant in $Tenants)
{
$Account_to_seek="Z$($Tenant.name)"
#TRY{$TenantPW=Get-CC $Account_to_seek -BypassUserCheck TRUE} CATCH {}
[string]$TenantPW = Get-Random # don't have an actual tenant, so provide a random password
IF(![string]::IsNullOrWhiteSpace($TenantPW))
{
$UiDict."$($Tenant.Name)" = "$Account_to_seek/$tenantPw"
$TenantInfo+=$Tenant
}
}
Return $UiDict,$TenantInfo
}
And here's the result of processing the value returned from the function:
PS C:\Junk> . 'C:\Junk\Untitled-4.ps1'
Name is: 111 Password is: Z111/568345342
Name is: 222 Password is: Z222/1677127922
Tenant is: 111
Tenant is: 222