Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell WMI SystemRestore

Introduction to PowerShell WMI SystemRestore SystemRestore WMI PowerShell

This real-life task for PowerShell is to control your desktop computer's system restore points.

We will employ the WMI SystemRestore class to enable, or disable, the protection settings for restore points.

(Screenshot of Control Panel, System, Advanced Tab)

Topics for SystemRestore

 ♣

WMI Class SystemRestore

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.

Set-SysRestore Function

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. SystemRestore WMI PowerShell

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

Example:
Set-SysRestore -RestoreOpt enable -SysName MyComputer

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 ToolFree Download of Solarwinds  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:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

Possible Reasons for Turning Off System Restore

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.

Disable-ComputerRestore

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.

# PowerShell 2.0 Disable ComputerRestore Script
Clear-Host
#Enable-ComputerRestore -drive "C:\"
Disable-ComputerRestore -drive "C:\"

Summary of PowerShell SystemRestore

Thanks to PowerShell's [WMI] we can access SystemRestore and thus enable or disable protection of the C:\ or another drive.

If you like this page then please share it with your friends

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • WMI Services   • Win32_ComputerSystem

WMI Class  • [WMI] Type  • Win32_printer   • Win32_product   • SystemRestore

WMI Disk   • DNS   • PowerShell -Filter   • Windows PowerShell   • Memory

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

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.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.