# Récupère le chemin du répertoire du script $scriptDirectory = $PSScriptRoot # Nom de la machine $machineName = $env:COMPUTERNAME $Directory = "History-Logs" # Crée le répertoire 'History-Logs' s'il n'existe pas $fullDirectoryPath = Join-Path $scriptDirectory $Directory if (-not (Test-Path $fullDirectoryPath)) { New-Item -ItemType Directory -Path $fullDirectoryPath } # Nom de fichier avec le nom de la machine, la date et l'heure $dateTime = (Get-Date).ToString('yyyyMMdd-HHmm') $exportFileName = "${machineName}_Full_History_PowerShell_export_$dateTime.txt" $exportPath = Join-Path $fullDirectoryPath $exportFileName # Chemin vers le fichier d'historique pour l'utilisateur actuel $historyPath = "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt" # Vérifie si le fichier d'historique existe if (Test-Path $historyPath) { # Copie le contenu du fichier d'historique vers le fichier d'exportation Get-Content $historyPath | Out-File $exportPath Write-Host "L'historique des commandes a été exporté avec succès à '$exportPath'" } else { Write-Host "Le fichier d'historique n'a pas été trouvé à '$historyPath'" }