Skip to content

WebApplication

dscbot edited this page Jan 3, 2023 · 2 revisions

WebApplication

Parameters

Parameter Attribute DataType Description Allowed Values
Website Key String Name of website with which web application is associated
Name Key String Name of web application
WebAppPool Required String Web application pool for the web application
PhysicalPath Required String Physical path for the web application directory
Ensure Write String Whether web application should be present or absent Present, Absent
SslFlags Write StringArray[] SSLFlags for the application ``, Ssl, `SslNegotiateCert`, `SslRequireCert`, `Ssl128`
AuthenticationInfo Write DSC_WebApplicationAuthenticationInformation Hashtable containing authentication information (Anonymous, Basic, Digest, Windows)
PreloadEnabled Write Boolean Allows a Application to automatically start without a request
ServiceAutoStartEnabled Write Boolean Enables Autostart on an Application.
ServiceAutoStartProvider Write String Adds a AutostartProvider
ApplicationType Write String Adds a AutostartProvider ApplicationType
EnabledProtocols Write StringArray[] Adds EnabledProtocols on an Application http, https, net.tcp, net.msmq, net.pipe

DSC_WebApplicationAuthenticationInformation

Parameters

Parameter Attribute DataType Description Allowed Values
Anonymous Write Boolean Enable anonymous authentication
Basic Write Boolean Enable basic authentication
Digest Write Boolean Enable digest authentication
Windows Write Boolean Enable Windows authentication

Description

The WebApplication DSC resource is used to...

Requirements

  • Target machine must be running Windows Server 2012 R2 or later.

Known issues

All issues are not listed here, see here for all open issues.

Examples

Example 1

Create a new web application on the Default Web Site This example shows how to use the WebApplication DSC resource to create a new web application.

Configuration Sample_WebApplication_NewWebApplication
{
    param
    (
        # Target nodes to apply the configuration
        [String[]] $NodeName = 'localhost',

        # Destination path for Website content
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String] $DestinationPath
    )

    # Import the module that defines custom resources
    Import-DscResource -Module PSDesiredStateConfiguration
    Import-DscResource -Module WebAdministrationDsc

    Node $NodeName
    {
        # Install the IIS role
        WindowsFeature IIS
        {
            Ensure                  = 'Present'
            Name                    = 'Web-Server'
        }

        # Install the ASP .NET 4.5 role
        WindowsFeature AspNet45
        {
            Ensure                  = 'Present'
            Name                    = 'Web-Asp-Net45'
        }

        # Start the Default Web Site
        WebSite DefaultSite
        {
            Ensure                  = 'Present'
            Name                    = 'Default Web Site'
            State                   = 'Started'
            PhysicalPath            = 'C:\inetpub\wwwroot'
            DependsOn               = '[WindowsFeature]IIS'
        }

        # Create a new application pool for the application
        WebAppPool SampleAppPool
        {
            Ensure                  = 'Present'
            Name                    = 'SampleAppPool'
        }

        # Clone the wwwroot folder to the destination
        File WebContent
        {
            Ensure                  = 'Present'
            SourcePath              = 'C:\inetpub\wwwroot'
            DestinationPath         = $DestinationPath
            Recurse                 = $true
            Type                    = 'Directory'
            DependsOn               = '[WindowsFeature]IIS'
        }

        # Create a new web application with Windows Authentication
        WebApplication SampleApplication
        {
            Ensure                  = 'Present'
            Name                    = 'SampleApplication'
            WebAppPool              = 'SampleAppPool'
            Website                 = 'Default Web Site'
            PreloadEnabled          = $true
            ServiceAutoStartEnabled = $true
            AuthenticationInfo      = DSC_WebApplicationAuthenticationInformation
            {
                Anonymous   = $false
                Basic       = $false
                Digest      = $false
                Windows     = $true
            }
            SslFlags                = ''
            PhysicalPath            = $DestinationPath
            DependsOn               = '[WebSite]DefaultSite','[WebAppPool]SampleAppPool'
        }
    }
}

Example 2

This shows an example for all possible settings for the WebApplication resource

configuration Sample_WebApplication
{

    param
    (
        # Target nodes to apply the configuration
        [String[]] $NodeName = 'localhost',

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [String] $PhysicalPath
    )

    Import-DscResource -ModuleName WebAdministrationDsc

    node $NodeName
    {
        WebApplication WebApplication
        {
            Website                  = 'Website'
            Ensure                   = 'Present'
            Name                     = 'WebApplication'
            PhysicalPath             = $PhysicalPath
            WebAppPool               = 'DefaultAppPool'
            ApplicationType          = 'ApplicationType'
            AuthenticationInfo       = `
                DSC_WebApplicationAuthenticationInformation
            {
                Anonymous = $true
                Basic     = $false
                Digest    = $false
                Windows   = $false
            }
            PreloadEnabled           = $true
            ServiceAutoStartEnabled  = $true
            ServiceAutoStartProvider = 'ServiceAutoStartProvider'
            SslFlags                 = @('Ssl')
            EnabledProtocols         = @('http', 'net.tcp')
        }
    }
}