Results 1 to 3 of 3
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts

    Cool My First PowerShell Utility

    Hello All,

    As you know from previous posts in this thread I've been trying to learn PowerShell, it is an experience let me tell you.

    All that aside I have managed to write a small script some of you may find useful. The script will list all the current system restore points that are saved in your system or you can list just those of a certian type like Installs, Uninstalls, Manually Created, or Windows Update created.

    This script does require administrator privileges. I tried to run it from a Scheduled Task but then I couldn't set the window size/colors/font and quite a bit of the output was truncated. So I settled for a shortcut with the Administrator option checked. you still have 1 extra click to approve the elevation but it does work. Here's how I setup the shortcut:
    Code:
    ShortCut Properties:
     Tab           Settings
    ShortCut     Target: powershell.exe d:\{path to file}\RestorePointsByType.ps1"
                     Run:    Normal window.
                     Icon:    %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
                     Advanced: Check "Run as administrator" {you'll still have to click the YES button but at least you won't have to remember to run as administrator}
    Layout         Window size: 140
                      Window height: 45
    Colors         Screen background: Lt. Blue   {my preferences choose your own}
                               text          : Black
    Here's the actual code...just paste it into Notepad and name the file RestorePointsByType.ps1.
    Code:
    param( $rpType = -1 )
    
    #  Programmed by: RetiredGeek @ WSL
    #  Version No:    1.4
    #  Last Updated:     31 July 2011
    
    # Notes:
    # In the normal output for Get-ComputerRestorePoint:
    #    Type 0 shows as APPLICATION_INSTALL
    #    Type 1 shows as APPLICATION_UNINSTALL
    #  You MUST use the numbers for comparision!
    #  Using an UNTyped param allows the use of the * for the All option
    
       If ($rpType -eq -1) {
    # Note: If you use single vs double quotes the new-lines will not interpret!     
         $p ="`nParameter Required:`n`n"
         $p = $p + " * = All`n"
         $p = $p + " 0 = Installations`n"
         $p = $p + " 1 = Uninstalls`n"
         $p = $p + "16 = Manually Created`n"
         $p = $p + "18 = Windows Update Created`n"
        
        $rptype = Read-Host "$p`nEnter the Number for the desired Restore Points."
        if ($rpType -eq "") 
        {
          Exit
        }  # End If  
       } # End If  $rpType -eq -1
       
       switch($rpType)
       {
         ""      {Break}                       #No selection Exit program
         '*'     {Get-ComputerRestorePoint}    #Display All Restore Poits
         default {
                   foreach($rp in Get-ComputerRestorePoint) {
                       if ($rp.RestorePointType -eq [int] $rpType) {
                         $rp
                       } # End if
                   } # End foreach
                 } # End default case  
        } #End switch
    
        $rpType = Read-Host "`n`nPress Any key to exit"
    I've heavily commented the code {my normal habit} to help me and any reader understand what is going on.

    Comments and especially code improvements gratefully accepted.

    P.S. I forgot to mention that if you call the program from a command line you can add an argument for the type of Restore Points you want listed, just append the appropriate number (see comments at top of script for numbers). If you do not supply an argument you will be prompted.
    Last edited by RetiredGeek; 2011-08-01 at 12:49. Reason: Per RR's suggestion
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  2. #2
    Gold Lounger
    Join Date
    Oct 2007
    Location
    Johnson City, Tennessee, USA
    Posts
    3,202
    Thanks
    37
    Thanked 215 Times in 202 Posts
    Quote Originally Posted by RetiredGeek View Post

    Comments and especially code improvements gratefully accepted.
    "Geekster"
    I'm in AWE! ... Although i do not use "System Restore" , and this may be already available... But i think that if you could selectively choose which restore point(s) that you want to save or delete would be of help. Just a thought.... Maybe you could do a thread on "Power Shell " basics... Regards Fred
    PlainFred

    None are so hopelessly enslaved as those who falsely believe they are free (J. W. Von Goethe)

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by Just Plain Fred View Post
    "Geekster"
    Maybe you could do a thread on "Power Shell " basics...
    Fred,

    I'd love to...once I understand them. It's been quite a slog but I'm slowly starting to understand things. It is quite a challenge between the 1 book I have, the quick reference guide, the MDSN pages on Powershell, and lots of Googling! I'm currently working through redoing a script I downloaded so it will give you a very quick look into your computer. I know SIW, BelArc, etc., already do this but it's the challenge and it is very quick. The hardest thing is getting things formatted. I actually had to write information to a file and read it back in to get rid of all the empty lines PS put in the output, then delete the temp file. How's the song go..."We'll have fun fun fun...."
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •