Isaiah Melendez
asked on
Powershell 7zip extract and Move
Dear Experts,
Could you provide an example of extracting .7z files with 7zip and moving the extracted all .7z files to a network directory?
.7z directory = C:\source
move extracted files directory = \\servername\c$\destinatio n
Doing all this via powershell 3.0?
Could you provide an example of extracting .7z files with 7zip and moving the extracted all .7z files to a network directory?
.7z directory = C:\source
move extracted files directory = \\servername\c$\destinatio
Doing all this via powershell 3.0?
This will expand the files directly to the target folder:
Function Expand-Archive([string]$Path, [string]$Destination) {
$7z_Application = "C:\Program Files\7-Zip\7z.exe"
$7z_Arguments = @(
'x' ## eXtract files with full paths
'-y' ## assume Yes on all queries
"`"-o$($Destination)`"" ## set Output directory
"`"$($Path)`"" ## <archive_name>
)
& $7z_Application $7z_Arguments
}
Get-ChildItem "C:\source" -Filter *.7z | ForEach-Object {
Expand-Archive -Path $_.FullName -Destination "\\servername\c$\destination"
}
ASKER
ObDA,
Your solution is 99% there. The only part I am missing was actually moving/deleting the files from the source location. So basically, if test1.7z and test2.7z are in the c:\source dir I want them to get deleted once the extract has been done into the \\servername\c$\destinatio n location.
Does that make sense?
Your solution is 99% there. The only part I am missing was actually moving/deleting the files from the source location. So basically, if test1.7z and test2.7z are in the c:\source dir I want them to get deleted once the extract has been done into the \\servername\c$\destinatio
Does that make sense?
Hey there sj77, use Remove-Item * -Include *.7z or something similar to do that.
https://msdn.microsoft.com /en-us/pow ershell/re ference/5. 1/microsof t.powershe ll.managem ent/remove -item
https://msdn.microsoft.com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Greg,
Like this?
Like this?
Function Expand-Archive([string]$Path, [string]$Destination) {
$7z_Application = "C:\Program Files\7-Zip\7z.exe"
$7z_Arguments = @(
'x' ## eXtract files with full paths
'-y' ## assume Yes on all queries
"`"-o$($Destination)`"" ## set Output directory
"`"$($Path)`"" ## <archive_name>
)
& $7z_Application $7z_Arguments
Remove-Item * -Include *.7z
}
oBdA's response is very much on point and thorough sj77. I want to keep that in my toolbox going forward too :P
Hello guys,
can you please help me how to use the Expand-Archive function if a 7z file is password protected? Of course, i know the password :)
Thanks in advanced for your help.
Best regards,
Zoltan
can you please help me how to use the Expand-Archive function if a 7z file is password protected? Of course, i know the password :)
Thanks in advanced for your help.
Best regards,
Zoltan
https://gallery.technet.mi
From there on it's just Move-Item (or Get-ChildItem -Recurse "somewhere" | Move-Item "toSomewhereElse". Check this out for that...
https://msdn.microsoft.com
Let me know if that helps?