Misc/Install-NCHDependentModules.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function Install-NCHDependentModules {
    param(        
        [Parameter(Mandatory = $false)]
        [String] $ContainerName,
        [Parameter(Mandatory = $false)]
        [Switch] $ContainerModulesOnly
    )

    if (!$ContainerModulesOnly) {
        $null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
        
        #navcontainerhelper
        $FindModule = Find-Module 'navcontainerhelper'            
        if($FindModule){
            write-host -Object " Installing $($FindModule.Name) version $($FindModule.Version) on Docker Host." -ForegroundColor Gray
            Install-Module 'navcontainerhelper' -Force 
        }
        
        #CRS.NavContainerHelperExtension .NavContainerHelperExtension'
        if($FindModule){
            write-host -Object " Installing $($FindModule.Name) version $($FindModule.Version) on Docker Host." -ForegroundColor Gray
            Install-Module 'CRS.NavContainerHelperExtension' -Force             
        }
    }

    if ($ContainerName) {
        $Session = Get-NavContainerSession -containerName $ContainerName
        Invoke-Command -Session $Session -ScriptBlock {
            param(
                $ContainerName
            )
            function InstallModuleFromPSGallery ([String] $Module) {
                $FindModule = Find-Module $Module
                write-host -Object " Installing $($FindModule.Name) version $($FindModule.Version) from $($FindModule.Repository) on Container $ContainerName" -ForegroundColor Gray
                Install-Module $Module -Force 
            }

            Write-host "Installing dependent modules on Container $ContainerName" -ForegroundColor Green
            
            $null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

            InstallModuleFromPSGallery -Module Cloud.Ready.Software.NAV 
            InstallModuleFromPSGallery -Module Cloud.Ready.Software.SQL 
            InstallModuleFromPSGallery -Module Cloud.Ready.Software.Windows 
            InstallModuleFromPSGallery -Module Cloud.Ready.Software.PowerShell 
        } -ArgumentList $ContainerName
    }

}