7Zip Extract Rar Files to Folder from rar Name

# To run on your computer, Install the Powershell 7 Zip Module
# https://github.com/thoemmi/7Zip4Powershell

# ==================
# Extract .rar files
# ==================
Import-Module 7zip4Powershell
$Folder = "C:\Temp\Ebooks 2013\"
$rars = Get-ChildItem "$Folder\*.rar"
#Get-ChildItem *.rar
ForEach ($rar in $rars){  
    $outputFolder = [io.path]::GetFileNameWithoutExtension("$rar")
    Write-Output "$outputFolder"
    
    Expand-7Zip -ArchiveFileName $rar -TargetPath "$Folder\$outputFolder"
    
}

 

7 Zip Compress directory

 

# This script can be used to zip a dirctory with plain powershell.
$source = "C:\temp"
$destination = "D:\temp.zip"
 
If(Test-path $destination) {Remove-item $destination}
Add-Type -assembly "system.io.compression.filesystem"
 
[io.compression.zipfile]::CreateFromDirectory($Source, $destination)