Containers/New-Container.ps1
function New-Container { Param( [Parameter(Mandatory = $false)] [string] $ContainerName, [Parameter(Mandatory = $false)] [string] $ImageName, [Parameter(Mandatory = $false)] [string] $LicenseFile, [Parameter(Mandatory = $false)] [pscredential] $Credential, [Parameter(Mandatory = $false)] [string] $Country = "", [switch] $alwaysPull, [switch] $SetupTestUsers, [switch] $SkipTestTool, [switch] $includeCSide, [switch] $skipBackup, [switch] $useHyperVIsolation, [switch] $includeClickOnce, [switch] $enableTaskScheduler, [switch] $isLocal ) if ($null -eq $ContainerName -or $ContainerName -eq "") { $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name') } if ($null -eq $Credential) { $NewCredential = New-CredentialFromEnvironmentJson if ($NewCredential -eq $false) { $Credential = [PSCredential]::new('admin', (ConvertTo-SecureString 'P@ssword1' -AsPlainText -Force)) $Password = (ConvertTo-SecureString 'P@ssword1' -AsPlainText -Force) } else { $Credential = $NewCredential $Password = (ConvertTo-SecureString (Get-EnvironmentKeyValue -KeyName "password") -AsPlainText -Force) } } else { $Password = $Credential.Password } if ($null -eq $ImageName -or $ImageName -eq "") { $ImageName = (Get-ImageNameForRepo) } $target = Get-AppKeyValue -KeyName "Target" if ($target -eq "Cloud" -or $target -eq "Extension") { $EnvironmentType = "Sandbox" } else { $EnvironmentType = "OnPrem" } if ($Country -eq "") { $Country = "w1" } if ($ImageName -in @("2016","2017","2018")) { $cu = Get-EnvironmentKeyValue -KeyName "cu" $artifactUrl = Get-NavArtifactUrl -nav $imageName -cu $cu -select Latest -country $Country Write-Host "Using Version $ImageName Cumulative Update $cu Country $Country" } else { $artifactUrl = Get-BCArtifactUrl -version $ImageName -select Latest -country $Country -Type $EnvironmentType Write-Host "Using Version $ImageName Country $Country" } Write-Host "Using Artifact Url $artifactUrl" [version]$platform = Get-AppKeyValue -KeyName "platform" if ($platform.Major -lt 15) { $skipBackup = $true } #disable using backup, since this is currently possibly causing issues as well $skipBackup = $true if (!$skipBackup.IsPresent) { if (!(Test-Path "C:\.backups")) { New-Item -Path "C:\.backups" -ItemType Directory | Out-Null } if ($Country -eq "") { $Country = Get-EnvironmentKeyValue -KeyName "locale" } $platform = Get-AppKeyValue -KeyName 'platform' $bakFolder = (Join-Path "C:\.backups" $platform) $bakFolder = (Join-Path $bakFolder $Country) if (Test-Path (Join-Path $bakFolder "*")) { Write-Host "Using backups to create container" } } else { Write-Host "Not using backups to create container" } $startParameters = @{ containerName = $ContainerName Credential = $Credential artifactUrl = $artifactUrl licenseFile = $LicenseFile } if ($useHyperVIsolation.IsPresent) { $startParameters.Add('isolation', 'HyperV') } if (Get-EnvironmentKeyValue -KeyName "usePremium") { $startParameters.Add('assignPremiumPlan', $true) } [version]$platform = Get-AppKeyValue -KeyName 'platform' if ($platform.Major -gt 13) { $startParameters.Add('includeAL', $true) } if (!($SkipTestTool.IsPresent)) { if ($platform.Major -gt 11) { $startParameters.Add('includeTestToolkit', $true) } } if ($isLocal.IsPresent) { $startParameters.Add('memoryLimit', '16GB') } else { $startParameters.Add('memoryLimit', '8GB') } if ($platform.Major -le 14) { $startParameters.Add('shortcuts', 'DesktopFolder') } else { $startParameters.Add('shortcuts', 'None') $startParameters.Add('enableSymbolLoading', $false) } if ($alwaysPull.IsPresent) { $startParameters.Add('alwaysPull', $true) } if ($includeCSide) { $startParameters.Add('includeCSide', $true) $startParameters.Add('clickonce', $true) } if (!$skipBackup.IsPresent) { $startParameters.Add('bakFolder', $bakFolder) $startParameters.Add('additionalParameters', @("-v C:\.backups:C:\.backups")) } if ($enableTaskScheduler.IsPresent) { $startParameters.Add('enableTaskScheduler', $true) } else { $startParameters.Add('enableTaskScheduler', $false) } Flush-ContainerHelperCache -cache bcartifacts -keepDays 7 if ($SetupTestUsers.IsPresent) { New-NavContainer -accept_eula -accept_outdated -auth NavUserPassword -updateHosts -useBestContainerOS -doNotExportObjectsToText ` -finalizeDatabasesScriptBlock { Setup-NavContainerTestUsers -containerName $ContainerName -password $Password -credential $Credential } ` @startParameters } else { New-NavContainer -accept_eula -accept_outdated -auth NavUserPassword -updateHosts -useBestContainerOS -doNotExportObjectsToText @startParameters } } Export-ModuleMember New-Container |