I've make a powershell script with running multiple powershell. I would like to do a GUI progressbar that will advandce according to the content of a log.txt file in real time. (All my script write in this file when they finish).
For now I've made this, it's works but my logs need to be finish and didn't work in real time.
# Pour bloquer le resize du form et supprimer les icones Minimize and Maximize
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
# Choix de la taille
$form.Size = New-Object System.Drawing.Size(400,370)
# Barre de progression
$progress = New-Object System.Windows.Forms.ProgressBar
$progress.Location = New-Object System.Drawing.Point(20,185)
$progress.Name = 'progressBar'
$progress.Step = 1
$progress.Size = New-Object System.Drawing.Size(350,23)
$form.Controls.Add($progress)
# Bouton OK
$button_ok = New-Object System.Windows.Forms.Button
$button_ok.Text = "OK"
$button_ok.Size = New-Object System.Drawing.Size(355,40)
$button_ok.Location = New-Object System.Drawing.Size(20,230)
$form.Controls.Add($button_ok)
$CheminLOGS = "c:\logs.txt"
$button_ok.Add_Click(
{
Do {
$Check1 = Select-String -Path $CheminLOGS -Pattern "FIN SCRIPT-PHASE1"
Write-Host "La Phase1 n'est pas terminee"
TIMEOUT 5 /nobreak
}Until($Check1 -Like "$CheminLOGS*")
Write-Host "PHASE 1 TERMINEE"
$progress.Value = 25
Do {
$Check2 = Select-String -Path $CheminLOGS -Pattern "FIN SCRIPT-PHASE2"
Write-Host "La Phase2 n'est pas terminee"
TIMEOUT 5 /nobreak
}Until($Check2 -Like "$CheminLOGS*")
Write-host PHASE 2 Terminée
$progress.Value = 100
})
$form.Topmost = $true
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
Can you help me ?