未找到TFS Powershell安装模块

时间:2017-08-07 19:57:21

标签: powershell tfs

我已经使用7Zip4Powershell编写了下面的PS脚本7zip文件夹,但是在构建过程中它失败并出现以下错误:

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 个答案:

答案 0 :(得分:-1)

根据您的错误消息,请在构建代理计算机中仔细检查您的powershell版本。

从Powershell 5.0开始,您将能够使用cmdlet Install-Module Save-Module 。如果您使用的是较低版本的PS,则会出现类似的错误。

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