Home > Tech Tips > Fixing Windows 10 Corruption with PowerShell

Fixing Windows 10 Corruption with PowerShell

This isn’t anything new but after a few quick searches on Google, I was only hitting pages using the older dism.exe instead of the PowerShell cmdlets. There are cmdlets in the dism PowerShell module which provide the same capabilities for repairing Windows 10.

Using the PowerShell cmdlets instead of dism.exe is so much faster.

Module and Cmdlets

PS C:\Windows\system32> get-command -module dism

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Add-AppProvisionedPackage                          3.0        Dism
Alias           Add-ProvisionedAppPackage                          3.0        Dism
Alias           Add-ProvisionedAppxPackage                         3.0        Dism
Alias           Apply-WindowsUnattend                              3.0        Dism
Alias           Get-AppProvisionedPackage                          3.0        Dism
Alias           Get-ProvisionedAppPackage                          3.0        Dism
Alias           Get-ProvisionedAppxPackage                         3.0        Dism
Alias           Optimize-AppProvisionedPackages                    3.0        Dism
Alias           Optimize-ProvisionedAppPackages                    3.0        Dism
Alias           Optimize-ProvisionedAppxPackages                   3.0        Dism
Alias           Remove-AppProvisionedPackage                       3.0        Dism
Alias           Remove-ProvisionedAppPackage                       3.0        Dism
Alias           Remove-ProvisionedAppxPackage                      3.0        Dism
Alias           Set-AppPackageProvisionedDataFile                  3.0        Dism
Alias           Set-ProvisionedAppPackageDataFile                  3.0        Dism
Alias           Set-ProvisionedAppXDataFile                        3.0        Dism
Cmdlet          Add-AppxProvisionedPackage                         3.0        Dism
Cmdlet          Add-WindowsCapability                              3.0        Dism
Cmdlet          Add-WindowsDriver                                  3.0        Dism
Cmdlet          Add-WindowsImage                                   3.0        Dism
Cmdlet          Add-WindowsPackage                                 3.0        Dism
Cmdlet          Clear-WindowsCorruptMountPoint                     3.0        Dism
Cmdlet          Disable-WindowsOptionalFeature                     3.0        Dism
Cmdlet          Dismount-WindowsImage                              3.0        Dism
Cmdlet          Enable-WindowsOptionalFeature                      3.0        Dism
Cmdlet          Expand-WindowsCustomDataImage                      3.0        Dism
Cmdlet          Expand-WindowsImage                                3.0        Dism
Cmdlet          Export-WindowsCapabilitySource                     3.0        Dism
Cmdlet          Export-WindowsDriver                               3.0        Dism
Cmdlet          Export-WindowsImage                                3.0        Dism
Cmdlet          Get-AppxProvisionedPackage                         3.0        Dism
Cmdlet          Get-NonRemovableAppsPolicy                         3.0        Dism
Cmdlet          Get-WIMBootEntry                                   3.0        Dism
Cmdlet          Get-WindowsCapability                              3.0        Dism
Cmdlet          Get-WindowsDriver                                  3.0        Dism
Cmdlet          Get-WindowsEdition                                 3.0        Dism
Cmdlet          Get-WindowsImage                                   3.0        Dism
Cmdlet          Get-WindowsImageContent                            3.0        Dism
Cmdlet          Get-WindowsOptionalFeature                         3.0        Dism
Cmdlet          Get-WindowsPackage                                 3.0        Dism
Cmdlet          Get-WindowsReservedStorageState                    3.0        Dism
Cmdlet          Mount-WindowsImage                                 3.0        Dism
Cmdlet          New-WindowsCustomImage                             3.0        Dism
Cmdlet          New-WindowsImage                                   3.0        Dism
Cmdlet          Optimize-AppXProvisionedPackages                   3.0        Dism
Cmdlet          Optimize-WindowsImage                              3.0        Dism
Cmdlet          Remove-AppxProvisionedPackage                      3.0        Dism
Cmdlet          Remove-WindowsCapability                           3.0        Dism
Cmdlet          Remove-WindowsDriver                               3.0        Dism
Cmdlet          Remove-WindowsImage                                3.0        Dism
Cmdlet          Remove-WindowsPackage                              3.0        Dism
Cmdlet          Repair-WindowsImage                                3.0        Dism
Cmdlet          Save-WindowsImage                                  3.0        Dism
Cmdlet          Set-AppXProvisionedDataFile                        3.0        Dism
Cmdlet          Set-NonRemovableAppsPolicy                         3.0        Dism
Cmdlet          Set-WindowsEdition                                 3.0        Dism
Cmdlet          Set-WindowsProductKey                              3.0        Dism
Cmdlet          Set-WindowsReservedStorageState                    3.0        Dism
Cmdlet          Split-WindowsImage                                 3.0        Dism
Cmdlet          Start-OSUninstall                                  3.0        Dism
Cmdlet          Update-WIMBootEntry                                3.0        Dism
Cmdlet          Use-WindowsUnattend                                3.0        Dism

You can run a check to see if Windows has been flagged for corruption by something that failed.

Repair-WindowsImage -Online -CheckHealth

With the ScanHealth parameter you can check for component store corruption.

Repair-WindowsImage -Online -ScanHealth

Then you can check the scan.

Lastly, the repair.

Repair-WindowsImage -Online -RestoreHealth

I had plenty of my own issues with Windows 10 2004 and had to perform a repair using a newly created Windows 10 iso from the Media Creation Tool. First, mount the ISO. I saved the file just to my desktop.

Mount-DiskImage -ImagePath $Env:USERPROFILE\Desktop\Windows.iso -StorageType ISO -Access ReadOnly

The ISO mounted as drive E: on my system. Then I had to retrieve the index number of Windows 10 Pro so I can specify that as the source.

PS C:\Windows\system32> Get-WindowsImage -ImagePath E:\sources\install.esd


ImageIndex       : 1
ImageName        : Windows 10 Home
ImageDescription : Windows 10 Home
ImageSize        : 14,321,196,908 bytes

ImageIndex       : 2
ImageName        : Windows 10 Home N
ImageDescription : Windows 10 Home N
ImageSize        : 13,561,654,913 bytes

ImageIndex       : 3
ImageName        : Windows 10 Home Single Language
ImageDescription : Windows 10 Home Single Language
ImageSize        : 14,323,311,629 bytes

ImageIndex       : 4
ImageName        : Windows 10 Education
ImageDescription : Windows 10 Education
ImageSize        : 14,564,034,276 bytes

ImageIndex       : 5
ImageName        : Windows 10 Education N
ImageDescription : Windows 10 Education N
ImageSize        : 13,805,519,197 bytes

ImageIndex       : 6
ImageName        : Windows 10 Pro
ImageDescription : Windows 10 Pro
ImageSize        : 14,564,675,087 bytes

ImageIndex       : 7
ImageName        : Windows 10 Pro N
ImageDescription : Windows 10 Pro N
ImageSize        : 13,805,865,233 bytes

I tried to repair my Windows 10 2004 box directly from the esd file.

Repair-WindowsImage -Online -RestoreHealth -Source "esd:E:\sources\install.esd:6" -LimitAccess

Unforturnatly, after checking the dism.log file, it seems that it couldn’t use the esd file…. Bummer.

So I had to extract a wim from the esd file.

Export-WindowsImage -SourceImagePath E:\sources\install.esd -SourceIndex 6 -DestinationImagePath $Env:USERPROFILE\Desktop\install.wim -CompressionType None -CheckIntegrity

I wanted to check everything and make sure it landed ok.

Get-WindowsImage -ImagePath $Env:USERPROFILE\Desktop\install.wim


ImageIndex       : 1
ImageName        : Windows 10 Pro
ImageDescription : Windows 10 Pro
ImageSize        : 14,564,675,087 bytes

I know this is getting redundant, but you should know how it goes. Just try, try, and try again……

Repair-WindowsImage -Online -RestoreHealth -Source "wim:$env:USERPROFILE\Desktop\install.wim:1" -LimitAccess -Verbose

The only thing left is to dismount the ISO image.

Dismount-DiskImage -ImagePath $env:USERPROFILE\Desktop\Windows.iso