28 lines
993 B
PowerShell
28 lines
993 B
PowerShell
function Generate-RandomPassword {
|
|
param([int]$Length = 12)
|
|
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$#%&"
|
|
$password = ""
|
|
for ($i = 0; $i -lt $Length; $i++) {
|
|
$password += $chars.ToCharArray() | Get-Random
|
|
}
|
|
return $password
|
|
}
|
|
|
|
# 1. Définir le chemin du fichier
|
|
$path = "C:\Users\vboxuser\Desktop\Scripts\happy_koalas_employees.csv"
|
|
|
|
# 2. Charger les données en mémoire
|
|
# On utilise une variable ($data) pour libérer le fichier après la lecture
|
|
$data = Import-Csv -Path $path -Delimiter ";"
|
|
|
|
# 3. Remplir la colonne Password si elle est vide
|
|
foreach ($row in $data) {
|
|
if ([string]::IsNullOrWhiteSpace($row.Password)) {
|
|
$row.Password = Generate-RandomPassword -Length 10
|
|
}
|
|
}
|
|
|
|
# 4. Réécrire par-dessus le fichier original
|
|
$data | Export-Csv -Path $path -NoTypeInformation -Delimiter ";" -Encoding utf8
|
|
|
|
Write-Host "Le fichier original a été mis à jour avec succès !" -ForegroundColor Cyan |