-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNew-PremiumNavContainerWithExtendedData.ps1
149 lines (119 loc) · 6.89 KB
/
New-PremiumNavContainerWithExtendedData.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function New-PremiumNavContainerWithExtendedData {
Param(
[switch]$accept_eula,
[string]$containerName,
[string]$imageName = "",
[string]$licenseFile = "",
[System.Management.Automation.PSCredential]$Credential = $null,
[string]$customConfigPackageFile = ""
)
$startTime=(Get-Date);
Clear-Host
Write-Host "Start creation of $containerName"
New-NavContainer -accept_eula:$accept_eula `
-containername $containername `
-auth NavUserPassword `
-Credential $credential `
-includeCSide `
-doNotExportObjectsToText `
-usessl:$false `
-updateHosts `
-assignPremiumPlan `
-shortcuts Desktop `
-imageName $navdockerimage `
-licenseFile $licenseFile `
-additionalParameters $additionalParameters `
-alwaysPull
Setup-NavContainerTestUsers -containerName $containername -password $password
Switch-NavContainerToPremiumMode -containerName $containername
ImportAndApply-ConfigPackageInNavContainer -containerName $containername -configPackageType:Premium
#ImportAndApply-ConfigPackageInNavContainer -containerName $containername -configPackageType:Custom -customConfigPackageFile $customConfigPackageFile
$Elapsed = (Get-Date)-$startTime;
Write-Host "Creation of $containerName is finished. It took " $Elapsed.TotalMinutes " minutes"
}
function Switch-NavContainerToPremiumMode {
param (
[Parameter(Mandatory=$false)]
[string]$containerName = "navserver",
[Parameter(Mandatory=$false)]
[string]$tenant = "default",
[System.Management.Automation.PSCredential]$sqlCredential = $null
)
$fobfile = Join-Path $env:TEMP "SetPremiumExperience.fob"
Download-File -sourceUrl "http://bit.ly/bcsetpremiumexpfob" -destinationFile $fobfile
Import-ObjectsToNavContainer -containerName $containerName -objectsFile $fobfile -sqlCredential $sqlCredential
Start-Sleep -Seconds 5
Invoke-NavContainerCodeunit -containerName $containerName -tenant $tenant -CodeunitId 60000 -MethodName SetPremiumExperience
Write-Host -ForegroundColor green "Business Central UI is switched to Premium mode"
}
function ImportAndApply-ConfigPackageInNavContainer {
param (
[Parameter(Mandatory=$false)]
[string]$containerName = "navserver",
[Parameter(Mandatory=$false)]
[string]$tenant = "default",
[Parameter(Mandatory=$false)]
[ValidateSet('Premium','Custom')]
[string]$configPackageType = "Premium",
[Parameter(Mandatory=$false)]
[string]$customConfigPackageFile
)
if ($configPackageType -eq "Custom" -and !$customConfigPackageFile) {
throw "Specify configuration package file"
}
# Import fob to run Import And Apply Conf Package File
$fobfile = Join-Path $env:TEMP "ImportAndApplyRapidStartPackage.fob"
Download-File -sourceUrl "http://bit.ly/bcimportapplyconfpackfob" -destinationFile $fobfile
Import-ObjectsToNavContainer -containerName $containerName -objectsFile $fobfile -sqlCredential $sqlCredential
Start-Sleep -Seconds 5
# Find Cronus Company
$CronusCompany = Get-CompanyInNavContainer -containerName $containerName | Where { $_.CompanyName -like ‘CRONUS*’ -and $_.EvaluationCompany -eq "true"} | Select-Object -First 1
if ($configPackageType -eq "Premium")
{
# Get Extended Conf Package File from Container
$containerConfigPackageFilePath = Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock {
#Try to find Extended Configuration Package
$originalFile = Get-Childitem –Path C:\ConfigurationPackages\*.EXTENDED.rapidstart | Select-Object -First 1
Copy-Item $originalFile.fullName -Destination $env:TEMP
return Join-Path $env:TEMP $originalFile.Name
}
if ($containerConfigPackageFilePath -eq "") {
throw "Extended configuration package was not found"
}
# Import and apply Conf Package File
Write-Host "Importing and applying configuration package from $containerConfigPackageFilePath (container path)"
Invoke-NavContainerCodeunit -containerName $containerName -tenant $tenant -CompanyName $CronusCompany.CompanyName -CodeunitId 60000 -MethodName ImportAndApplyRapidStartPackage -Argument $containerConfigPackageFilePath
Write-Host -ForegroundColor Green "Configuration package imported and applied"
}
if ($configPackageType -eq "Custom")
{
if ($customConfigPackageFile.StartsWith("http://", [StringComparison]::OrdinalIgnoreCase) -or $customConfigPackageFile.StartsWith("https://", [StringComparison]::OrdinalIgnoreCase)) {
$tempFileName = "CustomConfigurationPackage.rapidstart"
$localConfigPackageFilePath = Join-Path $env:TEMP $tempFileName
$containerConfigPackageFilePath = Join-Path "C:\" $tempFileName
Write-Host "Downloading file from $customConfigPackageFile"
Download-File -sourceUrl $customConfigPackageFile -destinationFile $localConfigPackageFilePath
} else {
$tempFileName = "CustomConfigurationPackage.rapidstart"
$localConfigPackageFilePath = $customConfigPackageFile
$containerConfigPackageFilePath = Join-Path "C:\" $tempFileName
}
Copy-FileToNavContainer -containerName $containerName -localPath $localConfigPackageFilePath -containerPath $containerConfigPackageFilePath
Write-Host "Importing and applying custom configuration package"
Invoke-NavContainerCodeunit -containerName $containerName -tenant $tenant -CompanyName $CronusCompany.CompanyName -CodeunitId 60000 -MethodName ImportAndApplyRapidStartPackage -Argument $containerConfigPackageFilePath
Write-Host -ForegroundColor Green "$configPackageType configuration package imported and applied"
}
}
install-module navcontainerhelper -force
$accept_eula = $true
$containername = 'BC-Prem-Ext'
$navdockerimage = 'mcr.microsoft.com/businesscentral/sandbox:ca'
$username = 'admin'
$password = ConvertTo-SecureString "admin" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)
$licenseFile = 'C:\ProgramData\NavContainerHelper\License\license.flf'
New-PremiumNavContainerWithExtendedData -accept_eula:$accept_eula `
-containername $containername `
-Credential $credential `
-imageName $navdockerimage `
-licenseFile $licenseFile