Advertisement
Guest User

Untitled

a guest
May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Backup-BitlockerasSystem
  2. $urlPSexec = 'https://live.sysinternals.com/psexec.exe'
  3. $psexecEXE = 'C:\Windows\Temp\psexec.exe'
  4. $out = [System.IO.Path]::GetTempFileName()
  5.  
  6.  
  7. if (!$(Test-Path $psexecEXE))
  8. {
  9.     Write-Host "Downloading $urlPSexec to $psexecEXE"
  10.     (New-Object System.Net.WebClient).DownloadFile($urlPSexec, $psexecEXE)
  11. }
  12.  
  13. #The command to run as the system account. Using Start-Transcript to get the results
  14. [String]$backupCommand = "Start-Transcript -Path ""$out"";Backup-BitLockerKeyProtector -MountPoint 'C:' -KeyProtectorId " + '$((Get-BitLockerVolume -MountPoint "C:").KeyProtector[1].KeyProtectorId)'
  15.  
  16. Write-Host "Running command as system: $backupCommand"
  17. #Start Powershell as the system account and run $backupCommand
  18. $procPsExec = Start-Process -PassThru -Wait -FilePath $psexecEXE -ArgumentList "-acceptEULA -s -i powershell -noprofile -command $backupcommand"
  19. Write-Host "PSExec process exited with code $($procPsExec.ExitCode)"
  20. if ($procPsExec.ExitCode -eq 0)
  21. {
  22.     #Display Success message
  23.     Write-Host "Bitlocker Backup was success"
  24.     Write-Host $(Get-Content $out | Out-String)
  25. } else {
  26.     #Display Failure
  27.     Write-Host "Bitlocker Backup was failure"
  28.     Write-Error $(Get-Content $out | Out-String)
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement