Module/Administration/Get-BCSLicensedToPerServerInstance.ps1

<#
.SYNOPSIS
    Get BC tenant licens to value
.DESCRIPTION
    Get BC tenant licens to value for all tenants on a BC serverInstance
.EXAMPLE
 
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
#>

function Get-BCSLicensedToPerServerInstance {
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
        [string]$ServerInstance
    )
    begin {}

    process {
        Import-BCSDynamicsNavModules -ServerInstance $serverInstance

        $tenants = Get-NAVAppTenant -ServerInstance $serverInstance

        $appsHash = [PSCustomObject]@();

        foreach ($tenant in $tenants)
        {
            $license = Export-NAVServerLicenseInformation -ServerInstance $serverInstance -Tenant $tenant.Id

            $lineCount = 0;

            ForEach ($line in $($license -split "`r`n"))
            {
                $lineCount = $lineCount + 1;

                if ($lineCount -eq 5) {
                    $licensedTo = $Line.Substring(26,$line.Length - 26)
                }
            }

            $item = New-Object PSObject
            $item | Add-Member -type NoteProperty -Name 'tenantId' -Value $tenant.Id;
            $item | Add-Member -type NoteProperty -Name 'LicensedTo' -Value $licensedTo;

            $appsHash += $item;
        }

        $appsHash    }
    end {
    }
}

Export-ModuleMember -Function Get-BCSLicensedToPerServerInstance