functions/remote/Get-TaskAccount.ps1

function Get-TaskAccount {
    [CmdletBinding()]
    param (
        [switch]
        $AsHashtable,

        [Parameter(ValueFromPipeline = $true)]
        [PSFComputer[]]
        $ComputerName,

        [string]
        $OU,

        [string]
        $Filter = '*',

        [string]
        $Server,

        [pscredential]
        $Credential
    )
    begin {
        $targets = [System.Collections.ArrayList]::new()
        if ($OU) {
            $parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include OU, Filter, Server, Credential
            foreach ($computer in Resolve-Computer @parameters) {
                $null = $targets.Add($computer)
            }
        }

        $scriptblock = [scriptblock]::Create((Get-Command Get-LocalTaskAccount).Definition)
    }
    process {
        foreach ($computer in $ComputerName) {
            $null = $targets.Add($computer)
        }
    }
    end {
        $results = Invoke-PSFCommand -ComputerName $targets -ScriptBlock $scriptblock
        if (-not $AsHashtable) { return $results }

        $hash = @{}
        foreach ($resultGroup in $results | Group-Object ComputerName) {
            $hash[$resultGroup.Name] = $resultGroup.Group
        }
        $hash
    }
}