dsc command for iis service availability on iis

984 views Asked by At

I started using DSC configuration on power shell using Windows PowerShell ISE for deployment activities. I have a Windows 2012 web server which has IIS installed on it. On this IIS server, I have 12 services installed and running.

Now I am updating the code bits of one of the services on this IIS. Before I do that; I want to stop the IIS if it is running. IS there any command for this?

I tried the below command, but it checks only abt the IIS:

WindowsFeature IIS 
{ 
  Ensure = "Present"
  Name = "Web-Server" 
}
1

There are 1 answers

0
TravisEz13 On

What you probably should do is stop the default website as your configuration should describe the state you want. You shouldn't want to install IIS just to stop it, but you probably don't want the default site.

Here is a configuration to do that:

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:\inetpub\wwwroot"
            DependsOn       = "[WindowsFeature]IIS"
        }
    }
}