Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#Requires -RunAsAdministrator
Function Start-ReInstallAppx {
<#
.SYNOPSIS
Get back all the apps that come default with Windows 10
.DESCRIPTION
Get back all the apps that come default with Windows 10
.EXAMPLE
Start-ReInstallAppx -Filter "*Microsoft.WindowsStore*"
.NOTES
http://go.microsoft.com/fwlink/?LinkId=619547
Adapted from
http://download.microsoft.com/download/5/F/0/5F04003A-035E-4A0F-9662-43E32C546F6C/reinstall-preinstalledApps.zip
#>
[CmdletBinding(SupportsShouldProcess)]
Param(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$Filter
)
Begin {
$HT = @{ ErrorAction = 'Stop'}
}
Process {
try {
# Get all the provisioned packages
$Packages = Get-Item -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Applications' @HT |
Get-ChildItem @HT
} catch {
Write-Warning -Message "Failed to get packages list from the registry or filesystem because $($_.Exception.Message)"
}
if ($Packages) {
if ($Filter) {
$Packages = $Packages | Where-Object {$_.Name -like "$($Filter)" }
}
$Packages |
ForEach-Object -Process {
$p = $_
$PackageName = $PackagePath = $null
# get package name & path
try {
$d = $p | Get-ItemProperty @HT
if ($d) {
$PackageName = $d | Select-Object -ExpandProperty PSChildName
$PackagePath = [System.Environment]::ExpandEnvironmentVariables(($d| Select-Object -ExpandProperty Path))
}
} catch {
Write-Warning -Message "Failed to get package name and path for package $($p) because $($_.Exception.Message)"
}
# register the package
if ($PackageName -and $PackagePath) {
Write-Verbose -Message "Attempting to register package: $($PackageName)"
if ($PSCmdlet.ShouldProcess("$($PackageName))",'Register Appx package')) {
try {
Add-AppxPackage -Register $PackagePath -DisableDevelopmentMode @HT
Write-Verbose -Message "Successfully registered package from path $($PackagePath)"
} catch {
Write-Warning -Message "Failed to regiter from $($PackagePath) because $($_.Exception.Message)"
}
}
}
}
}
}
End {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment