[void][reflection.assembly]::loadwithpartialname("system.windows.forms")

Set-ExecutionPolicy Unrestricted
Clear-Host

write-host "Lancement du script"
write-host " "

# Fonction pour l'interface de saisie
Function ModeInstall() {
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 

    $objForm = New-Object System.Windows.Forms.Form 
    $objForm.Text = "Finalisation serveur"
    $objForm.Size = New-Object System.Drawing.Size(500,300) 
    $objForm.StartPosition = "CenterScreen"

    $objForm.KeyPreview = $True
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
        {$ClusterInstall=$objListBoxCluster.SelectedItem;$objForm.hide()}})
    $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
        {$objForm.hide()}})
    $objForm.AcceptButton = $OKButton
    $objForm.CancelButton = $CancelButton

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(10,230)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(200,230)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    
    $objLabel1 = New-Object System.Windows.Forms.Label
    $objLabel1.Location = New-Object System.Drawing.Size(10,20) 
    $objLabel1.Size = New-Object System.Drawing.Size(280,20) 
    $objLabel1.Text = "Merci de la clé Windows 2016 pour finaliser le serveur"

    $objLabel3 = New-Object System.Windows.Forms.Label
    $objLabel3.Location = New-Object System.Drawing.Size(10,80) 
    $objLabel3.Size = New-Object System.Drawing.Size(280,20) 
    $objLabel3.Text = "clé : "
    
    $objTextBoxKey = New-Object System.Windows.Forms.TextBox 
    $objTextBoxKey.Location = New-Object System.Drawing.Size(10,100) 
    $objTextBoxKey.Size = New-Object System.Drawing.Size(250,20)
    $objTextBoxKey.text = "AAAAA-BBBBB-CCCCC-DDDDD-EEEEE"
    $objForm.Controls.Add($objTextBoxKey)
    
        
    $objForm.Controls.AddRange(@($OKButton,$CancelButton,$objLabel1,$objLabel2,$objLabel3,$objLabel4,$objListBoxServeur))
    $objForm.Topmost = $True

    $dialogResult = $objForm.ShowDialog()

    if ($dialogResult -eq [System.Windows.Forms.DialogResult]::OK)
    {

        $Key = $objTextBoxKey.Text
        #$InstallCRPCEN
        
        $return = "$Key"
        $return
    }
    
    $objForm.dispose()

}     # End Function DriveList

write-host "  *****************************************"
Write-host " "

write-host "  *****************************************"
write-host "  * Génération de l'interface"
write-host "  *****************************************"

$ModeInstall = ModeInstall 
write-host "- Données saisie   ............................................... "
$Blocage = $False

write-host "- Validation des informations saisie ............................. "
if ($ModeInstall -ne $null) {
    $ModeInstall | foreach { $ModeInstall = $_ -split ';'
        $key             = $ModeInstall[0]
} }

write-host $key

Dism /online /Set-Edition:ServerStandard /AcceptEula /ProductKey:$key

Restart-Computer