2017-08-07 27 views
1

我已经写了下面的脚本PS使用到7zip的文件夹7Zip4Powershell然而,当它失败,出现以下错误在生成过程中:TFS PowerShell的安装,模块没有发现

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 C:\Build\Work\19\s\DevOps\7zCompress.ps1:3 char:5 
+ Install-Module -Scope CurrentUser -Name 7Zip4PowerShell -Verbose -Force 
+ ~~~~~~~~~~~~~~ 
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException 
+ FullyQualifiedErrorId : CommandNotFoundException 
Compress-7Zip : The term 'Compress-7Zip' 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 C:\Build\Work\19\s\DevOps\7zCompress.ps1:18 char:1 
+ Compress-7Zip -Path $sourcedir -ArchiveFileName $filename -CompressionLevel $com ... 
+ ~~~~~~~~~~~~~ 
+ CategoryInfo : ObjectNotFound: (Compress-7Zip:String) [], CommandNotFoundException 
+ FullyQualifiedErrorId : CommandNotFoundException 
Process completed with exit code 0 and had 1 error(s) written to the error stream. 

脚本

param([string]$sourcedir, [string]$filename, [string]$compressionLevel, [string]$compressionMethod) 
If (-not (Get-Module -ListAvailable -Name 7Zip4PowerShell)) { 
    Install-Module -Scope CurrentUser -Name 7Zip4PowerShell -Verbose -Force 
} 

If(Test-Path $filename) { 
    Remove-Item $filename 
} 

If (-not $compressionLevel) { 
    $compressionLevel = "Normal" 
} 

If (-not $compressionMethod) { 
    $compressionMethod = "Lzma2" 
} 

Compress-7Zip -Path $sourcedir -ArchiveFileName $filename -CompressionLevel $compressionLevel -CompressionMethod $compressionMethod 

如何获得TFS 2015本地认识安装模块是一个有效的命令?我已经在该机器上安装了MSI for Install-Module。我是否需要将其添加为构建代理的能力?

+1

将'Install-Module'更改为'Import-Module'? – gms0ulman

+0

与上面的@ gms0ulman是啊,没有安装模块,你想要将它导入到会话中。 – Paolis

+0

有一个'install-module'(如果你安装了软件包管理),但是'get-module'显示这个模块已经在本地可用,所以他应该导入它。 –

回答

-1

根据您的错误消息,请在构建代理机器中仔细检查PowerShell版本。从PowerShell的5.0

原因起你,你将能够使用该cmdlet 安装,模块保存-模块。如果您使用较低版本的PS,将会得到类似的错误。

您也可以使用构建服务帐户手动将RDP移植到构建代理,然后运行PS脚本。如果问题与环境或构建定义相关,这将缩小范围。