Functions/ModuleManagement/Get-BcModule.ps1
function Get-BcModule { [CmdletBinding(DefaultParameterSetName='ServerInstance')] Param ( # Gets the modules compatible with the supplied serverinstance. [Parameter(ParameterSetName='ServerInstance', Mandatory = $true)] [string] $ServerInstance, # Gets the modules compatible with the supplied BcVersion. E.g. 'bc15' or 'bc13'. [Parameter(ParameterSetName='BcVersion', Mandatory = $true)] [string] $BcVersion, [switch] $ManagementModule, [switch] $AppManagementModule, [switch] $AppToolsModule, [switch] $ModelToolsModule ) # If not a specific module is specified import all modules. if( $ManagementModule -eq $false -and $AppManagementModule -eq $false -and $AppToolsModule -eq $false -and $ModelToolsModule -eq $false) { $ManagementModule = $true $AppManagementModule = $true $AppToolsModule = $true $ModelToolsModule = $true } if($BcVersion){ if((Get-BcVersion -BcVersion $BcVersion) -eq $false){ "The supplied BC/NAV version '{0}' is not valid. Valid values are for example 'BC15', 'BC13', 'NAV2017'" -f $BcVersion | Write-Warning return } [hashtable] $BcVersion = Get-BcVersion -BcVersion $BcVersion } # Get BC version from Service if($ServerInstance){ $ServerInstanceConfig = Get-BCServerInstance -ServerInstance $ServerInstance -WarningAction SilentlyContinue if(-not $ServerInstanceConfig -or $ServerInstanceConfig.Version -eq '1.0.0.0'){ 'Could not look up the version number for Server Instance ''{0}''. Make sure the Server Instance exists and the installation is valid.' -f $ServerInstance | Write-Warning return } $BcVersionFolder = ([version](Get-BCServerInstance -ServerInstance $ServerInstance).Version).Major * 10 [hashtable] $BcVersion = Get-BcVersion -VersionFolder $BcVersionFolder } # Disable app modules for Dynamics NAV. if($BcVersion.ProductAbb -eq 'NAV'){ $AppManagementModule = $false $AppToolsModule = $false } # Disable model tools, merged into management module in bc18 if([int] $BcVersion.VersionFolder -gt 170){ $ModelToolsModule = $false } # Get installation folders $BcComponent = Get-BcComponent -BcVersion $BcVersion.Version $Service = $BcComponent | Where-Object Component -eq 'NST' if([int] $BcVersion.VersionFolder -lt 180){ $Rtc = $BcComponent | Where-Object Component -eq 'RTC' } if (-not $Service.IsInstalled) { Write-Warning 'Cannot find the BC installation folder. Make sure the BC server component is installed.' return $false } $Modules = @() if($ManagementModule){ $Modules += 'Microsoft.Dynamics.Nav.Management' } if($AppManagementModule){ $Modules += 'Microsoft.Dynamics.Nav.Apps.Management' } if($AppManagementModule){ $Modules += 'Microsoft.Dynamics.Nav.Apps.Tools' } if($ModelToolsModule){ $Modules += 'Microsoft.Dynamics.Nav.Model.Tools' } $ModulesPath = @() foreach($Module in $Modules){ $ModulePath = (Get-ChildItem (Join-Path -Path $Service.InstallLocation -ChildPath ($Module + ".psd1")) -Recurse).fullname if($ModulePath -and (Test-Path -Path $ModulePath)){ $ModulesPath += $ModulePath; continue } $ModulePath = (Get-ChildItem (Join-Path -Path $Service.InstallLocation -ChildPath ($Module + ".psm1")) -Recurse).fullname if($ModulePath -and (Test-Path -Path $ModulePath)){ $ModulesPath += $ModulePath; continue } if($Rtc.InstallLocation){ $ModulePath = (Get-ChildItem (Join-Path -Path $Rtc.InstallLocation -ChildPath ($Module + ".psd1")) -Recurse).fullname } if($ModulePath -and (Test-Path -Path $ModulePath)){ $ModulesPath += $ModulePath; continue } 'Could not find module {0}.' -f $Module | Write-Warning } $ModulesPath } Export-ModuleMember -Function Get-BcModule |