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 ) 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) } if ($Country -ne "") { $ImageName = (($ImageName -replace ".{2}$") + $Country) } Write-Host "Using Image $ImageName" [version]$platform = Get-AppKeyValue -KeyName "platform" if ($platform.Major -lt 15) { $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" } [version]$platform = Get-AppKeyValue -KeyName 'platform' $includeAL = $false if ($platform.Major -gt 13) { $includeAL = $true } $TestLibrariesOnly = $false if ($platform.Major -gt 14) { $TestLibrariesOnly = !$SkipTestTool.IsPresent } if ($skipBackup.IsPresent) { if ($SetupTestUsers.IsPresent) { New-NavContainer -containerName $ContainerName -accept_eula -accept_outdated -auth NavUserPassword ` -Credential $Credential -imageName $ImageName -licenseFile $LicenseFile -updateHosts -isolation "HyperV" ` -useBestContainerOS -includeAL:$includeAL -shortcuts None -includeTestToolkit:(!$SkipTestTool.IsPresent) -includeTestLibrariesOnly:($TestLibrariesOnly) ` -alwaysPull:$alwaysPull -doNotExportObjectsToText -includeCSide:$includeCSide -EnableTaskScheduler:$false ` -finalizeDatabasesScriptBlock { Setup-NavContainerTestUsers -containerName $ContainerName -password $Password -credential $Credential } } else { New-NavContainer -containerName $ContainerName -accept_eula -accept_outdated -auth NavUserPassword ` -Credential $Credential -imageName $ImageName -licenseFile $LicenseFile -updateHosts -isolation "HyperV" ` -useBestContainerOS -includeAL:$includeAL -shortcuts None -includeTestToolkit:(!$SkipTestTool.IsPresent) -includeTestLibrariesOnly:($TestLibrariesOnly) ` -alwaysPull:$alwaysPull -doNotExportObjectsToText -includeCSide:$includeCSide -EnableTaskScheduler:$false } } else { if ($SetupTestUsers.IsPresent) { New-NavContainer -containerName $ContainerName -accept_eula -accept_outdated -auth NavUserPassword ` -Credential $Credential -imageName $ImageName -licenseFile $LicenseFile -updateHosts -isolation "HyperV" ` -useBestContainerOS -includeAL:$includeAL -shortcuts None -includeTestToolkit:(!$SkipTestTool.IsPresent) -includeTestLibrariesOnly:($TestLibrariesOnly) ` -alwaysPull:$alwaysPull -doNotExportObjectsToText -includeCSide:$includeCSide -EnableTaskScheduler:$false ` -additionalParameters @("-v C:\.backups:C:\.backups") ` -finalizeDatabasesScriptBlock { Setup-NavContainerTestUsers -containerName $ContainerName -password $Password -credential $Credential } -bakFolder ($bakFolder) } else { New-NavContainer -containerName $ContainerName -accept_eula -accept_outdated -auth NavUserPassword ` -Credential $Credential -imageName $ImageName -licenseFile $LicenseFile -updateHosts -isolation "HyperV" ` -useBestContainerOS -includeAL:$includeAL -shortcuts None -includeTestToolkit:(!$SkipTestTool.IsPresent) -includeTestLibrariesOnly:($TestLibrariesOnly) ` -alwaysPull:$alwaysPull -doNotExportObjectsToText -includeCSide:$includeCSide -EnableTaskScheduler:$false ` -additionalParameters @("-v C:\.backups:C:\.backups") ` -bakFolder ($bakFolder) } } } Export-ModuleMember New-Container |