amazon-web-serviceswindows-serverwindows-server-2016user-data

Userdata: Installing IIS on Windows Server 2016


I'm trying to script a new server setup in AWS that will have IIS installed. The way I'm trying to to this is with User-Data:

<powershell> 
Start-Transcript; 

# Set Default Password for Testing
net user "Administrator" "Password.1"; 

# Install IIS
Import-Module ServerManager; 
Install-WindowsFeature web-server, web-webserver -IncludeAllSubFeature; 
Install-WindowsFeature web-mgmt-tools; 

# Configure Bindings to :443
New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https -SslFlags 0;
$newCert = New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My; 
$SslBinding = Get-WebBinding -Name "Default Web Site" -Protocol "https";
$SslBinding.AddSslCertificate($newCert.GetCertHashString(), "my"); 
Get-WebBinding -Port 80 -Name "Default Web Site" | Remove-WebBinding;

# Install CodeDeploy Agent 
Import-Module AWSPowerShell; 
New-Item -Path "C:\Temp" -ItemType "directory" -Force; 
Read-S3Object -BucketName aws-codedeploy-us-east-1 -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi; 
c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt;
</powershell>

My problem seems to be that in order for the install to actually complete, I need to have remote-desktop'd into the machine.

Given this is going to be in an autoscale group it's not practical to have to remote desktop into the servers as they're being spun up to meet demand.

Why do I have to remote desktop in for the script to complete? Can I write the script in such a way that will mean I don't have to RDP into the servers as they're being spun up?


Solution

  • I've had success installing IIS via a Userdata script by using the

    Enable-WindowsOptionalFeature -NoRestart
    Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole'