Guest User

reinstall-edge.ps1

a guest
May 7th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [CmdletBinding()]
  2. param(
  3.     [string][ValidateSet("Remove", "Install")]$Action,
  4.     [switch]$AcceptEULA
  5. )
  6.  
  7. #requires -RunAsAdministrator
  8. #requires -Version 5
  9.  
  10. <#
  11. .Synopsis
  12.    ReInstall Microsoft Edge -- v1.1 Created by: http://fatt.xyz
  13.    This script will allow you to re-install Microsoft Edge Browser for Windows 10.
  14.    The script MUST be run as administrator to function.
  15. .DESCRIPTION
  16.    There are two stages that can be run.  First, the removal of Edge.
  17.    A reboot is then required.  Afterwards, Stage 2 will re-install Edge.
  18. .EXAMPLE
  19.    Reinstall-Edge.ps1 -Action Reinstall -Verbose
  20. .NOTES
  21.    http://fatt.xyz/programs/reinstall-microsoft-edge/
  22. #>
  23.  
  24. $Host.UI.RawUI.WindowTitle = "REINSTALL MICROSOFT EDGE v1.1"
  25.  
  26. Write-Output "This script is provided for free use and contains ABSOLUTELY ZERO WARRANTY!
  27.  
  28. By using this script, you accept all liability of anything that may happen.
  29. Use it at your own risk.  FATT.XYZ are under zero obligation to address
  30. issues that may arise during the use, or misuse, of this script.  You, the
  31. user, are solely responsible for any outcomes of the use of this script.
  32. To use this script, you must agree to these conditions.
  33. Additionally, please keep in mind that THIS WILL DELETE ALL BROWSER DATA
  34. FROM EDGE including but not limited to favorites, saved passwords, cookies,
  35. history, settings, and site data.  Please ensure you backup this data
  36. before running this script if it is needed.  By proceeding, you acknowledge
  37. that you are aware that all of your Edge data will be permanently lost."
  38.  
  39. while (!$AcceptEULA) {
  40. $eulaInput = Read-Host "`nType 'I AGREE' in capitals to proceed. By proceeding you agree to the conditions above. Type 'exit' to cancel the script."
  41. if ($eulaInput -eq 'I AGREE') {$AcceptEULA = $true}
  42. elseif ($eulaInput -eq 'exit') {exit}
  43. }
  44.  
  45. Write-Verbose "Checking if machine is running Windows 10."
  46. $cimQuery = Get-CimInstance -Namespace root\cimv2 -ClassName Win32_OperatingSystem
  47. if ($cimQuery.Caption -like "Microsoft Windows 10*") {
  48.     Write-Verbose "The machine is running Windows 10."
  49. } else {
  50.     Write-Error "The operating system running on this machine is not supported by this script.
  51.    Only Windows 10 is supported."
  52.     exit
  53. }
  54.  
  55. #check if Edge is present
  56. $edgeCheck = (Test-Path -Path "$env:USERPROFILE\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe")
  57.  
  58. Function Remove-Edge {
  59.     Write-Verbose "Checking if Edge is installed."
  60.     if ($edgeCheck -eq $true) {
  61.         Write-Error "Edge is present, removing Edge"
  62.         } else {
  63.         Write-Verbose "Edge is not present. Exiting script."
  64.         exit
  65.         } #if
  66.  
  67.     Write-Verbose "Closing all instances of Edge."
  68.     Get-Process microsoftedge | Stop-Process -Force
  69.  
  70.     Write-Verbose "Removing Edge folder."
  71.     Remove-Item -Path $env:USERPROFILE\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe -Recurse
  72.  
  73.     Write-Warning "The computer needs to reboot. Relaunch the script and select '-Action Install' after reboot if Edge is to be reinstalled."
  74.     Restart-Computer -Confirm
  75. }
  76.  
  77. Function Install-Edge {
  78.     Write-Verbose "Checking if Edge is installed."
  79.     if ($edgeCheck -eq $true) {
  80.         Write-Error "Edge is present. Exiting script."
  81.         exit
  82.         } else {
  83.         Write-Verbose "Edge is not present, installing Edge."
  84.         }
  85.  
  86.     Get-AppXPackage -AllUsers -Name Microsoft.MicrosoftEdge ^ |
  87.     ForEach-Object {Add-AppxPackage -DisableDevelopmentMode -Register ^"$($_.InstallLocation)\AppXManifest.xml^" -Verbose}
  88. }
  89.  
  90.  
  91. #run whatever was specified in $Action
  92. switch ($Action) {
  93.     Remove {Remove-Edge}
  94.     Install {Install-Edge}
  95.     Default {
  96.         if ($edgeCheck -eq $true) {
  97.         Remove-Edge
  98.         } else {
  99.         Install-Edge
  100.         } #if
  101.     } #default
  102. } #switch
Advertisement
Add Comment
Please, Sign In to add comment