Ajout du support de unattend
Ajout du script cmd à utiliser pour lancer DeployCenter
This commit is contained in:
1 parent
2019c565f5
commit
e067721763
12 files changed
+663
-166
No files matched your search
+78
-14
@@ -124,6 +124,11 @@ if (-not (Test-Path -LiteralPath $deploymentModulePath -PathType Leaf)) {
|
||||
throw "Module de déploiement introuvable : $deploymentModulePath"
|
||||
}
|
||||
Import-Module $deploymentModulePath -Force
|
||||
$unattendModulePath = Join-Path $script:DeployRoot 'Modules\Unattend.psm1'
|
||||
if (-not (Test-Path -LiteralPath $unattendModulePath -PathType Leaf)) {
|
||||
throw "Module Unattend introuvable : $unattendModulePath"
|
||||
}
|
||||
Import-Module $unattendModulePath -Force
|
||||
$script:PartitionProfilesRoot = Join-Path $script:DeployRoot 'Partitioning\Profiles'
|
||||
$script:PartitionProfiles = @()
|
||||
foreach ($profileName in (Get-DeployCenterPartitionProfileNames -ProfilesRoot $script:PartitionProfilesRoot)) {
|
||||
@@ -147,6 +152,7 @@ $script:SelectedPartitionProfile = $script:PartitionProfiles[$script:SelectedPar
|
||||
$script:SelectedPartitionSizing = $null
|
||||
$script:SelectedDiskIndex = $null
|
||||
$script:SelectedWindowsEdition = $null
|
||||
$script:RestartAfterDeployment = $false
|
||||
$script:RefreshingDiskList = $false
|
||||
$script:ChangingPartitionProfileSelection = $false
|
||||
|
||||
@@ -242,6 +248,22 @@ foreach ($themeFileName in $defaultThemeFiles.Keys) {
|
||||
}
|
||||
|
||||
$script:Config = Read-DeployCenterConfig -ConfigPath $script:ConfigPath
|
||||
$script:UnattendProfilesRoot = Join-Path $script:DeployRoot 'Unattend\Profiles'
|
||||
$script:UnattendProfiles = @()
|
||||
foreach ($unattendProfileName in (Get-DeployCenterUnattendProfileNames -ProfilesRoot $script:UnattendProfilesRoot)) {
|
||||
try {
|
||||
$script:UnattendProfiles += Import-DeployCenterUnattendProfile `
|
||||
-ProfilesRoot $script:UnattendProfilesRoot -ProfileName $unattendProfileName
|
||||
} catch {
|
||||
& $script:SourceLogAction "Profil Unattend '$unattendProfileName' ignoré : $($_.Exception.Message)" 'WARNING'
|
||||
}
|
||||
}
|
||||
$duplicateUnattendNames = @($script:UnattendProfiles | Group-Object -Property Name | Where-Object Count -gt 1)
|
||||
foreach ($duplicateName in $duplicateUnattendNames) {
|
||||
& $script:SourceLogAction "Profils Unattend ignorés car leur nom affiché est en double : $($duplicateName.Name)." 'WARNING'
|
||||
$script:UnattendProfiles = @($script:UnattendProfiles | Where-Object { [string]$_.Name -ne [string]$duplicateName.Name })
|
||||
}
|
||||
$script:UnattendOobeChoice = 'Avec OOBE'
|
||||
foreach ($partitionProfile in $script:PartitionProfiles) {
|
||||
foreach ($partition in $partitionProfile.Partitions) {
|
||||
if ([string]$partition.Size.Policy -ne 'ConfiguredMB') { continue }
|
||||
@@ -437,7 +459,7 @@ $script:cmbTheme.BringToFront()
|
||||
# ============================================================
|
||||
|
||||
$script:groupPC = New-GroupBox -Text "Informations du PC" `
|
||||
-X $margin -Y 100 -Width $usableWidth -Height 105 -Theme $script:Theme -Font $script:FontGroup
|
||||
-X $margin -Y 100 -Width $usableWidth -Height 90 -Theme $script:Theme -Font $script:FontGroup
|
||||
|
||||
$script:lblManufacturer = New-Label -Text "Fabricant : -" `
|
||||
-X 18 -Y 25 -Width 330 -Height 24 -Theme $script:Theme -Font $script:FontRegular
|
||||
@@ -449,18 +471,12 @@ $script:lblFirmware = New-Label -Text "Firmware : -" `
|
||||
-X 360 -Y 52 -Width 220 -Height 24 -Theme $script:Theme -Font $script:FontRegular
|
||||
$script:lblArchitecture = New-Label -Text "Architecture : -" `
|
||||
-X 600 -Y 52 -Width 220 -Height 24 -Theme $script:Theme -Font $script:FontRegular
|
||||
$script:lblWinPE = New-Label -Text "Environnement : -" `
|
||||
-X 18 -Y 78 -Width 350 -Height 22 `
|
||||
-Theme $script:Theme -Font $script:FontSmall `
|
||||
-Color $script:Theme.Secondary
|
||||
|
||||
$script:groupPC.Controls.AddRange(@(
|
||||
$script:lblManufacturer,
|
||||
$script:lblModel,
|
||||
$script:lblSerial,
|
||||
$script:lblFirmware,
|
||||
$script:lblArchitecture,
|
||||
$script:lblWinPE
|
||||
$script:lblArchitecture
|
||||
))
|
||||
$script:form.Controls.Add($script:groupPC)
|
||||
|
||||
@@ -469,7 +485,7 @@ $script:form.Controls.Add($script:groupPC)
|
||||
# ============================================================
|
||||
|
||||
$script:groupDisks = New-GroupBox -Text "Préparation du déploiement" `
|
||||
-X $margin -Y 220 -Width $usableWidth -Height 226 -Theme $script:Theme -Font $script:FontGroup
|
||||
-X $margin -Y 205 -Width $usableWidth -Height 270 -Theme $script:Theme -Font $script:FontGroup
|
||||
|
||||
$deploymentControls = New-DeployCenterDeploymentControls `
|
||||
-Parent $script:groupDisks `
|
||||
@@ -481,6 +497,9 @@ $script:btnChooseWindows = $deploymentControls.ChooseSystemButton
|
||||
$script:lblSelectedWindows = $deploymentControls.SelectedSystemLabel
|
||||
$script:lblPartitionProfile = $deploymentControls.PartitionProfileLabel
|
||||
$script:cmbPartitionProfile = $deploymentControls.PartitionProfileComboBox
|
||||
$script:cmbUnattendProfile = $deploymentControls.UnattendProfileComboBox
|
||||
$script:DeploymentControls = $deploymentControls
|
||||
$script:lblHostName = $deploymentControls.HostNameLabel
|
||||
$script:txtHostName = $deploymentControls.HostNameTextBox
|
||||
$script:cmbPartitionProfile.SelectedIndex = $script:SelectedPartitionProfileIndex
|
||||
|
||||
@@ -585,9 +604,18 @@ $script:btnChooseWindows.Add_Click({
|
||||
$script:lblSelectedWindows.ForeColor = $script:Theme.Success
|
||||
$script:lblSelectedWindows.Name = 'lblSelectedWindows'
|
||||
$script:cmbPartitionProfile.Enabled = $true
|
||||
Set-DeployCenterUnattendProfileChoices -ComboBox $script:cmbUnattendProfile `
|
||||
-Profiles $script:UnattendProfiles -EditionName ([string]$edition.Name) `
|
||||
-OobeChoice $script:UnattendOobeChoice
|
||||
}
|
||||
})
|
||||
|
||||
$script:cmbUnattendProfile.Add_SelectedIndexChanged({
|
||||
$showHostName = $script:cmbUnattendProfile.SelectedItem -and
|
||||
[string]$script:cmbUnattendProfile.SelectedItem -ne $script:UnattendOobeChoice
|
||||
Set-DeployCenterUnattendHostNameVisibility -Controls $script:DeploymentControls -ShowHostName ([bool]$showHostName)
|
||||
})
|
||||
|
||||
$script:btnLog.Add_Click({
|
||||
if ($script:logForm.IsDisposed) { return }
|
||||
if (-not $script:logForm.Visible) { $script:logForm.Show($script:form) }
|
||||
@@ -602,7 +630,18 @@ $script:btnDeploy.Add_Click({
|
||||
$diskIndex = $null
|
||||
if ($null -ne $script:cmbDisk.SelectedItem) { $diskIndex = [int]$script:cmbDisk.SelectedItem.Tag }
|
||||
$diskInfo = if ($null -ne $diskIndex) { Get-SelectedDeployDiskInfo -HardwareInfo $script:HardwareInventory -DiskIndex $diskIndex } else { $null }
|
||||
$hostName = [string]$script:txtHostName.Text.Trim()
|
||||
$unattendChoice = [string]$script:cmbUnattendProfile.SelectedItem
|
||||
$unattendProfile = $null
|
||||
$hostName = $null
|
||||
if ($unattendChoice -and $unattendChoice -ne $script:UnattendOobeChoice) {
|
||||
$matchingProfiles = @($script:UnattendProfiles | Where-Object { [string]$_.Name -eq $unattendChoice })
|
||||
if ($matchingProfiles.Count -ne 1) {
|
||||
Show-DeployCenterMessage -Message "Le profil Unattend '$unattendChoice' est introuvable ou ambigu." -Title 'Profil Unattend' -Icon Error -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
return
|
||||
}
|
||||
$unattendProfile = $matchingProfiles[0]
|
||||
$hostName = [string]$script:txtHostName.Text.Trim()
|
||||
}
|
||||
|
||||
if ($null -eq $diskInfo) {
|
||||
Show-DeployCenterMessage -Message 'Sélectionne le disque de destination.' -Title 'Déploiement Windows' -Icon Warning -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
@@ -612,10 +651,19 @@ $script:btnDeploy.Add_Click({
|
||||
Show-DeployCenterMessage -Message 'Sélectionne une édition Windows à installer.' -Title 'Déploiement Windows' -Icon Warning -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
return
|
||||
}
|
||||
if ($hostName -notmatch '^(?=.*[A-Za-z])[A-Za-z0-9](?:[A-Za-z0-9-]{0,13}[A-Za-z0-9])?$') {
|
||||
if ($null -ne $unattendProfile -and $unattendProfile.ComputerName -and $hostName -notmatch '^(?=.*[A-Za-z])[A-Za-z0-9](?:[A-Za-z0-9-]{0,13}[A-Za-z0-9])?$') {
|
||||
Show-DeployCenterMessage -Message "Le nom d’hôte doit contenir de 1 à 15 caractères, commencer et finir par une lettre ou un chiffre, et ne contenir que des lettres, chiffres ou tirets." -Title "Nom d’hôte invalide" -Icon Warning -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
return
|
||||
}
|
||||
if ($null -ne $unattendProfile) {
|
||||
try {
|
||||
Test-DeployCenterUnattendConfiguration -Profile $unattendProfile `
|
||||
-Configuration $script:Config -HostName $hostName
|
||||
} catch {
|
||||
Show-DeployCenterMessage -Message $_.Exception.Message -Title 'Configuration Unattend invalide' -Icon Warning -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
return
|
||||
}
|
||||
}
|
||||
if ($script:SelectedPartitionSizing -and [int]$script:SelectedPartitionSizing.DiskIndex -ne [int]$diskInfo.Index) {
|
||||
Show-DeployCenterMessage -Message 'La taille des partitions correspond à un autre disque. Sélectionne de nouveau le profil de partitionnement.' -Title 'Partitionnement' -Icon Warning -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
return
|
||||
@@ -630,9 +678,10 @@ $script:btnDeploy.Add_Click({
|
||||
$sizeParts += ("espace restant : {0:N1} Go" -f $script:SelectedPartitionSizing.RemainderGB)
|
||||
$sizeDescription = $sizeParts -join ', '
|
||||
}
|
||||
$unattendDescription = if ($null -ne $unattendProfile) { "Profil Unattend : $($unattendProfile.Name)`r`nNom d’hôte : $hostName" } else { 'Configuration initiale : Avec OOBE' }
|
||||
$confirmation = Show-DeployCenterConfirmation `
|
||||
-Title "Confirmer l’effacement du disque" `
|
||||
-Message ("Disque {0} — {1} ({2:N1} Go)`r`nProfil : {3}`r`nÉdition : {4}`r`nTailles : {5}`r`nNom d’hôte : {6}`r`nTout le contenu du disque sera effacé. Cette opération est irréversible." -f $diskInfo.Index, $diskInfo.Model, $diskInfo.SizeGB, $script:SelectedPartitionProfile.Name, $script:SelectedWindowsEdition.Name, $sizeDescription, $hostName) `
|
||||
-Message ("Disque {0} — {1} ({2:N1} Go)`r`nProfil de partitionnement : {3}`r`nÉdition : {4}`r`nTailles : {5}`r`n{6}`r`nTout le contenu du disque sera effacé. Cette opération est irréversible." -f $diskInfo.Index, $diskInfo.Model, $diskInfo.SizeGB, $script:SelectedPartitionProfile.Name, $script:SelectedWindowsEdition.Name, $sizeDescription, $unattendDescription) `
|
||||
-Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
if (-not $confirmation) { return }
|
||||
|
||||
@@ -672,6 +721,8 @@ $script:btnDeploy.Add_Click({
|
||||
-SizingState $script:SelectedPartitionSizing `
|
||||
-Edition $script:SelectedWindowsEdition `
|
||||
-HostName $hostName `
|
||||
-UnattendProfile $unattendProfile `
|
||||
-UnattendConfiguration $script:Config `
|
||||
-Firmware $script:HardwareInventory.Firmware `
|
||||
-TemporaryRoot $script:InventoryDir `
|
||||
-LogAction $script:SourceLogAction `
|
||||
@@ -679,7 +730,13 @@ $script:btnDeploy.Add_Click({
|
||||
|
||||
$progress.Form.Close()
|
||||
$script:form.Enabled = $true
|
||||
Show-DeployCenterMessage -Message 'Windows a été appliqué. Le déploiement est prêt à être finalisé par le redémarrage de WinPE.' -Title 'Déploiement terminé' -Icon Information -Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
$restartAfterDeployment = Show-DeployCenterDeploymentComplete `
|
||||
-Message 'Windows a été appliqué avec succès. Le déploiement est prêt.' `
|
||||
-Owner $script:form -Theme $script:Theme -Font $script:FontRegular
|
||||
if ($restartAfterDeployment) {
|
||||
$script:RestartAfterDeployment = $true
|
||||
$script:form.Close()
|
||||
}
|
||||
} catch {
|
||||
if (-not $progress.Form.IsDisposed) { $progress.Form.Close() }
|
||||
$script:form.Enabled = $true
|
||||
@@ -688,7 +745,7 @@ $script:btnDeploy.Add_Click({
|
||||
} finally {
|
||||
if (-not $progress.Form.IsDisposed) { $progress.Form.Dispose() }
|
||||
$script:form.Enabled = $true
|
||||
$script:form.Activate()
|
||||
if (-not $script:form.IsDisposed -and $script:form.Visible) { $script:form.Activate() }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -821,4 +878,11 @@ finally {
|
||||
Stop-DeployCenterVnc
|
||||
}
|
||||
$script:form.Dispose()
|
||||
if ($script:RestartAfterDeployment) {
|
||||
try {
|
||||
Restart-DeployCenterWinPE -LogAction $script:SourceLogAction
|
||||
} catch {
|
||||
& $script:SourceLogAction "Échec de la demande de redémarrage : $($_.Exception.Message)" 'ERROR'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user