Código
Import-Module Microsoft.PowerShell.Management [System.Console]::Title = "3rd Party Driver Backup Tool - by Elektro" [CultureInfo]::CurrentUICulture = "en-US" try { Set-ExecutionPolicy -ExecutionPolicy "Unrestricted" -Scope "Process" } catch { } $Timestamp = Get-Date -Format "yyyy∕MMMM∕dd HH꞉mm꞉ss" $OutputDirectory = "$env:USERPROFILE\Desktop\3rd Party Drivers Backup $Timestamp" Do { Clear-Host Write-Host "" Write-Host " $($host.ui.RawUI.WindowTitle)" Write-Host " +===========================================================+" Write-Host " | |" Write-Host " | This script will make a full backup of the 3rd party |" Write-Host " | device drivers that are installed in the current machine, |" Write-Host " | and will save them into the user's desktop directory. |" Write-Host " | |" Write-Host " +===========================================================+" Write-Host "" Write-Host " CURRENT SCRIPT CONFIG:" Write-Host " ----------------------" Write-Host "" Write-Host " Output Directory:" Write-Host " $OutputDirectory" Write-Host " ___________________________________________________________" Write-Host "" Write-Host " -Continue? (Y/N)" $key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") $char = $key.Character.ToString().ToUpper() if ($char -ne "Y" -and $char -ne "N") { [console]::beep(1500, 500) } } while ($char -ne "Y" -and $char -ne "N") if ($char -eq "N") {Exit(1)} else {Clear-Host} if (-not (Test-Path $OutputDirectory)) { New-Item -Path "$OutputDirectory" -ItemType "Directory" -Force | Out-Null } & { $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.FileName = "DISM.exe" $psi.Arguments = "/Online /Export-Driver /Destination:""$OutputDirectory""" $psi.UseShellExecute = $false $p = [System.Diagnostics.Process]::Start($psi) $p.WaitForExit() $dismExitCode = $p.ExitCode if ($dismExitCode -eq 0) { Write-Host "" Write-Host "Operation Completed!" -BackgroundColor Black -ForegroundColor Green Write-Host "" } else { Write-Host "" Write-Host "Operation Failed. Confirm to delete the output directory:" -BackgroundColor Black -ForegroundColor Red Write-Host "" Remove-Item -Path "$OutputDirectory" -Recurse -Force -ErrorAction SilentlyContinue -Confirm:$true } } Write-Host "" Write-Host "Press any key to exit..." $key = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") Exit($dismExitCode)