rj07thomas

Automating MSERT

Mar 18th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Del C:\Support\Scripts\Security\MSERT\*.exe
  2.  
  3. $TargetUri = (Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkId=212732").BaseResponse.RequestMessage.RequestUri.AbsoluteUri
  4.  
  5. Invoke-WebRequest $TargetUri -OutFile C:\Support\Scripts\Security\MSERT\MSERT.exe
  6.  
  7. $msertFile = Get-Item .\msert.exe
  8. $version = $msertFile.VersionInfo.ProductVersion
  9. $newName = $msertFile.BaseName
  10. $newName = $newName + "." + $version
  11. $newName = $newName + "." + "exe"
  12. ren $msertFile $newName
  13.  
  14. Invoke-Expression '& ".\$newName" /Q /F'
  15.  
  16. Clear-Host
  17.  
  18. Do
  19. {
  20. Clear-Host
  21.  
  22. $msert = Get-Process MSERT* -ErrorAction SilentlyContinue
  23.  
  24. If($msert -ne $null)
  25. {
  26. Write-Host "The time is "$(Get-Date -f yyyy-MM-dd-h-m)"and MSERT is running."
  27. }
  28.  
  29. Start-Sleep 300
  30.  
  31. } While ($msert -ne $null)
  32.  
  33. $filename = 'msert.log'
  34. $source = 'C:\Windows\Debug\' + $filename
  35. $target = 'C:\Support\Scripts\Security\MSERT\' + $filename + '.' + $(Get-Date -f yyyy-MM-dd-h-m)
  36. Move-Item $source $target
  37.  
Advertisement
Add Comment
Please, Sign In to add comment