2017-08-07 26 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腳本。如果問題與環境或構建定義相關,這將縮小範圍。