解压压缩文件通过powershell,我使用下面的脚本。但我得到这个错误信息
Microsoft.PowerShell.Archive\Expand-Archive : The module 'Microsoft.PowerShell.Archive' could not be loaded. For more
information, run 'Import-Module Microsoft.PowerShell.Archive'.
At C:\windowsagentinstall.ps1:34 char:1
+ Microsoft.PowerShell.Archive\Expand-Archive -Path ApplicareSingleAgentWindows.Zi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...\Expand-Archive:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
这是我的剧本
echo "Downloading Applicare SingleAgent Installer ..."
#This will hide the progress bar. If the progress bar is enabled it will slow the download process
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $env:PROTOCOL"://"$env:IP":"$env:PORT/applicare/standalone?userId=$env:USERID"&"filename=ApplicareSingleAgentWindows.zip -OutFile $pwd\ApplicareSingleAgentWindows.zip
echo "Download Complete"
try {
$scriptPath = $PSScriptRoot
if (!$scriptPath)
{
if ($psISE)
{
$scriptPath = Split-Path -Parent -Path $psISE.CurrentFile.FullPath
}
else {
Write-Host -ForegroundColor Red "Cannot resolve script file's path"
exit 1
}
}
}
catch {
Write-Host -ForegroundColor Red "Caught Exception: $($Error[0].Exception.Message)"
exit 2
}
#echo "Current directory"
Write-Host "SingleAgent downloaded in Path: $scriptPath"
echo "Creating ApplicareSingleAgentWindows directory"
New-Item -Path 'ApplicareSingleAgentWindows' -ItemType Directory -Force
echo "Extracting ApplicareSingleagent zip file to ApplicareSingleAgentWindows directory"
Microsoft.PowerShell.Archive\Expand-Archive -Path ApplicareSingleAgentWindows.Zip -DestinationPath "$scriptPath\ApplicareSingleAgentWindows" -Force
Set-Location -Path "$scriptPath\ApplicareSingleAgentWindows"
我执行此“Import-Module Microsoft.PowerShell.Archive”命令,但它不起作用,我得到以下错误
Import-Module : The specified module 'Microsoft.PowerShell.Archive' was not loaded because no valid module file was
found in any module directory.
At line:1 char:1
+ Import-Module Microsoft.PowerShell.Archive
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Microsoft.PowerShell.Archive:String) [Import-Module], FileNotFound
Exception
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
我尝试了另一个命令,得到了相同的问题。“Install-Module -Name Microsoft.PowerShell.Archive -RequiredVersion 1.2.5”
PS C:\ApplicareSingleAgentWindows> Install-Module -Name Microsoft.PowerShell.Archive -RequiredVersion 1.2.5
Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Install-Module -Name Microsoft.PowerShell.Archive -RequiredVersion 1.2.5
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
1条答案
按热度按时间7fhtutme1#
您声明您使用的是PowerShell 4.0。
Microsoft.PowerShell.Archive
模块。PowerShellGet
模块,因此您无法使用Install-Module
来安装它。你有两个选择:
PowerShellGet
模块,以便使Install-Module
对您可用,这使您可以安装PowerShell Gallery中可用的 * 任何 * 模块。Save-Module
,您可以从该机器将下载的模块复制到v4机器。