用户数据:在 Windows Server 2016 上安装 IIS

Userdata: Installing IIS on Windows Server 2016

我正在尝试在将安装 IIS 的 AWS 中编写新的服务器设置脚本。我尝试的方法是使用用户数据:

<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>

我的问题似乎是为了真正完成安装,我需要将远程桌面连接到机器中。

鉴于这将在一个自动缩放组中,因此在服务器启动以满足需求时必须将远程桌面连接到服务器是不切实际的。

为什么我必须远程桌面才能完成脚本? 我能否以这样一种方式编写脚本,这意味着我不必在服务器启动时将 RDP 连接到服务器?

感谢上面的Adil B。我通过更改功能的安装方式解决了这个问题。新脚本如下所示:

<powershell> 
Start-Transcript; 

# Install IIS
Import-Module ServerManager; 
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole';

# 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>

我已经通过用户数据脚本成功安装了 IIS,方法是使用 Enable-WindowsOptionalFeature 命令并设置了 -NoRestart 标志:Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole'