# 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