0

I have created a ps1 script to extract a 3Gb zip folder. It works Whenever I run it from PowerShell ISE but when I add my script to windows server 2019 task scheduler it just says running and it doesn't do anything.

I tried

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
Set-location C:\
sz x -oC:/ test.zip

I also tried

setx path "%path%;C:\Program Files\7-Zip"
Set-location C:\
7z x test.zip -oc:\ -r

I expect to extract the 3gbs folder.

lit
  • 14,456
  • 10
  • 65
  • 119
Salah
  • 173
  • 3
  • 17
  • 1
    Please copy and paste the command that was entered into Windows Task Scheduler. – lit Nov 11 '19 at 15:42
  • schtasks /create /tn "Extract" /sc onstart /delay 0000:30 /rl highest /ru system /tr "powershell.exe -file C:\scripts\setup\test.ps1" – Salah Nov 12 '19 at 06:32

1 Answers1

0

I was able to solve it this way:

Add-Type -Assembly "System.IO.Compression.Filesystem"
[System.IO.Compression.ZipFile]::ExtractToDirectory('C:\test.zip','C:\')

And the way I have created the Task Scheduler:

schtasks /create /tn "Extract" /sc onstart /delay 0000:30 /rl highest /ru system /tr "powershell.exe -file C:\scripts\setup\test.ps1"

It took 4 minutes to extract a 3GB folder. I found the solution here: https://ridicurious.com/2019/07/29/3-ways-to-unzip-compressed-files-using-powershell/

Salah
  • 173
  • 3
  • 17