直接在 PowerShell 7.5.0-rc.1 中运行此命令时,会提取存档:
Expand-Archive -path .\test.zip -DestinationPath .
但是通过 Deno 脚本运行它:
new Deno.Command("PowerShell", {
args: ["Expand-Archive -path ./test.zip -DestinationPath ."],
}).spawn();
产生这个错误:
Expand-Archive : The 'Expand-Archive'
command was found in the module
'Microsoft.PowerShell.Archive', but the
module could not be loaded. For more
information, run 'Import-Module
Microsoft.PowerShell.Archive'.
At line:1 char:1
+ Expand-Archive -path ./test.zip
-DestinationPath .
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound
: (Expand-Archive:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CouldNotAutolo
adMatchingModule
然后我运行这个脚本:
new Deno.Command("PowerShell", {
args: ["Import-Module Microsoft.PowerShell.Archive"],
}).spawn();
new Deno.Command("PowerShell", {
args: ["Expand-Archive -path ./test.zip -DestinationPath ."],
}).spawn();
并产生这个错误:
Import-Module : File C:\program files\powersh
ell\7-preview\Modules\Microsoft.PowerShell.Ar
chive\Microsoft.PowerShell.Archive.psm1
cannot be loaded because running scripts is
disabled on this system. For more
information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170
.
At line:1 char:1
+ Import-Module Microsoft.PowerShell.Archive
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError:
(:) [Import-Module], PSSecurityExceptio
n
+ FullyQualifiedErrorId : UnauthorizedAc
cess,Microsoft.PowerShell.Commands.Impor
tModuleCommand
Expand-Archive : The 'Expand-Archive'
command was found in the module
'Microsoft.PowerShell.Archive', but the
module could not be loaded. For more
information, run 'Import-Module
Microsoft.PowerShell.Archive'.
At line:1 char:1
+ Expand-Archive -path ./test.zip
-DestinationPath .
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound
: (Expand-Archive:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CouldNotAutolo
adMatchingModule
以下是执行策略的当前配置:
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Unrestricted
CurrentUser Undefined
LocalMachine Unrestricted
你有什么想法吗?