I use PowerShell to make doing menial tasks on my Windows 7 PC easier. I rarely save these and end up having to write them each time I want to do the same task – which is simple because PowerShell rocks.
One thing I have to do often is unrar/decompress multiple archives spanning several folders. WinRAR comes with a handy command line decompression executable – UnRAR.exe. Here is my script to do my work (mainly so that I don’t need to remember it). It needs more work to handle errors and the like, but for now it is just this.
$archive = 'C:\Path\To\Folder' # Location of the parent folder
$location = 'D:\Destination' # Location of the destination folder
$winrar = 'C:\Program Files\WinRAR\UnRAR.exe' # Location of WinRAR's UnRAR.exe
cd $location
$subfolders = dir $archive | Where-Object { $_.PSIsContainer } # Get all subfolders
$subfolders | % {
$childpath = $archive + "\" + $_.Name # Path to subfolder
Get-ChildItem $childpath -filter "*.rar" | % { # Get all RAR files in the subfolder
$file = $childpath + '\' + $_.Name # Path to RAR file in subfolder
& $winrar e $file # Executes a string as a command
}
}
