Module/Administration/Get-BCSAppStatusForServerInstance.ps1

<#
.SYNOPSIS
 
.DESCRIPTION
 
.EXAMPLE
 
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
#>

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

    process {
        Import-BCSDynamicsNavModules -ServerInstance $serverInstance

        $tenants = Get-NAVAppTenant -ServerInstance $ServerInstance | Select-Object -Property Id;

        $appsHash = [PSCustomObject]@();

        foreach ($tenant in $tenants) {
            $apps = Get-NAVAppInfo -ServerInstance $ServerInstance -Tenant $tenant.Id -TenantSpecificProperties | Where-Object Name -eq $AppName

            foreach ($app in $apps) {
                $NameVersion = ("{0}{1}" -f $app.Name, $app.Version);

                $item = New-Object PSObject
                $item | Add-Member -type NoteProperty -Name 'ServerInstance' -Value $ServerInstance;
                $item | Add-Member -type NoteProperty -Name 'BCVersion' -Value $ServerInstanceVersion;
                $item | Add-Member -type NoteProperty -Name 'Tenant' -Value $tenant.Id
                $item | Add-Member -type NoteProperty -Name 'Name' -Value $app.Name
                $item | Add-Member -type NoteProperty -Name 'Publisher' -Value $app.Publisher
                $item | Add-Member -type NoteProperty -Name 'Version' -Value $app.Version
                $item | Add-Member -type NoteProperty -Name 'Scope' -Value $app.Scope
                $item | Add-Member -type NoteProperty -Name 'IsInstalled' -Value $app.IsInstalled
                $item | Add-Member -type NoteProperty -Name 'IsPublished' -Value $app.IsPublished
                $item | Add-Member -type NoteProperty -Name 'SyncState' -Value $app.SyncState
                $item | Add-Member -type NoteProperty -Name 'NameVersion' -Value $NameVersion
                $item | Add-Member -type NoteProperty -Name 'AppID' -Value $app.AppId

                $appsHash += $item;
            }
        }

        $appsHash
    }

    end {
    }
}

Export-ModuleMember -Function Get-BCSAppStatusForServerInstance