Module/BusinessCentral/Get-BCSServerInstances.ps1

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

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

    process {
        if ([string]::IsNullOrEmpty($serverInstance)) {
            Import-BCSDynamicsNavModules
            $instances = Get-NAVServerInstance
        } else {
            Import-BCSDynamicsNavModules -ServerInstance $serverInstance
            $instances = Get-NAVServerInstance $ServerInstance
        }

        $Hash = [PSCustomObject]@();

        foreach ($instance in $instances) {
            $item = New-Object PSObject
            $item | Add-Member -type NoteProperty -Name 'ServerInstance' -Value $instance.ServerInstance;
            $item | Add-Member -type NoteProperty -Name 'DisplayName' -Value $Instance.DisplayName;
            $item | Add-Member -type NoteProperty -Name 'State' -Value $instance.State
            $item | Add-Member -type NoteProperty -Name 'ServiceAccount' -Value $instance.ServiceAccount
            $item | Add-Member -type NoteProperty -Name 'Version' -Value $instance.Version
            $item | Add-Member -type NoteProperty -Name 'Default' -Value $instance.Default

            $Hash += $item;
        }

        $Hash
    }
    end {
    }
}

Export-ModuleMember -Function Get-BCSServerInstances