Wie Sie ein PowerShell-Modul im Azure-Funktion

Muss ich das AWS-Modul, das von der PS-Galerie, aber wenn ich versuche, führen Sie die Installation Schritt innerhalb einer Azure-Funktion, es funktioniert nicht. Die -verbose argument flag nicht schriftlich etwas an die Konsole.

Was ist der richtige Weg, um nutzen und zusätzliche PowerShell-Module innerhalb einer Azure-Funktion?

Funktion code

[Console]::WriteLine("PowerShell Timer trigger function executed at:$(get-date)");
if (-not (Get-Module -Name "AWSPowerShell")) {
[Console]::WriteLine("AWSPowerShell not installed");
Install-Module -Name AWSPowerShell -Scope CurrentUser -ErrorAction Continue -Verbose
}
if (-not (Get-Module -Name "AWSPowerShell")){
[Console]::WriteLine("AWSPowerShell install step failed");
}

Funktion log

2016-06-09T11:24:31.108 Function started (Id=e09be687-2e13-4754-942e-eab75c8516e5)
2016-06-09T11:24:32.788 Powershell Timer trigger function executed at:06/09/2016 11:24:32
AWSPowerShell not installed
AWSPowerShell install step failed
2016-06-09T11:24:32.788 Function completed (Success, Id=e09be687-2e13-4754-942e-eab75c8516e5)

Update

Pro @travis' Antwort ich habe den vorgeschlagenen code, einschließlich des nuget-Paket-manager Linie. Dies funktioniert immer noch nicht. Ich fügte hinzu, ein anderes debug-Zeile und festgestellt, dass gab es keine Modul-Anbietern, sogar nach dem Versuch, hinzufügen von nuget!

Überarbeitete code

[Console]::WriteLine("Powershell Timer trigger function executed at:$(get-date)");

Get-PackageProvider -Name nuget -ForceBootstrap

$pkg=Get-PackageProvider -ListAvailable
if ($pkg.Count -lt 1){ [Console]::WriteLine("No providers")}

if (-not (Get-Module -listavailable -Name "AWSPowerShell")) {
    [Console]::WriteLine("AWSPowerShell not installed");
    Install-Module -Name AWSPowerShell -Scope CurrentUser -ErrorAction Continue -Verbose -force
}

if (-not (Get-Module -listavailable -Name "AWSPowerShell")){
    [Console]::WriteLine("AWSPowerShell install step failed");
}

Import-Module AWSPowerShell

Überarbeitete Protokoll

2016-06-09T17:54:03.859 Powershell Timer trigger function executed at:06/09/2016 17:54:02
No providers
AWSPowerShell not installed
AWSPowerShell install step failed
2016-06-09T17:54:03.859 Function completed (Success, Id=80efb9fc-5e91-45f9-ab58-3b71fcd764af)
InformationsquelleAutor Steph Locke | 2016-06-09
Schreibe einen Kommentar