About Me

My photo
HANUMANGARH, RAJASTHAN, India

Friday, 15 December 2023

Reinstall the Windows default apps without error

 

# Define function to reinstall app

function Reinstall-App {

  param (

    [string]$PackageName

  )


  # Get app details

  $app = Get-AppxPackage *"$PackageName"*


  # Check if app exists

  if (!$app) {

    Write-Host "App '$PackageName' not found. Skipping..."

    return

  }


  # Try to uninstall silently (ignore errors)

  try {

    Remove-AppxPackage $app -Quiet

  } catch {}


  # Register app from AppX manifest

  try {

    Add-AppxPackage -DisableDevelopmentMode -Register "$app.InstallLocation\AppXManifest.xml"

  } catch {

    Write-Host "Error registering app '$PackageName': $_" -ForegroundColor Yellow

  }


  # Wait for installation to complete

  Start-Sleep 10


  # Check if app is installed

  $app = Get-AppxPackage *"$PackageName"*

  if (!$app) {

    Write-Host "Reinstalling '$PackageName' failed." -ForegroundColor Red

  } else {

    Write-Host "Reinstalled '$PackageName'." -ForegroundColor Green

  }

}


# List of apps to reinstall

$appsToReinstall = @("Photos", "Mail", "Calculator", "Calendar")


# Loop through apps and reinstall

foreach ($app in $appsToReinstall) {

  Reinstall-App -PackageName $app

}


# Inform user about completion

Write-Host "Reinstallation of Windows apps completed."

No comments:

Post a Comment

Export contact from Justdial

  Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company th...