1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| function choice([string]$prompt, [string[]]$AcceptValue = "", [string]$defaultValue = "")
{
# Dans le prompt nous pouvons utiliser la valeur spécial #promptinfo# qui sera remplacé par les valeurs acceptées et par default
$promptinfo = ""
if ($AcceptValue -ne "")
{
$promptinfo = "(valeurs acceptées : " + $($AcceptValue -join "/") + ")"
}
if ($defaultValue -ne "")
{
$promptinfo += " (valeur par default : " + $defaultValue + ")"
}
if ($promptinfo -ne "")
{
$promptinfo = " " + $promptinfo.Trim() + " "
}
$prompt = ($prompt -replace "#promptinfo#", $promptinfo -replace " ", " ").Trim()
while ($true)
{
$result = Read-Host -Prompt $prompt
if ($result -eq "" -and $defaultValue -ne $null)
{
$result = $defaultValue
}
if ($AcceptValue -ne "" -and ($result -notin $AcceptValue))
{
Write-Host "Valeur inacceptable ! veuillé rééssayer !" -ForegroundColor Red
continue
}
else
{
return $result
}
}
}
do
{
do
{
$ReponseUtilisateur = choice "Entrez le nom du dossier à traiter EX : \\servertest\repertoire A#promptinfo#" "" "C:\dossieratraiter"
} until ((choice "Le dossier choisi est $ReponseUtilisateur, est-ce correct #promptinfo# ?" ("Y", "N")) -eq "Y")
Write-Host ""
do
{
$ReponseUtilisateur2 = choice "Entrez le nom du dossier de sortie.csv EX : C:\Users\Documents#promptinfo#" "" "C:\dossiersortie"
} until ((choice "Le dossier choisi est $ReponseUtilisateur2, est-ce correct #promptinfo# ?" ("Y", "N")) -eq "Y")
Write-Host ""
do
{
$dateselectionnée = choice "Entrez la date a traiter au format jj/mm/aa A#promptinfo#" "" (Get-Date).ToString("dd/MM/yyyy")
} until ((choice "La date choisie est: $dateselectionnée, est-ce correct #promptinfo# ?" ("Y", "N")) -eq "Y")
Get-ChildItem -Path $ReponseUtilisateur -Recurse -Force | Where-Object {!$_.PSIsContainer -and $_.LastAccessTime -lt [datetime]::ParseExact($dateselectionnée, "dd/MM/yyyy", $null)} | Sort-Object -Property Path | Export-Csv -Path "$ReponseUtilisateur2\sortie.csv" -NoTypeInformation -Delimiter ";" -Encoding Default
Write-Output "Le fichier sortie.csv à été créé dans le repertoire $ReponseUtilisateur2"
Write-Host ""
} until ((choice "Voulez-vous arrêter #promptinfo# ?" ("Y", "N")) -eq "Y") |
Partager