我开始使用Windows PowerShell ISE在Power shell上使用DSC配置进行部署活动。我有一个安装了IIS的Windows 2012 Web服务器。在此 IIS 服务器上,我安装并运行了 12 个服务。
现在,我正在更新此 IIS 上其中一个服务的代码位。在我这样做之前;如果 IIS 正在运行,我想停止它。有什么命令吗?
我尝试了以下命令,但它只检查 IIS:
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
您可能应该做的是停止默认网站,因为您的配置应该描述您想要的状态。 您不应该只是为了阻止它而安装 IIS,但您可能不想要默认站点。
下面是执行此操作的配置:
Configuration Sample_xWebsite_StopDefault
{
param
(
# Target nodes to apply the configuration
[string[]]$NodeName = 'localhost'
)
# Import the module that defines custom resources
Import-DscResource -Module xWebAdministration
Node $NodeName
{
# Install the IIS role
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
# Stop the default website
xWebsite DefaultSite
{
Ensure = "Present"
Name = "Default Web Site"
State = "Stopped"
PhysicalPath = "C:inetpubwwwroot"
DependsOn = "[WindowsFeature]IIS"
}
}
}