Unrar archives with Powershell

Are you like me and have literally thousands of .rar archived material laying around on old disks?

It can be a pain in the lower region of the backside of your body to unrar all of those files without it being time consuming and boring as hell.

After some fiddlin’ around in PowerShell and some Googelin’, I  created this script to do the job for me. It uses unrar.exe, a commande line based extract tool to do the job, and plases the files in a directory of your choice. Just run the script, and it unrars all the archives it finds under the parent folder.

Unrar.exe can be downloaded from here.

Remember to change the directory to unrar.exe if you choose a different install dir.

Please feel free to comment if you have some way of improving or simplifying the code.

– F

(Based on the script of this awesome guy)

$parent = 'c:temprar'
$unrarred = 'c:tempunrar'
$files = @()

# Test to see if Unpackdir is present
if ((Test-Path -Path $unrarred) -ne $true)
 
# If not present, create Unpackdir
{md C:Tempunrar}


Get-ChildItem $parent -Recurse -Filter "*.rar" | % {

    # Recurse through all subfolders looking for .rar files only.

    $files = $files + $_.FullName
}

foreach ($f in $files) {

    # UnRAR the files. -y responds Yes to any queries UnRAR may have.

   C:unrarUnRAR.exe x -y $f $unrarred
}

Powershell Execution Policy

The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies:

  • Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted – No restrictions; all Windows PowerShell scripts can be run.

To assign a particular policy simply call Set-ExecutionPolicy followed by the appropriate policy name. For example, this command sets the execution policy to Unrestricted:

Set-ExecutionPolicy Unrestricted

First post!

Hi there!

Just a quick post to see if the site is working and performing well.

First of all, this site exists mainly to organize all of my thoughts and “guides” revolving Microsoft System Center Operations Manager, which I daily use in my line of work as a Surveillance Consultant.

Secondly, I needed a place other than Facebook and Instagram to present some of my photos. I bought my first SLR in 2011, and haven’t been able to put it away since. An awesome (but expensive) hobby!

My photos will be available through the Photography link in the menu above.

Please feel free to leave some constructive criticism in the comments!

Cheers,

-F