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 ) 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" } $startParameters = @{ containerName = $ContainerName Credential = $Credential imageName = $ImageName licenseFile = $LicenseFile } if ($useHyperVIsolation.IsPresent) { $startParameters.Add('isolation', 'HyperV') } [version]$platform = Get-AppKeyValue -KeyName 'platform' if ($platform.Major -gt 13) { $startParameters.Add('includeAL', $true) } if (!$SkipTestTool) { $startParameters.Add('includeTestToolkit', $true) if ($platform.Major -gt 14) { $startParameters.Add('includeTestLibrariesOnly', $true) } } if ($platform.Major -le 14) { $startParameters.Add('shortcuts', 'DesktopFolder') $startParameters.Add('enableSymbolLoading', $true) } else { $startParameters.Add('shortcuts', 'None') } if ($alwaysPull.IsPresent) { $startParameters.Add('alwaysPull', $true) } if ($includeCSide) { $startParameters.Add('includeCSide', $true) } if (!$skipBackup.IsPresent) { $startParameters.Add('bakFolder', $bakFolder) $startParameters.Add('additionalParameters', @("-v C:\.backups:C:\.backups")) } 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 |