提取7zip脚本在Windows Server 2019任务计划程序中不起作用

时间:2019-11-11 15:10:38

标签: powershell amazon-ec2 7zip taskscheduler windows-server-2019

我创建了一个ps1脚本来提取3Gb zip文件夹。每当我从PowerShell ISE运行它时,它都可以工作,但是当我将脚本添加到Windows Server 2019任务计划程序时,它只是说正在运行,并且它什么都不做。

我尝试过

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

我也尝试过

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

我希望提取3gbs文件夹。

1 个答案:

答案 0 :(得分:0)

我能够这样解决:

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

以及我创建任务计划程序的方式:

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

提取3GB文件夹花费了4分钟。 我在这里找到解决方案: https://ridicurious.com/2019/07/29/3-ways-to-unzip-compressed-files-using-powershell/