#Requires –Version 5.0 #Requires -RunAsAdministrator #Requires –Modules Dism # Get script directory if ($myInvocation.MyCommand.CommandType -ne [System.Management.Automation.CommandTypes]::Script) { $ScriptDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) } else { $ScriptDir = [System.IO.Path]::GetDirectoryName($psISE.CurrentFile.FullPath) } Set-Location "$ScriptDir" # Create mount folder if it doesn't exist if (!(Test-Path -path "$ScriptDir\Mount")) { New-Item "$ScriptDir\Mount" -Type Directory -Force | Out-Null } Get-WindowsImage -ImagePath "$ScriptDir\install.wim" -ErrorAction Stop | ForEach-Object { # Mount image(s) "{0} {1} {2}" -f "Mounting image", $($_.ImageIndex), "`n" Mount-WindowsImage -Path "$ScriptDir\Mount" -ErrorAction Stop -Index $_.ImageIndex -ImagePath $_.ImagePath | Out-Null # Get a list of all apps $AppArrayList = Get-AppxProvisionedPackage -Path "$ScriptDir\Mount" | Select-Object -Property DisplayName,PackageName | Sort-Object -Property DisplayName # Loop through the list of apps ForEach ($App in $AppArrayList) { # Exclude essential Windows apps if (($App.DisplayName -in "Microsoft.WindowsCalculator","Microsoft.WindowsStore","Microsoft.Appconnector","Microsoft.WindowsSoundRecorder")) { Write-Output -InputObject "Skipping: $($App.DisplayName)" } # Remove everything else else { $AppProvisioningPackageName = Get-AppxProvisionedPackage -Path "$ScriptDir\Mount" | Where-Object { $_.DisplayName -like $App.DisplayName } | Select-Object -ExpandProperty PackageName # Attempt to remove AppxProvisioningPackage try { Write-Output -InputObject "Removing: $AppProvisioningPackageName" Remove-AppxProvisionedPackage -PackageName $AppProvisioningPackageName -Path "$ScriptDir\Mount" -ErrorAction Stop | Out-Null } catch [System.Exception] { Write-Warning -Message $_.Exception.Message } } # Else } # ForEach #region Customise Default User Profile Write-Output -InputObject "`nCustomising the default user profile" REG LOAD "HKLM\_USER" "$ScriptDir\Mount\Users\Default\NTUSER.DAT" | Out-Null REG LOAD "HKLM\_SOFTWARE" "$ScriptDir\Mount\Windows\System32\config\SOFTWARE" | Out-Null & REG ADD "HKLM\_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v LaunchTo /d 1 /t REG_DWORD /f & REG ADD "HKLM\_USER\Software\Microsoft\Windows\CurrentVersion\Search" /v BingSearchEnabled /d 0 /t REG_DWORD /f & REG ADD "HKLM\_USER\Software\Microsoft\Windows\CurrentVersion\Search" /v SearchboxTaskbarMode /d 1 /t REG_DWORD /f & REG ADD "HKLM\_SOFTWARE\Policies\Microsoft\Windows\CloudContent" /v DisableWindowsConsumerFeatures /d 1 /t REG_DWORD /f REG UNLOAD "HKLM\_USER" | Out-Null REG UNLOAD "HKLM\_SOFTWARE" | Out-Null #endregion "{0} {1}" -f "`nUnmounting image", $($_.ImageIndex) Get-WindowsImage -Mounted | Dismount-WindowsImage -Save -ErrorAction Stop | Out-Null } # Get-WindowsImage