### Install IIS and Unlock Configuration Sections (IIS Configuration Path) Source: https://github.com/dsccommunity/webadministrationdsc/wiki/IisFeatureDelegation This example installs the IIS Windows Feature and unlocks specified IIS configuration sections using the IIS Configuration Path format for the 'Path' setting. Ensure the WebAdministrationDsc and PSDesiredStateConfiguration modules are imported. ```powershell configuration Example { param ( [Parameter()] [string[]] $NodeName = 'localhost' ) Import-DscResource -Module WebAdministrationDsc Import-DscResource -Module PSDesiredStateConfiguration Node $NodeName { # Install the IIS role WindowsFeature IIS { Ensure = 'Present' Name = 'Web-Server' } # Allow Write access to some section that normally don't have it. IisFeatureDelegation serverRuntime { Filter = '/system.webserver/serverRuntime' OverrideMode = 'Allow' Path = 'MACHINE/WEBROOT/APPHOST' } IisFeatureDelegation anonymousAuthentication { Filter = '/system.webserver/security/authentication/anonymousAuthentication' OverrideMode = 'Allow' Path = 'MACHINE/WEBROOT/APPHOST' } IisFeatureDelegation sessionState { Filter = '/system.web/sessionState' OverrideMode = 'Allow' Path = 'MACHINE/WEBROOT/APPHOST' } } } ``` -------------------------------- ### Complete IIS Server Configuration Source: https://context7.com/dsccommunity/webadministrationdsc/llms.txt This example demonstrates configuring a full IIS server using multiple DSC resources. It includes installing IIS and features, setting up site and application pool defaults, configuring logging, creating a website, and applying security settings. ```powershell Configuration Complete_IIS_Server { param ( [String[]] $NodeName = 'localhost', [Parameter(Mandatory)] [String] $WebsiteName, [Parameter(Mandatory)] [String] $WebsitePath ) Import-DscResource -Module WebAdministrationDsc Import-DscResource -Module PSDesiredStateConfiguration Node $NodeName { # Install IIS and required features WindowsFeature IIS { Ensure = 'Present'; Name = 'Web-Server' } WindowsFeature AspNet45 { Ensure = 'Present'; Name = 'Web-Asp-Net45' } WindowsFeature IISMgmt { Ensure = 'Present'; Name = 'Web-Mgmt-Tools' } # Configure site defaults WebSiteDefaults SiteDefaults { IsSingleInstance = 'Yes' LogFormat = 'W3C' LogDirectory = 'D:\IISLogs' DefaultApplicationPool = 'DefaultAppPool' DependsOn = '[WindowsFeature]IIS' } # Configure app pool defaults WebAppPoolDefaults PoolDefaults { IsSingleInstance = 'Yes' ManagedRuntimeVersion = 'v4.0' IdentityType = 'ApplicationPoolIdentity' DependsOn = '[WindowsFeature]IIS' } # Configure global logging IisLogging GlobalLogging { LogPath = 'D:\IISLogs' LogFormat = 'W3C' Logflags = @('Date','Time','ClientIP','ServerIP','Method','UriStem', 'HttpStatus','TimeTaken','UserAgent','Host') DependsOn = '[WindowsFeature]IIS' } # Stop default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' PhysicalPath = 'C:\inetpub\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Create application pool WebAppPool MainPool { Name = "${WebsiteName}Pool" Ensure = 'Present' State = 'Started' managedRuntimeVersion = 'v4.0' managedPipelineMode = 'Integrated' identityType = 'ApplicationPoolIdentity' DependsOn = '[WindowsFeature]IIS' } # Create website directory File WebsiteContent { Ensure = 'Present' DestinationPath = $WebsitePath Type = 'Directory' } # Create website WebSite MainSite { Ensure = 'Present' Name = $WebsiteName State = 'Started' PhysicalPath = $WebsitePath ApplicationPool = "${WebsiteName}Pool" BindingInfo = @( DSC_WebBindingInformation { Protocol = 'HTTP'; Port = 80; HostName = $WebsiteName } ) DependsOn = '[WebAppPool]MainPool','[File]WebsiteContent' } # Security: Disable TRACE method WebConfigPropertyCollection DisableTrace { WebsitePath = 'MACHINE/WEBROOT/APPHOST' Filter = 'system.webServer/security/requestFiltering' CollectionName = 'verbs' ItemName = 'add' ItemKeyName = 'verb' ItemKeyValue = 'TRACE' ItemPropertyName = 'allowed' ItemPropertyValue = 'false' Ensure = 'Present' DependsOn = '[WindowsFeature]IIS' } } } ``` -------------------------------- ### Install IIS and Unlock Configuration Sections (IIS Module Path) Source: https://github.com/dsccommunity/webadministrationdsc/wiki/IisFeatureDelegation This example installs the IIS Windows Feature and unlocks specified IIS configuration sections using the IIS Module Path format for the 'Path' setting. Ensure the WebAdministrationDsc and PSDesiredStateConfiguration modules are imported. ```powershell configuration Example { param ( [Parameter()] [string[]] $NodeName = 'localhost' ) Import-DscResource -Module WebAdministrationDsc Import-DscResource -Module PSDesiredStateConfiguration Node $NodeName { # Install the IIS role WindowsFeature IIS { Ensure = 'Present' Name = 'Web-Server' } # Allow Write access to some section that normally don't have it. IisFeatureDelegation serverRuntime { Filter = '/system.webserver/serverRuntime' OverrideMode = 'Allow' Path = 'IIS:\Sites\Default Web Site' } IisFeatureDelegation anonymousAuthentication { Filter = '/system.webserver/security/authentication/anonymousAuthentication' OverrideMode = 'Allow' Path = 'IIS:\Sites\Default Web Site' } IisFeatureDelegation sessionState { Filter = '/system.web/sessionState' OverrideMode = 'Allow' Path = 'IIS:\Sites\Default Web Site' } } } ``` -------------------------------- ### Create Website from Configuration Data Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration dynamically creates websites based on configuration data, allowing for scalable deployment across multiple nodes. It installs IIS and ASP.NET, stops the default site, copies content, and starts the new website. ```powershell Configuration Sample_WebSite_NewWebsiteFromConfigurationData { # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration # Dynamically find the applicable nodes from configuration data Node $AllNodes.where{ $_.Role -eq 'Web' }.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' } # Stop an existing website (set up in Sample_WebSite_Default) WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' ServerAutoStart = $false PhysicalPath = $Node.DefaultWebSitePath DependsOn = '[WindowsFeature]IIS' } # Copy the website content File WebContent { Ensure = 'Present' SourcePath = $Node.SourcePath DestinationPath = $Node.DestinationPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]AspNet45' } # Create a new website WebSite BakeryWebSite { Ensure = 'Present' Name = $Node.WebsiteName State = 'Started' ServerAutoStart = $true PhysicalPath = $Node.DestinationPath DependsOn = '[File]WebContent' } } } $ConfigurationData = @{ # Node specific data AllNodes = @( # All the WebServers have the following identical information @{ NodeName = '*' WebsiteName = 'FourthCoffee' SourcePath = 'C:\BakeryWebsite\' DestinationPath = 'C:\inetpub\FourthCoffee' DefaultWebSitePath = 'C:\inetpub\wwwroot' }, @{ NodeName = 'WebServer1.fourthcoffee.com' Role = 'Web' }, @{ NodeName = 'WebServer2.fourthcoffee.com' Role = 'Web' } ) } ``` -------------------------------- ### Configure Web Application with All Possible Settings Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebApplication This example demonstrates configuring a WebApplication resource with all available settings, including authentication, preload, auto-start, SSL flags, and enabled protocols. Ensure the 'WebAdministrationDsc' module is imported. ```powershell 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') } } } ``` -------------------------------- ### Configure IIS WebApplication Source: https://context7.com/dsccommunity/webadministrationdsc/llms.txt Use this snippet to create an IIS web application, including installing IIS, configuring the application pool, and setting authentication and SSL flags. ```powershell Configuration Sample_WebApplication { param ( [String[]] $NodeName = 'localhost', [Parameter(Mandatory)] [String] $PhysicalPath ) Import-DscResource -Module PSDesiredStateConfiguration Import-DscResource -Module WebAdministrationDsc Node $NodeName { # Install IIS WindowsFeature IIS { Ensure = 'Present' Name = 'Web-Server' } # Ensure the Default Web Site is started WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Started' PhysicalPath = 'C:\inetpub\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Create a dedicated application pool WebAppPool SampleAppPool { Ensure = 'Present' Name = 'SampleAppPool' } # Create directory for application content File WebContent { Ensure = 'Present' SourcePath = 'C:\inetpub\wwwroot' DestinationPath = $PhysicalPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]IIS' } # Create the web application with Windows Authentication WebApplication SampleApplication { Ensure = 'Present' Name = 'SampleApplication' WebAppPool = 'SampleAppPool' Website = 'Default Web Site' PhysicalPath = $PhysicalPath PreloadEnabled = $true ServiceAutoStartEnabled = $true AuthenticationInfo = DSC_WebApplicationAuthenticationInformation { Anonymous = $false Basic = $false Digest = $false Windows = $true } SslFlags = @('Ssl') EnabledProtocols = @('http', 'https') DependsOn = '[WebSite]DefaultSite','[WebAppPool]SampleAppPool' } } } ``` -------------------------------- ### Install PHP on IIS Composite Configuration Source: https://github.com/dsccommunity/webadministrationdsc/blob/main/README.md Use this configuration to automate the installation of PHP on IIS. It handles prerequisites, PHP archive extraction, MySQL extension installation, php.ini configuration, and IIS module registration. Ensure all parameters like `PackageFolder`, `DownloadUri`, `Vc2012RedistDownloadUri`, `DestinationPath`, and `ConfigurationPath` are correctly set. ```powershell configuration xPhp { param ( [Parameter(Mandatory = $true)] [switch] $installMySqlExt, [Parameter(Mandatory = $true)] [string] $PackageFolder, [Parameter(Mandatory = $true)] [string] $DownloadUri, [Parameter(Mandatory = $true)] [string] $Vc2012RedistDownloadUri, [Parameter(Mandatory = $true)] [String] $DestinationPath, [Parameter(Mandatory = $true)] [string] $ConfigurationPath ) # Make sure the IIS Prerequisites for PHP are present IisPreReqs_php Iis { Ensure = "Present" # Removed because this dependency does not work in # Windows Server 2012 R2 and below # This should work in WMF v5 and above # DependsOn = "[File]PackagesFolder" } # Download and install Visual C Redist2012 from chocolatey.org Package vcRedist { Path = $Vc2012RedistDownloadUri ProductId = "{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}" Name = "Microsoft Visual C++ 2012 x64 Minimum Runtime - 11.0.61030" Arguments = "/install /passive /norestart" } $phpZip = Join-Path $PackageFolder "php.zip" # Make sure the PHP archine is in the package folder xRemoteFile phpArchive { uri = $DownloadURI DestinationPath = $phpZip } # Make sure the content of the PHP archine are in the PHP path Archive php { Path = $phpZip Destination = $DestinationPath } if ($installMySqlExt ) { # Make sure the MySql extention for PHP is in the main PHP path File phpMySqlExt { SourcePath = "$($DestinationPath)\ext\php_mysql.dll" DestinationPath = "$($DestinationPath)\php_mysql.dll" Ensure = "Present" DependsOn = @("[Archive]PHP") MatchSource = $true } } # Make sure the php.ini is in the Php folder File PhpIni { SourcePath = $ConfigurationPath DestinationPath = "$($DestinationPath)\php.ini" DependsOn = @("[Archive]PHP") MatchSource = $true } # Make sure the php cgi module is registered with IIS IisModule phpHandler { Name = "phpFastCgi" Path = "$($DestinationPath)\php-cgi.exe" RequestPath = "*.php" Verb = "*" Ensure = "Present" DependsOn = @("[Package]vcRedist","[File]PhpIni") # Removed because this dependency does not work in # Windows Server 2012 R2 and below # This should work in WMF v5 and above # "[IisPreReqs_php]Iis" } # Make sure the php binary folder is in the path Environment PathPhp { Name = "Path" Value = ";$($DestinationPath)" Ensure = "Present" Path = $true DependsOn = "[Archive]PHP" } } xPhp -PackageFolder "C:\packages" \ -DownloadUri -DownloadUri "http://windows.php.net/downloads/releases/php-5.5.13-Win32-VC11-x64.zip" \ -Vc2012RedistDownloadUri "http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe" \ -DestinationPath "C:\php" \ -ConfigurationPath "C:\MyPhp.ini" \ -installMySqlExt $false ``` -------------------------------- ### Create New Web Application with Windows Authentication Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebApplication Use this snippet to create a new web application on the Default Web Site with Windows Authentication enabled. Ensure IIS and ASP.NET 4.5 roles are installed and the Default Web Site is started. ```powershell 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' } } } ``` -------------------------------- ### Create and Configure Application Pool with WebAppPool DSC Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebAppPool This example demonstrates creating and configuring an application pool using the WebAppPool DSC resource. Ensure the WebAdministrationDsc module is imported. ```powershell Configuration Sample_WebAppPool { param ( [String[]]$NodeName = 'localhost' ) Import-DscResource -ModuleName WebAdministrationDsc Node $NodeName { WebAppPool SampleAppPool { Name = 'SampleAppPool' Ensure = 'Present' State = 'Started' autoStart = $true CLRConfigFile = '' enable32BitAppOnWin64 = $false enableConfigurationOverride = $true managedPipelineMode = 'Integrated' managedRuntimeLoader = 'webengine4.dll' managedRuntimeVersion = 'v4.0' passAnonymousToken = $true startMode = 'OnDemand' queueLength = 1000 cpuAction = 'NoAction' cpuLimit = 90000 cpuResetInterval = (New-TimeSpan -Minutes 5).ToString() cpuSmpAffinitized = $false cpuSmpProcessorAffinityMask = 4294967295 cpuSmpProcessorAffinityMask2 = 4294967295 identityType = 'ApplicationPoolIdentity' idleTimeout = (New-TimeSpan -Minutes 20).ToString() idleTimeoutAction = 'Terminate' loadUserProfile = $true logEventOnProcessModel = 'IdleTimeout' logonType = 'LogonBatch' manualGroupMembership = $false maxProcesses = 1 pingingEnabled = $true pingInterval = (New-TimeSpan -Seconds 30).ToString() pingResponseTime = (New-TimeSpan -Seconds 90).ToString() setProfileEnvironment = $false shutdownTimeLimit = (New-TimeSpan -Seconds 90).ToString() startupTimeLimit = (New-TimeSpan -Seconds 90).ToString() orphanActionExe = '' orphanActionParams = '' orphanWorkerProcess = $false loadBalancerCapabilities = 'HttpLevel' rapidFailProtection = $true rapidFailProtectionInterval = (New-TimeSpan -Minutes 5).ToString() rapidFailProtectionMaxCrashes = 5 autoShutdownExe = '' autoShutdownParams = '' disallowOverlappingRotation = $false disallowRotationOnConfigChange = $false logEventOnRecycle = 'Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory' restartMemoryLimit = 0 restartPrivateMemoryLimit = 0 restartRequestsLimit = 0 restartTimeLimit = (New-TimeSpan -Minutes 1440).ToString() restartSchedule = @('00:00:00', '08:00:00', '16:00:00') } } } ``` -------------------------------- ### IisModule Resource Configuration Source: https://github.com/dsccommunity/webadministrationdsc/wiki/IisModule Configuration example for the IisModule DSC resource. ```APIDOC ## IisModule Resource ### Description The `IisModule` DSC resource is used to manage IIS modules. ### Method Not Applicable (DSC Resource) ### Endpoint Not Applicable (DSC Resource) ### Parameters #### Path Parameters - **Key** (String) - Required - The path to the module, usually a dll, to be added to IIS. #### Query Parameters None #### Request Body None (DSC Resource Configuration) ### Request Example ```powershell Configuration IisModuleExample { Import-DscResource -ModuleName "WebAdministrationDsc" Node "localhost" { IisModule ExampleModule { Key = "C:\Windows\System32\inetsrv\MyModule.dll" Name = "MyCustomModule" RequestPath = "*.dll" Verb = @("GET", "POST") Ensure = "Present" ModuleType = "FastCgiModule" SiteName = "Default Web Site" EndPointSetup = $true } } } ``` ### Response #### Success Response (200) Not Applicable (DSC Resource) #### Response Example None (DSC Resource) ``` -------------------------------- ### Create IIS Website with Custom Logging Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration installs IIS, ASP.NET 4.5, stops the default website, copies content, and creates a new website with custom W3C log fields. Ensure the source and destination paths are valid. ```powershell configuration Sample_WebSite_WithCustomLogFields_EnsureAbsent { param ( # Target nodes to apply the configuration [String[]] $NodeName = 'localhost', # Name of the website to create [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $WebSiteName, # Optional Site Id for the website [Parameter()] [UInt32] $SiteId, # Source Path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $SourcePath, # Destination path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $DestinationPath ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration 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' } # Stop the default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' ServerAutoStart = $false PhysicalPath = 'C:\inetpub\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Copy the website content File WebContent { Ensure = 'Present' SourcePath = $SourcePath DestinationPath = $DestinationPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]AspNet45' } # Create the new Website WebSite NewWebsite { Ensure = 'Present' Name = $WebSiteName SiteId = $SiteId State = 'Started' ServerAutoStart = $true PhysicalPath = $DestinationPath DependsOn = '[File]WebContent' LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent') LogFormat = 'W3C' LogCustomFields = @( DSC_LogCustomFieldInformation { LogFieldName = 'ClientEncoding' SourceName = 'Accept-Encoding' SourceType = 'RequestHeader' Ensure = 'Absent' } ) } } } ``` -------------------------------- ### Configure Website with SSL using DSC Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration installs IIS and ASP.NET, copies website content, and creates a new website with HTTPS binding using a specified certificate. Ensure the CertificateThumbprint is valid and accessible. ```powershell configuration Sample_WebSite_WithSSLFlags { param ( # Target nodes to apply the configuration [String[]] $NodeName = 'localhost', # Name of the website to create [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $WebSiteName, # Source Path for Website content [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $SourcePath, # Destination path for Website content [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $DestinationPath ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration 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" } # Stop the default website WebSite DefaultSite { Ensure = "Present" Name = "Default Web Site" State = "Stopped" ServerAutoStart = $false PhysicalPath = "C:\\inetpub\\wwwroot" DependsOn = "[WindowsFeature]IIS" } # Copy the website content File WebContent { Ensure = "Present" SourcePath = $SourcePath DestinationPath = $DestinationPath Recurse = $true Type = "Directory" DependsOn = "[WindowsFeature]AspNet45" } # Create the new Website # Have it set to the CertificateThumbprint # and set that the Server Name Indication is required WebSite NewWebsite { Ensure = "Present" Name = $WebSiteName State = "Started" PhysicalPath = $DestinationPath DependsOn = "[File]WebContent" BindingInfo = DSC_WebBindingInformation { Protocol = 'https' Port = '443' CertificateStoreName = 'My' CertificateThumbprint = 'BB84DE3EC423DDDE90C08AB3C5A828692089493C' HostName = $WebSiteName IPAddress = '*' SSLFlags = '1' } } } } ``` -------------------------------- ### Configure a WebApplicationHandler Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebApplicationHandler Use this snippet to configure a new web application handler. Ensure the WebAdministrationDsc module is imported. This example sets up a handler for ISAPI modules with specific script processor and location settings. ```powershell Configuration Example { Import-DscResource -ModuleName WebAdministrationDsc Node 'localhost' { WebApplicationHandler WebHandlerTest { Path = 'MACHINE/WEBROOT/APPHOST' Name = 'ATest-WebHandler' PhysicalHandlerPath = '*' Verb = '*' Modules = 'IsapiModule' RequireAccess = 'None' ScriptProcessor = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" ResourceType = 'Unspecified' AllowPathInfo = $false ResponseBufferLimit = 0 Type = $null PreCondition = $null Location = 'Default Web Site/TestDir' } } } ``` -------------------------------- ### Install WebAdministrationDsc Module Source: https://github.com/dsccommunity/webadministrationdsc/wiki/Home Install the WebAdministrationDsc module from the PowerShell Gallery using PowerShellGet. Ensure you have PowerShell 5.0 or higher. ```powershell Install-Module -Name WebAdministrationDsc -Repository PSGallery ``` -------------------------------- ### Install WebAdministrationDsc Module from PowerShell Gallery Source: https://github.com/dsccommunity/webadministrationdsc/blob/main/README.md Install the WebAdministrationDsc module from the PowerShell Gallery using PowerShellGet. This command is compatible with PowerShell 5.0 and later. ```powershell Find-Module -Name WebAdministrationDsc | Install-Module ``` -------------------------------- ### Create New Website with Certificate Thumbprint Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration creates a new website, installs IIS and ASP.NET, copies website content, and configures HTTPS bindings using specified certificate thumbprints. Ensure the necessary modules are imported and parameters are provided. ```powershell Configuration Sample_WebSite_NewWebsite_UsingCertificateThumbprint { param ( # Target nodes to apply the configuration [string[]] $NodeName = 'localhost', # Name of the website to create [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $WebSiteName, # Source Path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $SourcePath, # Destination path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $DestinationPath ) # Import the module that defines custom resources 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' } # Stop the default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' PhysicalPath = 'C:\\inetpub\\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Copy the website content File WebContent { Ensure = 'Present' SourcePath = $SourcePath DestinationPath = $DestinationPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]AspNet45' } # Create the new Website with HTTPS WebSite NewWebsite { Ensure = 'Present' Name = $WebSiteName State = 'Started' PhysicalPath = $DestinationPath BindingInfo = @( DSC_WebBindingInformation { Protocol = 'HTTPS' Port = 8443 CertificateThumbprint = '71AD93562316F21F74606F1096B85D66289ED60F' CertificateStoreName = 'WebHosting' } DSC_WebBindingInformation { Protocol = 'HTTPS' Port = 8444 CertificateThumbprint = 'DEDDD963B28095837F558FE14DA1FDEFB7FA9DA7' CertificateStoreName = 'My' } ) DependsOn = '[File]WebContent' } } } ``` -------------------------------- ### Verify WebAdministrationDsc Resource Installation Source: https://github.com/dsccommunity/webadministrationdsc/wiki/Home Confirm that the WebAdministrationDsc DSC resources are available after installation by running Get-DscResource. This command lists all DSC resources from the specified module. ```powershell Get-DscResource -Module WebAdministrationDsc ``` -------------------------------- ### Configure IisLogging with Default Custom Fields Source: https://github.com/dsccommunity/webadministrationdsc/wiki/IisLogging This example shows how to configure IIS logging with custom fields using default settings. The 'Ensure' parameter defaults to 'Present' if not specified. Ensure the WebAdministrationDsc module is imported. ```powershell configuration Sample_IisLogging_LogCustomFields_EnsurePresentDefault { param ( # Target nodes to apply the configuration [String[]] $NodeName = 'localhost' ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc Node $NodeName { IisLogging Logging { LogPath = 'C:\IISLogFiles' Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent') LogFormat = 'W3C' LogTargetW3C = 'File,ETW' LogCustomFields = @( DSC_LogCustomField { LogFieldName = 'ClientEncoding' SourceName = 'Accept-Encoding' SourceType = 'RequestHeader' } ) } } } ``` -------------------------------- ### Configure Website with Custom Log Fields Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration ensures IIS and ASP.NET 4.5 are installed, stops the default website, copies content, and creates a new website with custom W3C log fields. It requires parameters for website name, source, and destination paths. ```powershell configuration Sample_WebSite_WithCustomLogFields_EnsurePresentDefault { param ( # Target nodes to apply the configuration [String[]] $NodeName = 'localhost', # Name of the website to create [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $WebSiteName, # Optional Site Id for the website [Parameter()] [UInt32] $SiteId, # Source Path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $SourcePath, # Destination path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $DestinationPath ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration 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' } # Stop the default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' ServerAutoStart = $false PhysicalPath = 'C:\\inetpub\\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Copy the website content File WebContent { Ensure = 'Present' SourcePath = $SourcePath DestinationPath = $DestinationPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]AspNet45' } # Create the new Website WebSite NewWebsite { Ensure = 'Present' Name = $WebSiteName SiteId = $SiteId State = 'Started' ServerAutoStart = $true PhysicalPath = $DestinationPath DependsOn = '[File]WebContent' LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent') LogFormat = 'W3C' LogCustomFields = @( DSC_LogCustomFieldInformation { LogFieldName = 'ClientEncoding' SourceName = 'Accept-Encoding' SourceType = 'RequestHeader' } ) } } } ``` -------------------------------- ### Configure Application Pool Defaults with WebAppPoolDefaults Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebAppPoolDefaults This example demonstrates how to use the WebAppPoolDefaults DSC resource to configure application pool default settings, specifically the managed runtime version and identity type. Ensure the WebAdministrationDsc and PSDesiredStateConfiguration modules are imported. ```powershell Configuration Sample_WebAppPoolDefaults { param ( # Target nodes to apply the configuration [string[]]$NodeName = 'localhost' ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration Node $NodeName { # Configures the application pool defaults. WebAppPoolDefaults PoolDefaults { IsSingleInstance = 'Yes' ManagedRuntimeVersion = 'v4.0' IdentityType = 'ApplicationPoolIdentity' } } } ``` -------------------------------- ### Create New Web Virtual Directory with DSC Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebVirtualDirectory Use this configuration to create a new virtual directory on the Default Web Site. Ensure the IIS role is installed and the default website is running. The configuration also handles copying virtual directory content. ```powershell configuration Sample_WebVirtualDirectory_NewVirtualDirectory { param ( # Target nodes to apply the configuration [System.String[]] $NodeName = 'localhost', # Name of virtual directory to create [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String] $VirtualDirectoryName, # Physical path of the virtual directory [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String] $PhysicalPath ) # 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' } # Start the default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Started' PhysicalPath = 'C:\\inetpub\\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Copy the virtual directory content File VirtualDirectoryContent { Ensure = 'Present' DestinationPath = $PhysicalPath Type = 'Directory' DependsOn = '[WindowsFeature]IIS' } # Create the new virtual directory WebVirtualDirectory NewVirtualDirectory { Ensure = 'Present' Website = "Default Web Site" WebApplication = '' Name = $VirtualDirectoryName PhysicalPath = $PhysicalPath DependsOn = '[File]VirtualDirectoryContent' } } } ``` -------------------------------- ### Configure Website with Custom Log Fields Source: https://github.com/dsccommunity/webadministrationdsc/wiki/WebSite This configuration ensures IIS and ASP.NET 4.5 are installed, copies website content, and creates a new website with custom W3C log fields. It requires parameters for website name, source and destination paths for content, and optionally a site ID. The custom log fields capture the 'Accept-Encoding' request header. ```powershell configuration Sample_WebSite_WithCustomLogFields_EnsurePresentExplicitly { param ( # Target nodes to apply the configuration [String[]] $NodeName = 'localhost', # Name of the website to create [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $WebSiteName, # Optional Site Id for the website [Parameter()] [UInt32] $SiteId, # Source Path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $SourcePath, # Destination path for Website content [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $DestinationPath ) # Import the module that defines custom resources Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration 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' } # Stop the default website WebSite DefaultSite { Ensure = 'Present' Name = 'Default Web Site' State = 'Stopped' ServerAutoStart = $false PhysicalPath = 'C:\inetpub\wwwroot' DependsOn = '[WindowsFeature]IIS' } # Copy the website content File WebContent { Ensure = 'Present' SourcePath = $SourcePath DestinationPath = $DestinationPath Recurse = $true Type = 'Directory' DependsOn = '[WindowsFeature]AspNet45' } # Create the new Website WebSite NewWebsite { Ensure = 'Present' Name = $WebSiteName SiteId = $SiteId State = 'Started' ServerAutoStart = $true PhysicalPath = $DestinationPath DependsOn = '[File]WebContent' LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent') LogFormat = 'W3C' LogCustomFields = @( DSC_LogCustomFieldInformation { LogFieldName = 'ClientEncoding' SourceName = 'Accept-Encoding' SourceType = 'RequestHeader' Ensure = 'Present' } ) } } } ```