Functions/Query/Views/Get-CdsRecordsFromView.ps1

<#
    .SYNOPSIS
    Retrieve records from a view
#>

function Get-CdsRecordsFromView {
    [CmdletBinding()]
    param
    (        
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.Xrm.Tooling.Connector.CrmServiceClient]
        $CdsClient = $Global:CdsClient,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $EntityLogicalName,      

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $ViewName
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {
          
        $selectedView = Get-CdsViews -EntityLogicalName $EntityLogicalName -Columns "name", "layoutxml", "fetchxml" | Where-Object -Property "name" -EQ $ViewName;
        $fetchQuery = Get-CdsQueryFromFetch -FetchXml $selectedView.fetchxml;
        $records = Get-CdsMultipleRecords -Query $fetchQuery;
        $records;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Get-CdsRecordsFromView -Alias *;

Register-ArgumentCompleter -CommandName New-CdsQueryExpression -ParameterName "EntityLogicalName" -ScriptBlock {

    param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)

    $validLogicalNames = Get-CdsEntitiesLogicalName;
    return $validLogicalNames | Where-Object { $_ -like "$wordToComplete*"};
}

Register-ArgumentCompleter -CommandName Get-CdsRecordsFromView -ParameterName "ViewName" -ScriptBlock {

    param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)

    $viewsNames = @();
    if (-not ($fakeBoundParameters.ContainsKey("EntityLogicalName"))) {
        return $viewsNames;
    }
    $views = Get-CdsViews -EntityLogicalName $fakeBoundParameters.EntityLogicalName -Columns "name";
    $views | ForEach-Object { $viewsNames += $_.name };
    return $viewsNames | Where-Object { $_ -like "$wordToComplete*" } | Sort-Object;
}