returnVar2Output.psm1

$FunctionScriptName = "returnVar2Output"
Write-Verbose "Import-Start| [$($FunctionScriptName)]"

function returnVar2Output {
    [cmdletbinding()]
    param(
        [Parameter()]$returnVar,
        [parameter(ValueFromPipeline)]$pipe
    )
    Begin {
        $SelfIdentifier = "returnVar2Output"
        Write-Debug "[$($SelfIdentifier)] Start"   

        $return = @{ }
        $return.exportVars = @( )
        $return.rawoutput_all = @( )
        $return.rawoutput_direct = @( )   
    }
    Process {
        if ($returnVar) { $pipe = $returnVar }

        $pipe | ForEach-Object {
            $return.exportVars += $_
            if ($_ -like "all*") { 
                $return.exportVars += Get-Variable -Name $_ -ValueOnly 
                $return.rawoutput_all += "- [$($_)] with [$((Get-Variable -Name $_ -ValueOnly).count)] nested variables"
            }
            else {
                $directvalue = Get-Variable -Name $_ -ValueOnly
                $directcount = if($directvalue.RowKey) { ($directvalue.Rowkey).count } else { $directvalue.count } #? separation due to false counting
                $return.rawoutput_direct += "- [$($_)] with [$($directcount)] direct values"
            }
        }
    }
    End {
        if (($return.exportVars).count -eq 0 -or !$return.exportVars) { Write-Error "[$($SelfIdentifier)] Nothing could be mapped var!" }
        Write-Debug "[$($SelfIdentifier)] End"
        
        return $return
    }   
} #v1.0

Export-ModuleMember -Function *
Write-Verbose "Import-END| [$($FunctionScriptName)]"