Functions/GenXdev.Console/Invoke-Fasti.ps1
############################################################################### <# .SYNOPSIS Will extract all archive files (zip, 7z, tar, etc) found in current directory and then DELETE them .DESCRIPTION Will extract all archive files (zip, 7z, tar, etc) found in current directory and then DELETE them. Each archive file is extracted into their own directory with the same name as the file .EXAMPLE PS D:\downloads> Invoke-Fasti .NOTES You need 7z installed #> function Invoke-Fasti { [CmdletBinding()] [Alias("Fasti")] param() Get-ChildItem @("*.7z", "*.xz", "*.bzip2", "*.gzip", "*.tar", "*.zip", "*.wim", "*.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", "*.vmdk", "*.wim", "*.xar", "*.z") -File -ErrorAction SilentlyContinue | ForEach-Object { $7z = "7z" $zip = $PSItem.fullname; $n = [system.IO.Path]::GetFileNameWithoutExtension($zip); $p = [System.IO.Path]::GetDirectoryName($zip); $r = [system.Io.Path]::Combine($p, $n); if ([System.IO.Directory]::exists($r) -eq $false) { [System.IO.Directory]::CreateDirectory($r) } if ((Get-Command $7z -ErrorAction SilentlyContinue).Length -eq 0) { $7z = "C:\Program Files\7-Zip\7z.exe"; if (![IO.File]::Exists($7z)) { if ((Get-Command winget -ErrorAction SilentlyContinue).Length -eq 0) { throw "You need to install 7zip or winget first"; } winget install 7zip if (![IO.File]::Exists($7z)) { throw "You need to install 7-zip"; } } } & $7z x -y "-o$r" $zip; if ($?) { try { Remove-Item "$zip" -Force -ErrorAction silentlycontinue } catch { } } } } |