Code Powershell
Page mise à jour le 11-03-2026 à 15:50
# tableau trié des éléments contenus dans un fichier csv
$elements = Import-Csv -Delimiter ";" -Path "FichierCsv" -Encoding utf8 | sort
# création d'un nouveau fichier
New-Item -ItemType file -Path "FichierTxt" -Force
Add-Content -Path "FichierTxt" -Value "Texte"
# énumération d'un tableau
foreach ($element in $tableau) {
$lname = $element.nom
$fname = $element.prenom
}
# date et heure
$date = Get-Date -Format "dd-MM-yyyy"
$heure = Get-Date -Format "HH:mm:ss"
$elements = Import-Csv -Delimiter ";" -Path "FichierCsv" -Encoding utf8 | sort
# création d'un nouveau fichier
New-Item -ItemType file -Path "FichierTxt" -Force
Add-Content -Path "FichierTxt" -Value "Texte"
# énumération d'un tableau
foreach ($element in $tableau) {
$lname = $element.nom
$fname = $element.prenom
}
# date et heure
$date = Get-Date -Format "dd-MM-yyyy"
$heure = Get-Date -Format "HH:mm:ss"
# boite de dialogue pour sélection de fichier
function SelectFile {
param([string]$title,[string]$directory,[string]$filter)
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $directory
$objForm.Filter = $filter
$objForm.Title = $title
$show = $objForm.ShowDialog()
if ($show -eq "OK") return $objForm.FileName
}
# boite de dialogue pour confirmation
# $apply = DialogBox "message" 4 -> if ($apply -eq 6) {...}
function DialogBox {
param([string]$text,[int]$buttons)
$box = New-Object -ComObject wscript.shell
# code des boutons affichés :
# 0 OK
# 1 OK, Cancel
# 2 Abort, Retry, Ignore
# 3 Yes, No, Cancel
# 4 Yes, No
# 5 Retry, Cancel
$answer = $box.popup($text, 0,"",$buttons)
# code de retour :
# 1 OK
# 2 Cancel
# 3 Abort
# 4 Retry
# 5 Ignore
# 6 Yes
# 7 No
return $answer
}
# barre de progression : $n=0 -> $n=ProgressBar($n)
function ProgressBar {
param([int]$i)
$i ++
if ($i -lt 80) {
Write-Host -NoNewline ">"
} else {
Write-Host ">"
$i = 0
}
return $i
}
function SelectFile {
param([string]$title,[string]$directory,[string]$filter)
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $directory
$objForm.Filter = $filter
$objForm.Title = $title
$show = $objForm.ShowDialog()
if ($show -eq "OK") return $objForm.FileName
}
# boite de dialogue pour confirmation
# $apply = DialogBox "message" 4 -> if ($apply -eq 6) {...}
function DialogBox {
param([string]$text,[int]$buttons)
$box = New-Object -ComObject wscript.shell
# code des boutons affichés :
# 0 OK
# 1 OK, Cancel
# 2 Abort, Retry, Ignore
# 3 Yes, No, Cancel
# 4 Yes, No
# 5 Retry, Cancel
$answer = $box.popup($text, 0,"",$buttons)
# code de retour :
# 1 OK
# 2 Cancel
# 3 Abort
# 4 Retry
# 5 Ignore
# 6 Yes
# 7 No
return $answer
}
# barre de progression : $n=0 -> $n=ProgressBar($n)
function ProgressBar {
param([int]$i)
$i ++
if ($i -lt 80) {
Write-Host -NoNewline ">"
} else {
Write-Host ">"
$i = 0
}
return $i
}
Papy WinTux - Philippe DESLOGES - 2023-2026 - Powered by Debian - Apache 2.4.54 - PHP 7.4.33 - Last update 20-04-2026 19:05 - Page size 21 ko built in 1 ms
All trademarks, logos, images and documents on these pages belong exclusively to their respective owners.
All trademarks, logos, images and documents on these pages belong exclusively to their respective owners.
