2017-08-07 5 views
1

Ich habe das PS-Skript unten geschrieben 7Zip4Powershell einen Ordner 7zip jedoch, wenn während des Build es mit dem folgenden Fehler fehl:TFS Powershell Install-Modul nicht gefunden

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. 

Script

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 

Wie bekomme ich TFS 2015 On-Premise zur Erkennung des Install-Moduls als gültigen Befehl? Ich habe das MSI für Install-Module bereits auf diesem Rechner installiert. Muss ich es vielleicht als Build-Agent-Fähigkeit hinzufügen?

+1

"Install-Module" in 'Import-Module' ändern? – gms0ulman

+0

Ja mit @ gms0ulman oben, es gibt kein Install-Modul, das Sie in die Sitzung importieren möchten. – Paolis

+0

Es gibt ein 'install-module' (wenn Sie die Paketverwaltung installiert haben), aber' get-module' zeigt hier an, dass das Modul bereits lokal verfügbar ist, also sollte es nur importiert werden. –

Antwort

-1

Überprüfen Sie Ihre Powershell-Version entsprechend Ihrer Fehlermeldung im Build Agent-Computer.

Ursache von Powershell 5.0 ab Sie, werden Sie das Cmdlet Install-Modul, nutzen können Save-Modul. Wenn Sie die niedrigere Version von PS verwenden, wird ein ähnlicher Fehler angezeigt.

Sie können RDP auch manuell mit dem Build-Dienstkonto an den Erstellungsagenten senden und das PS-Skript ausführen. Dies wird eingeschränkt, wenn das Problem mit der Umgebung oder Ihrer Builddefinition zusammenhängt.

Verwandte Themen