Search code examples
powershellzip

is there a powershell script that takes the first 3 zip folder sorted by date from a folder A and extracts them into a folder B?


I need to take the first 3 zip folder sorted by date and then extract them into a specific folder I tried this script but it doesn't work

percorso = Get-ChildItem -Path  'C:\first'| Sort-Object LastWriteTime -Descending 
ForEach ($file in (Get-ChildItem -Path "C:\first")[0..2]){Expand-Archive -DestinationPath 'C:\Users\second' -Force}

thanks


Solution

  • I think it should be the below. You weren't passing the source file path to Expand-Archive at all.

    $AllFiles = Get-ChildItem -Path  'C:\first'| Sort-Object LastWriteTime -Descending 
    ForEach ($File in $AllFiles[0..2]){
        Expand-Archive -Path $File -DestinationPath 'C:\Users\second' -Force}