PowerShell for Windows Admins

Jan 23 2011   1:10PM GMT

System Restore Points

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

PowerShell 2.0 supplies 4 cmdlets for working with system restore points. 

Disable-ComputerRestore
Enable-ComputerRestore
Get-ComputerRestorePoint
Restore-Computer

This is great but they only work with the local machine. You can test this easily by either looking at the help for each one or use

get-help * -Parameter computer*

to view all of the cmdlets with a computer related parameter.

YOU HAVE TO BE RUNNING POWERSHELL WITH ELEVATED PRIVILEGES FOR THIS TO WORK

Let’s start with Get-ComputerRestorePoint. We can perform this task using

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore

This starts the display with the oldest restore point. I want it the other way up. 

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending

I also only want the CreationTime, Sequence number and description

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending |
Format-Table SequenceNumber, CreationTime, Description –AutoSize

At this point we loose the formatting on the date and it reverts to WMI format.  Well, we know how to deal with that.

Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore |
sort SequenceNumber -Descending |
Format-Table SequenceNumber,
@{Name="Date"; Expression={$($_.ConvertToDateTime($_.CreationTime))}},
Description –AutoSize

Now I want to wrap this into a function

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
function get-systemrestorepoint {
[CmdletBinding()]
param ( 
[string]$computername="."
) 

$test = Test-Connection -ComputerName $computername -Count 1
if (-not ($test)){Throw "Computer $computername not reachable"
}

 Get-WmiObject -Namespace ‘root\default’ -Class SystemRestore `
 
-ComputerName $computername |
 
 
sort SequenceNumber -Descending |
 Format-Table SequenceNumber,
 
 @{Name
="Date"; Expression={$($_.ConvertToDateTime($_.CreationTime))}},
 Description -AutoSize
}

 

 

 

 

I can use this to access the system restore points on remote machines.  This becomes the first function in a new PAM module.  I’ll develop the rest over a series of posts.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: