functions/common/Test-DynamicsNavModuleAvailability.ps1
function Test-DynamicsNavModuleAvailability { <# .SYNOPSIS Tests whether a specific Dynamics NAV module can be loaded and whether its key commands are available. .DESCRIPTION Uses Get-DynamicsNavModule to locate and import the specified module (NavModelTools or NavAdminTool). Then verifies that key expected commands are available using Test-DynamicsNavModuleCommandAvailability. .PARAMETER PlatformVersion The Dynamics NAV platform version (e.g., "100", "200"). .PARAMETER ModuleType The module to load and test. Valid values are "NavModelTools" or "NavAdminTool". .OUTPUTS None. Outputs warning messages if loading or command verification fails. .EXAMPLE Test-DynamicsNavModuleAvailability -PlatformVersion "210" -ModuleType "NavAdminTool" Attempts to load the Admin module for platform 210 and verifies expected commands. .NOTES - This function depends on Get-DynamicsNavModule and Test-DynamicsNavModuleCommandAvailability. - It handles both script-based modules and module paths. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$PlatformVersion, [Parameter(Mandatory = $true)] [ValidateSet("NavModelTools", "NavAdminTool")] [string]$ModuleType ) try { $result = Get-DynamicsNavModule -PlatformVersion $PlatformVersion -ModuleType $ModuleType -Verbose if ($result -is [ScriptBlock]) { & $result } elseif ($result -is [string]) { Import-Module -Name $result -ErrorAction Stop } else { Write-Warning "Unbekannter Rückgabewert von Get-DynamicsNavModule." return } } catch { Write-Warning "Fehler beim Laden von $($ModuleType): $_" } Test-DynamicsNavModuleCommandAvailability -PlatformVersion $PlatformVersion -ModuleType $ModuleType } |