Script to refresh Windows 8 (PowerShell) 

Introduction 

This PowerShell script shows how to create custom refresh image. 

Scenarios 

Windows Refresh gives you a quick and easy way to start with a clean slate while also maintaining your apps, data, Windows settings, and user profile. 

Script 

Step1: Run the script in the Windows PowerShell Console, type the one command: Import-Module <Script Path> at the prompt.For example, type Import-Module C:\Script\ RefreshWindows8.psm1

This is shown in the following figure. 

Step2: You can type the command Get-Help Set-OSCRefreshReImage -Full to display the entire help file for this function, such as the syntax, parameters, or examples.  

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
If($PingResult) 
{ 
    If (Test-Path-Path $Path) 
    { 
        $FileExtension = Get-ChildItem-Path $Path|ForEach-Object{$_.Extension -eq ".wim"} 
        If($FileExtension) 
        { 
            Write-Host "Setting the current custom recovery image..."-ForegroundColor Green 
            Invoke-Expression-Command "recimg /setcurrent $Path" 
        } 
        Else 
        { 
            Write-Warning"Can not find *.wim file in $Path." 
        } 
    } 
    Else 
    { 
        Write-Warning"Cannot find path '$Path' because it does not exist." 
    } 
} 
Else 
{ 
    Write-Host "Failed to connect to $CN!, Please make sure your connectivity is unobstructed."-ForegroundColor Yellow 
}

Example 

Example 1: Type Set-OSCRefreshReImage -Path <Directory> command in the Windows PowerShell Console. 

This command set the active recovery image to the CustomRefresh.wim file in the location by the "C:\Script" Folder.

Prerequisite

Windows PowerShell 3.0
Windows 8