User Jake Barteaux @day1player on GitHub made a nice code snippet to achieve this.
#### Set file associations ####
Write-Host "[-] Setting file associations..." -ForegroundColor Green
# Zip
$7zip = "${Env:ProgramFiles}\7-Zip\7z.exe"
if (Test-Path $7zip) {
$7zipfiletype = "7z.exe"
cmd /c assoc .zip=$7zipfiletype | Out-Null
cmd /c assoc .7z=$7zipfiletype | Out-Null
cmd /c assoc .tar=$7zipfiletype | Out-Null
cmd /c assoc .bz=$7zipfiletype | Out-Null
cmd /c assoc .gz=$7zipfiletype | Out-Null
cmd /c assoc .gzip=$7zipfiletype | Out-Null
cmd /c assoc .bzip=$7zipfiletype | Out-Null
cmd /c @"
ftype $7zipfiletype="$7zip" "%1" "%*" > NUL
"@
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
Set-ItemProperty -Path "HKCR:\$7zipfiletype" -Name "(DEFAULT)" -Value "$7zipfiletype file" -Force | Out-Null
Write-Host "`t[+] 7zip -> .zip" -ForegroundColor Green
}
We can generalize this approach with all the file formats listed as supported by 7-Zip.
# Zip
$7zip = "${Env:ProgramFiles}\7-Zip\7z.exe"
if (Test-Path $7zip)
{
$7zipfiletype = '7z.exe'
foreach ($ext in '7z', 'XZ', 'BZIP2', 'GZIP', 'TAR', 'ZIP', 'WIM', 'APFS', 'AR', 'ARJ', 'CAB', 'CHM', 'CPIO', 'CramFS', 'DMG', 'EXT', 'FAT', 'GPT', 'HFS', 'IHEX', 'ISO', 'LZH', 'LZMA', 'MBR', 'MSI', 'NSIS', 'NTFS', 'QCOW2', 'RAR', 'RPM', 'SquashFS', 'UDF', 'UEFI', 'VDI', 'VHD', 'VHDX', 'VMDK', 'XAR', 'Z')
{
cmd /c assoc .zip=$7zipfiletype | Out-Null
}
cmd /c @"
ftype $7zipfiletype="$7zip" "%1" "%*" > NUL
"@
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
Set-ItemProperty -Path "HKCR:\$7zipfiletype" -Name '(DEFAULT)' -Value "$7zipfiletype file" -Force | Out-Null
Write-Host "`t[+] 7zip -> .zip" -ForegroundColor Green
}
This should associate all the available file types with 7zip.