src/Organization/Get-XrmOrganization.ps1

<#
    .SYNOPSIS
    Get Organization object.

    .DESCRIPTION
    Retrieve default organization record from target instance.

    .PARAMETER XrmClient
    Xrm connector initialized to target instance. Use latest one by default. (Dataverse ServiceClient)

    .PARAMETER Columns
    Specify expected columns to retrieve. (Default : all columns)

    .OUTPUTS
    PSCustomObject. The organization row (see Get-XrmMultipleRecords).

    .EXAMPLE
    $organization = Get-XrmOrganization -XrmClient $xrmClient -Columns "name", "languagecode";
    $organization.name;

    .LINK
    https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Get-XrmOrganization.md
#>

function Get-XrmOrganization {
    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        [Microsoft.PowerPlatform.Dataverse.Client.ServiceClient]
        $XrmClient = $Global:XrmClient,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [String[]]
        $Columns = @("*")
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {
        $query = New-XrmQueryExpression -LogicalName "organization" -Columns $Columns -TopCount 1;
        $results = $XrmClient | Get-XrmMultipleRecords -Query $query;

        $organization = $results | Select-Object -First 1;
        $organization;
    }
    end {
        $StopWatch.Stop();
        Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

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