At the heart of this example is [WmiClass]"\\$SysName\root\default:systemrestore".
Once we assign it to the variable $SysRestore, we can apply one of two
methods, .Disable("C:\") or .Enable("C:\").
The rest of the script consists of two wrappers, one to switch
between "Enable" and "Disable", the other wrapper is
the function called Set-SysRestore.
It is traditional to name PowerShell functions using existing verbs such as
'get-' or 'set-'. At the heart of this function is the switch ($RestoreOpt)
which calls upon the WMI class systemrestore. It is this parameter which
provides the option to enable or disable the system restore.
One important point, you need to supply a different value for $sysName.
########################################## ## ## Author: Dave Stone, Brooks Automation
## Date: 6 May 2010 ## Enables or disables the system restore on a
given computer ## ## Usage Set-SysRestore option computername
## ######################################
Function Set-SysRestore { param( $RestoreOpt =
$(throw "please specify option, disable or enable"), $sysName =
$(throw "please specify a computer name or IP Address. ` Enclose
entries containing spaces with single quotes") ) switch ($RestoreOpt)
{ "disable" {$SysRestore = [wmiclass]"\\$sysname\root\default:systemrestore"
$SysRestore.Disable("C:\")} "enable"
{$SysRestore = [wmiclass]"\\$sysname\root\default:systemrestore"
$SysRestore.Enable("C:\")} }
} Set-SysRestore -RestoreOpt disable -SysName 192.168.1.166
Note 0: This is one of those PowerShell scripts
where you need to 'Run as Administrator'. Also Restore Points are a feature of
client operating systems such as Windows 7 or Vista, and not servers.
Note 1: Trace the two options for the -RestoreOpt
parameter. The last line puts the function
Set-SysRestore to work, and disables the system restore on the C:\.
Note 2: To turn on your restore, issue the
reverse command: Set-SysRestore -RestoreOpt enable -SysName
YourComputer
Note 3: Pay close attention to -SysName, your
Windows 7 or Vista machine is unlikely to have an IP address of
192.168.1.166. You could of course use the hostname.
Guy Recommends: Solarwinds' Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the
users with their fields in the
top row, and save as .csv file. Then launch this FREE utility and match
your fields with AD's
attributes, click to import the users. Optionally, you can
provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
When I was trying to repair a Vista machine, I got into a knot trying a
system restore; this was because the anti-virus program kept giving a false positive
reaction to a file that I was trying to repair. By creating a
PowerShell function I was able to control system restore while I sorted out
the anti-virus problem.
Maybe the drive has run out of free space and you need to stop system
restore consuming any more disk space.
One Advantage of the above WMI technique is that you can turn off
system protection on the D, E or other drives. However, if you
just wish to disable system restore on the C:\ drive then you can use
PowerShell v 2.0's Disable-ComputerRestore cmdlet.
Please email me if you have a script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.