Functions/Get-BcTenant.ps1
function Get-BcTenant{ [CmdletBinding()] [Alias('Get-FpsBcTenant')] param( # The name of the Business Central Server Instance. E.g. 'BC180' [parameter(Mandatory=$true, ValueFromPipeline=$true)] [string] $ServerInstance, # The id of the BC tenant. # E.g. 'tenant1' or @('tenant1', 'tenant2') to specify multiple tenants. [string[]] $Tenants, # The computer name to retreive the BC Server Instances from. Default is the local system where the script is running on. E.g. 'MyComputer'. [string] $Computer = $env:COMPUTERNAME ) $serverInstanceObj = Get-BCServerInstance $ServerInstance -Computer $Computer # A scriptblock is used to load the Business Central binaries only into a temporarily PS session. # This prevents version conflicts of the binaries in the main powershell session. $scriptblock = [scriptblock] { param( [string[]] $BcModulesPath, [string] $ServerInstance ) $BcModulesPath | Import-Module -Force $allTenants = Get-NAVTenant -ServerInstance $ServerInstance if($Tenants){ $Tenants = $allTenants | Where-Object -Property Id -in $Tenants } else{ $Tenants = $allTenants } $tenantsToReturn = @() foreach($tenant in $tenants){ $tenantProperties = @{ 'License' = '' 'Extensions' = '' } # Add default Business Central properties to $tenantProperties $tenant | Get-Member -MemberType Property | ForEach-Object { $tenantProperties += @{$_.Name = $tenant.($_.Name)} } $tenantProperties = New-Object psobject -Property $tenantProperties $tenantProperties.Extensions = Get-NAVAppInfo -ServerInstance $ServerInstance -Tenant $tenant.Id -TenantSpecificProperties | Select-Object -Property AppId, Name, Publisher, Version, ExtensionDataVersion, IsPublished, Scope, SyncState, NeedsUpgrade, IsInstalled | Sort-Object -Property name $tenantsToReturn += $tenantProperties } $tenantsToReturn } $additionParams = @{} if ($Computer -ne 'localhost' -and $Computer -ne $env:COMPUTERNAME) { $additionParams = @{'ComputerName' = $Computer} } $result = Invoke-Command @additionParams -ScriptBlock $scriptBlock -ArgumentList ` $serverInstanceObj.GetBcPsModules(), $serverInstance # Add the license details per tenant. foreach($tenant in $result){ $tenant.License = Get-BcLicense -ServerInstance $ServerInstance -Tenant $tenant.Id -Computer $Computer } return $result } Export-ModuleMember -Function Get-BcTenant -Alias Get-FpsBcTenant |