Enable-ComputerRestore

Using Enable-ComputerRestore in PowerShell

Welcome back to Wahman’s PowerShell blog! Today, we’re taking a look at a useful PowerShell cmdlet that allows you to control one of Windows’ most resilient security and recovery features: System Restore. The cmdlet is Enable-ComputerRestore.

As described by Microsoft, Enable-ComputerRestore enables the System Restore feature on the specified file system drive(s). Once enabled, Windows will periodically create restore points that can be used to roll back the system to a previous state in case of system issues.

Syntax

Enable-ComputerRestore [-Drive] <String[]>

Why Use Enable-ComputerRestore?

If you’re managing a fleet of workstations or servers, or even just your personal machine, ensuring System Restore is enabled can be critical when trying to recover from failed updates, driver incompatibilities, or user errors that destabilize your system. Let’s walk through some practical examples, from basic to advanced usage.

Example 1: Enable System Restore on the C: Drive (Beginner)

This is the most common use case. You’re simply enabling System Restore on the main system drive:

Enable-ComputerRestore -Drive "C:\"

Example 2: Enable on Multiple Drives (Intermediate)

If you have multiple drives on which you’d like to enable System Restore:

Enable-ComputerRestore -Drive "C:\", "D:\"

Example 3: Checks and Enables Restore If Not Already Enabled (Intermediate)

This example helps you avoid re-enabling manually. Check if System Restore is already enabled using WMI, and only enable it if it isn’t.

$drive = "C:\"
$restoreStatus = Get-WmiObject -Namespace "root\default" -Class SystemRestore | Where-Object { $_.Drive -eq $drive }

if (-not $restoreStatus) {
    Enable-ComputerRestore -Drive $drive
    Write-Output "System Restore was disabled. Now enabled on $drive."
} else {
    Write-Output "System Restore is already enabled on $drive."
}

Example 4: Enable System Restore on All Logical Drives Programmatically (Advanced)

This approach dynamically enables System Restore on all logical drives that support it:

$drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.DisplayRoot -ne $null } | ForEach-Object { $_.Root }
Enable-ComputerRestore -Drive $drives
Write-Output "Enabled System Restore on all logical drives: $($drives -join ", ")"

Final Thoughts

Enable-ComputerRestore is a critical tool in every system administrator’s toolbox. It provides a simple way to help protect your systems against unexpected failures and keeps recovery just a restore point away.

Remember, enabling System Restore does not immediately create a restore point. You might want to manually create one after enabling using the Checkpoint-Computer cmdlet.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *