I am executing a powershell script as user-data, on a windows nano server. I post this error on AWS forum too.
The error is this line:
Install-Package -ProviderName NanoServerPackage -Name Microsoft-NanoServer-IIS-Package -Force
It's not executed, because this package is not found when is running on instance launch, but it's found correctly when I executed in a powershell command.
To check this, I was done the following:
1.- I checked the ps1 created by AWS. It's fine. 2.- I run the same script in a powershell console, in an empty nano server, with the same configuration; and it works fine 3.- I created a ps1, in an empty nano server, with the same configuration, and run it with remote powershell, and it works fine too 4.- I created a ps1 in my machine, and executed with remote "Invoke-Command" to an empty nano server, with same configuration, and works fine too.
The log shows this: log
This is my script edit: script
echo "$(Get-Date): Iniciando script"
echo "$(Get-Date): Estableciendo ExecutionPolicy"
Set-ExecutionPolicy RemoteSigned
echo "$(Get-Date): Instalando PackageProvider NuGet"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
echo "$(Get-Date): Instalando PackageProvider NanoServerPackage"
Install-PackageProvider -Name NanoServerPackage -Scope AllUsers -Force
echo "$(Get-Date): Revisando que NanoServerPackage se haya instalado correctamente"
get-package
echo "$(Get-Date): Instalando Package Microsoft-NanoServer-IIS-Package"
Install-Package -ProviderName NanoServerPackage -Name Microsoft-NanoServer-IIS-Package -Force
echo "$(Get-Date): Importando Modulo IISAdministration"
Import-module IISAdministration -Global -Force
Start-Service WAS
Start-Service W3SVC
echo "$(Get-Date): Instalando Packete AWSPowerShell.NetCore"
Install-Package -Name AWSPowerShell.NetCore -Source https://www.powershellgallery.com/api/v2/ -ProviderName NuGet -ExcludeVersion -Force
echo "$(Get-Date): Importando Modulo AWSPowerShell.NetCore"
Import-Module AWSPowerShell.NetCore -Force
echo "$(Get-Date): Iniciando servicios y copiando datos"
Copy-S3Object -BucketName demo-bucket-nanoserver -Key index.zip -LocalFile C:\inetpub\wwwroot\index.zip
Expand-Archive C:\inetpub\wwwroot\index.zip C:\inetpub\wwwroot\ -Force
Remove-Item C:\inetpub\wwwroot\index.zip
echo "$(Get-Date): Fin del sistema"
What is the error? Any help is appreciated
Thanks