├── CODE_OF_CONDUCT.md
├── source
├── WebAdministrationDsc.psm1
├── DSCResources
│ ├── DSC_WebSiteDefaults
│ │ ├── en-US
│ │ │ └── DSC_WebSiteDefaults.strings.psd1
│ │ ├── README.md
│ │ └── DSC_WebSiteDefaults.schema.mof
│ ├── DSC_WebAppPoolDefaults
│ │ ├── en-US
│ │ │ └── DSC_WebAppPoolDefaults.strings.psd1
│ │ ├── README.md
│ │ └── DSC_WebAppPoolDefaults.schema.mof
│ ├── DSC_WebSite
│ │ └── README.md
│ ├── DSC_IisModule
│ │ ├── README.md
│ │ ├── DSC_IisModule.schema.mof
│ │ └── en-US
│ │ │ └── DSC_IisModule.strings.psd1
│ ├── DSC_WebAppPool
│ │ ├── README.md
│ │ └── en-US
│ │ │ └── DSC_WebAppPool.strings.psd1
│ ├── DSC_SslSettings
│ │ ├── README.md
│ │ ├── en-US
│ │ │ └── DSC_SslSettings.strings.psd1
│ │ ├── DSC_SslSettings.schema.mof
│ │ └── DSC_SslSettings.psm1
│ ├── DSC_WebApplication
│ │ ├── README.md
│ │ ├── DSC_WebApplication.schema.mof
│ │ └── en-US
│ │ │ └── DSC_WebApplication.strings.psd1
│ ├── DSC_IisMimeTypeMapping
│ │ ├── README.md
│ │ ├── en-US
│ │ │ └── DSC_IisMimeTypeMapping.strings.psd1
│ │ └── DSC_IisMimeTypeMapping.schema.mof
│ ├── DSC_WebVirtualDirectory
│ │ ├── README.md
│ │ ├── DSC_WebVirtualDirectory.schema.mof
│ │ └── en-US
│ │ │ └── DSC_WebVirtualDirectory.strings.psd1
│ ├── DSC_IisFeatureDelegation
│ │ ├── en-US
│ │ │ └── DSC_IisFeatureDelegation.strings.psd1
│ │ ├── README.md
│ │ ├── DSC_IisFeatureDelegation.schema.mof
│ │ └── DSC_IisFeatureDelegation.psm1
│ ├── DSC_WebApplicationHandler
│ │ ├── README.md
│ │ ├── en-US
│ │ │ └── DSC_WebApplicationHandler.strings.psd1
│ │ └── DSC_WebApplicationHandler.schema.mof
│ ├── DSC_WebConfigProperty
│ │ ├── README.md
│ │ ├── en-US
│ │ │ └── DSC_WebConfigProperty.strings.psd1
│ │ └── DSC_WebConfigProperty.schema.mof
│ ├── DSC_IisLogging
│ │ ├── README.md
│ │ ├── en-US
│ │ │ └── DSC_IisLogging.strings.psd1
│ │ └── DSC_IisLogging.schema.mof
│ └── DSC_WebConfigPropertyCollection
│ │ ├── README.md
│ │ ├── en-US
│ │ └── DSC_WebConfigPropertyCollection.strings.psd1
│ │ └── DSC_WebConfigPropertyCollection.schema.mof
├── Examples
│ └── Resources
│ │ ├── SslSettings
│ │ └── Sample_SslSettings_RequireCert.ps1
│ │ ├── IisLogging
│ │ ├── Sample_IisLogging_LogFlags.ps1
│ │ ├── Sample_IisLogging_Rollover.ps1
│ │ ├── Sample_IisLogging_Truncate.ps1
│ │ ├── Sample_IisLogging_LogCustomFields_EnsurePresentDefault.ps1
│ │ ├── Sample_IisLogging_LogCustomFields_EnsureAbsent.ps1
│ │ └── Sample_IisLogging_LogCustomFields_EnsurePresentExplicitly.ps1
│ │ ├── WebApplicationHandler
│ │ └── Sample_WebApplicationHandler.ps1
│ │ ├── WebSite
│ │ ├── Sample_WebSite_RemoveDefault.ps1
│ │ ├── Sample_WebSite_StopDefault.ps1
│ │ ├── Sample_WebSite_NewWebsite.ps1
│ │ ├── Sample_WebSite_NewWebsiteFromConfigurationData.ps1
│ │ ├── Sample_WebSite_WithSSLFlags.ps1
│ │ ├── Sample_WebSite_NewWebsite_UsingCertificateSubject.ps1
│ │ ├── Sample_WebSite_WithCustomLogFields_EnsurePresentDefault.ps1
│ │ ├── Sample_WebSite_WithCustomLogFields_EnsureAbsent.ps1
│ │ ├── Sample_WebSite_WithCustomLogFields_EnsurePresentExplicitly.ps1
│ │ └── Sample_WebSite_NewWebsite_UsingCertificateThumbprint.ps1
│ │ ├── WebSiteDefaults
│ │ └── Sample_WebSiteDefaults.ps1
│ │ ├── WebAppPoolDefaults
│ │ └── Sample_WebAppPoolDefaults.ps1
│ │ ├── WebConfigProperty
│ │ ├── Sample_WebConfigProperty_Remove.ps1
│ │ └── Sample_WebConfigProperty_Add.ps1
│ │ ├── WebConfigPropertyCollection
│ │ ├── Sample_WebConfigPropertyCollection_Add.ps1
│ │ ├── Sample_WebConfigPropertyCollection_Remove.ps1
│ │ ├── Sample_WebConfigPropertyCollection_SingleItemRemove.ps1
│ │ └── Sample_WebConfigPropertyCollection_SingleItemAdd.ps1
│ │ ├── WebApplication
│ │ ├── Sample_WebApplication.ps1
│ │ └── Sample_WebApplication_NewWebApplication.ps1
│ │ ├── IisFeatureDelegation
│ │ ├── Sample_IisFeatureDelegation_IisModulePathFormat.ps1
│ │ └── Sample_IisFeatureDelegation_IisConfigurationPathFormat.ps1
│ │ ├── WebVirtualDirectory
│ │ ├── Sample_WebVirtualDirectory_NewVirtualDirectory.ps1
│ │ └── Sample_WebVirtualDirectory_NewVirtualDirectory_WithUncPath.ps1
│ │ ├── IisMimeTypeMapping
│ │ └── Sample_IisMimeTypeMapping_RemoveVideo.ps1
│ │ ├── WebAppPool
│ │ └── Sample_WebAppPool.ps1
│ │ └── Sample_EndToEndWebAdministration.ps1
├── Modules
│ └── WebAdministrationDsc.Common
│ │ ├── en-US
│ │ └── WebAdministrationDsc.Common.strings.psd1
│ │ └── WebAdministrationDsc.Common.psd1
├── en-US
│ └── about_xWebAdministration.help.txt
├── WikiSource
│ └── Home.md
└── WebAdministrationDsc.psd1
├── .markdownlint.json
├── .gitignore
├── .github
├── ISSUE_TEMPLATE
│ ├── General.md
│ ├── config.yml
│ ├── Resource_proposal.yml
│ └── Problem_with_resource.yml
├── stale.yml
└── PULL_REQUEST_TEMPLATE.md
├── CONTRIBUTING.md
├── .gitattributes
├── Resolve-Dependency.psd1
├── tests
├── Integration
│ ├── DSC_IISFeatureDelegation.config.ps1
│ ├── DSC_WebSiteDefaults.config.ps1
│ ├── DSC_SslSettings.config.ps1
│ ├── DSC_SslSettings.config.psd1
│ ├── DSC_WebVirtualDirectory.config.psd1
│ ├── DSC_WebApplication.config.psd1
│ ├── DSC_WebApplication.config.ps1
│ ├── DSC_WebAppPoolDefaults.config.ps1
│ ├── DSC_WebConfigProperty.config.ps1
│ ├── DSC_WebSite.config.psd1
│ ├── DSC_IISMimeTypeMapping.config.ps1
│ ├── DSC_WebVirtualDirectory.config.ps1
│ ├── DSC_WebSiteDefaults.Integration.Tests.ps1
│ ├── DSC_IISLogging.config.ps1
│ ├── DSC_WebAppPool.Integration.Tests.ps1
│ ├── DSC_WebConfigPropertyCollection.config.ps1
│ ├── DSC_SslSettings.Integration.Tests.ps1
│ ├── DSC_WebAppPoolDefaults.Integration.Tests.ps1
│ ├── DSC_IISFeatureDelegation.Integration.Tests.ps1
│ └── DSC_WebApplicationHandler.config.ps1
├── WebAdministrationDsc.TestHarness.psm1
└── TestHelper
│ └── CommonTestHelper.psm1
├── GitVersion.yml
├── codecov.yml
├── LICENSE
├── RequiredModules.psd1
├── SECURITY.md
└── .vscode
├── settings.json
├── analyzersettings.psd1
└── tasks.json
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | This project has adopted the [DSC Community Code of Conduct](https://dsccommunity.org/code_of_conduct).
4 |
--------------------------------------------------------------------------------
/source/WebAdministrationDsc.psm1:
--------------------------------------------------------------------------------
1 | <#
2 | This file is intentionally left empty. It is must be left here for the module
3 | manifest to refe to. It is recreated during the build process.
4 | #>
5 |
--------------------------------------------------------------------------------
/.markdownlint.json:
--------------------------------------------------------------------------------
1 | {
2 | "default": true,
3 | "MD029": {
4 | "style": "one"
5 | },
6 | "MD013": true,
7 | "MD024": false,
8 | "MD034": false,
9 | "no-hard-tabs": true
10 | }
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | output/
2 |
3 | **.bak
4 | *.local.*
5 | !**/README.md
6 | .kitchen/
7 |
8 | *.nupkg
9 | *.suo
10 | *.user
11 | *.coverage
12 | .vs
13 | .vscode
14 | .psproj
15 | .sln
16 | markdownissues.txt
17 | node_modules
18 | package-lock.json
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/General.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: General question or documentation update
3 | about: If you have a general question or documentation update suggestion around the resource module.
4 | ---
5 |
8 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: "Virtual PowerShell User Group #DSC channel"
4 | url: https://dsccommunity.org/community/contact/
5 | about: "To talk to the community and maintainers of DSC Community, please visit the #DSC channel."
6 |
7 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing).
4 |
5 | ## Running the Tests
6 |
7 | If want to know how to run this module's tests you can look at the [Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines/#running-tests)
8 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebSiteDefaults/en-US/DSC_WebSiteDefaults.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | SettingValue = Changing default Value '{0}' to '{1}'
4 | ValueOk = Default Value '{0}' is already '{1}'
5 | VerboseGetTargetResource = Get-TargetResource has been run.
6 | '@
7 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebAppPoolDefaults/en-US/DSC_WebAppPoolDefaults.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | SettingValue = Changing default value '{0}' to '{1}'
4 | ValueOk = Default value '{0}' is already '{1}'
5 | VerboseGetTargetResource = Get-TargetResource has been run.
6 | '@
7 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Needed for publishing of examples, build worker defaults to core.autocrlf=input.
2 | * text eol=autocrlf
3 |
4 | *.mof text eol=crlf
5 | *.sh text eol=lf
6 | *.svg eol=lf
7 |
8 | # Ensure any exe files are treated as binary
9 | *.exe binary
10 | *.jpg binary
11 | *.xl* binary
12 | *.pfx binary
13 | *.png binary
14 | *.dll binary
15 | *.so binary
16 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebSite/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebSite` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebSite).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisModule/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `IisModule` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministrationDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+IisModule).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebAppPool/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebAppPool` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebAppPool).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_SslSettings/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `SslSettings` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministrationDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+SslSettings).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_SslSettings/en-US/DSC_SslSettings.strings.psd1:
--------------------------------------------------------------------------------
1 | ConvertFrom-StringData @'
2 | UnableToFindConfig = Unable to find configuration in AppHost Config.
3 | SettingsslConfig = Setting {0} ssl binding to {1}.
4 | sslBindingsCorrect = ssl Bindings for {0} are correct.
5 | sslBindingsAbsent = ssl Bindings for {0} are absent.
6 | VerboseGetTargetResource = Get-TargetResource has been run.
7 | '@
8 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplication/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebApplication` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebApplication).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebSiteDefaults/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebSiteDefaults` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebSiteDefaults).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebAppPoolDefaults/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebAppPoolDefaults` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebAppPoolDefaults).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisMimeTypeMapping/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `IisMimeTypeMapping` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministrationDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+IisMimeTypeMapping).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebVirtualDirectory/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebVirtualDirectory` DSC resource is used to...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebVirtualDirectory).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisFeatureDelegation/en-US/DSC_IisFeatureDelegation.strings.psd1:
--------------------------------------------------------------------------------
1 | # Localized resources for DSC_IisFeatureDelegation
2 |
3 | ConvertFrom-StringData @'
4 | GetOverrideMode = Getting override mode for '{0}'.
5 | UnableToGetConfig = Unable to get configuration data for '{0}'.
6 | VerboseGetTargetResource = Get-TargetResource has been run.
7 | VerboseSetTargetResource = Changed overrideMode for '{0}' to '{1}'.
8 | '@
9 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplicationHandler/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebApplicationHandler` DSC resource is used to ...
4 |
5 | ## Requirements
6 |
7 | * Target machine must be running Windows Server 2012 R2 or later.
8 |
9 | ## Known issues
10 |
11 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebApplicationHandler).
12 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplicationHandler/en-US/DSC_WebApplicationHandler.strings.psd1:
--------------------------------------------------------------------------------
1 | ConvertFrom-StringData @'
2 | AddingHandler = Adding handler {0}
3 | UpdatingHandler = Updating handler {0}
4 | RemovingHandler = Removing handler {0}
5 | VerboseGetTargetPresent = Handler is Present {0}
6 | VerboseGetTargetAbsent = Handler is Absent {0}
7 | PropertyNotInDesiredState = Property is not in the desired state {0}
8 | '@
9 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigProperty/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebConfigProperty` DSC resource is used to ensure the value of an
4 | identified property in the web.config file.
5 |
6 | ## Requirements
7 |
8 | * Target machine must be running Windows Server 2012 R2 or later.
9 |
10 | ## Known issues
11 |
12 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebConfigProperty).
13 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisLogging/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `IisLogging` DSC resource is used to set the logfile settings for **all**
4 | websites; for individual websites use the Log options under **xWebSite**.
5 |
6 | ## Requirements
7 |
8 | * Target machine must be running Windows Server 2012 R2 or later.
9 |
10 | ## Known issues
11 |
12 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministrationDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+IisLogging).
13 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisFeatureDelegation/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `IisFeatureDelegation` DSC resource is used to manage the IIS configuration
4 | section locking (overrideMode) to control what configuration can be set in web.config.
5 |
6 | ## Requirements
7 |
8 | * Target machine must be running Windows Server 2012 R2 or later.
9 |
10 | ## Known issues
11 |
12 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministrationDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+IisFeatureDelegation).
13 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigProperty/en-US/DSC_WebConfigProperty.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | VerboseTargetCheckingTarget = Checking for the existence of property "{0}" using filter "{1}" located at "{2}".
4 | VerboseTargetPropertyNotFound = Property "{0}" has not been found.
5 | VerboseTargetPropertyFound = Property "{0}" has been found.
6 | VerboseSetTargetEditItem = Ensuring property "{0}" is set.
7 | VerboseSetTargetRemoveItem = Property "{0}" exists, removing property.
8 | '@
9 |
--------------------------------------------------------------------------------
/Resolve-Dependency.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | Gallery = 'PSGallery'
3 | AllowPrerelease = $false
4 | WithYAML = $true
5 |
6 | UseModuleFast = $true
7 | #ModuleFastVersion = '0.1.2'
8 | #ModuleFastBleedingEdge = $true
9 |
10 | UsePSResourceGet = $true
11 | #PSResourceGetVersion = '1.0.1'
12 |
13 | UsePowerShellGetCompatibilityModule = $true
14 | UsePowerShellGetCompatibilityModuleVersion = '3.0.23-beta23'
15 | }
16 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisMimeTypeMapping/en-US/DSC_IisMimeTypeMapping.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture ="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | AddingType = Adding MIMEType '{0}' for extension '{1}'.
4 | RemovingType = Removing MIMEType '{0}' for extension '{1}'.
5 | TypeExists = MIMEType '{0}' for extension '{1}' is present.
6 | TypeNotPresent = MIMEType '{0}' for extension '{1}' is not present.
7 | VerboseGetTargetPresent = MIMEType is Present.
8 | VerboseGetTargetAbsent = MIMEType is Absent.
9 | '@
10 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_SslSettings/DSC_SslSettings.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0"), FriendlyName("SslSettings")]
2 | class DSC_SslSettings : OMI_BaseResource
3 | {
4 | [Key, Description("Name of website in which to modify the SSL Settings")] String Name;
5 | [Required, Description("The Bindings in which to modify for the website"), ValueMap{"","Ssl","SslNegotiateCert","SslRequireCert","Ssl128"},Values{"","Ssl","SslNegotiateCert","SslRequireCert","Ssl128"}] String Bindings[];
6 | [Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"},Description("Whether the bindings should be present or absent")] String Ensure;
7 | };
8 |
--------------------------------------------------------------------------------
/source/Examples/Resources/SslSettings/Sample_SslSettings_RequireCert.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_SslSettings_RequireCert
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | SslSettings SiteDefaults
15 | {
16 | Ensure = 'Present'
17 | Name = 'contoso.com'
18 | Bindings = @('Ssl', 'SslNegotiateCert', 'SslRequireCert')
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_LogFlags.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_LogFlags
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date', 'Time', 'ClientIP', 'ServerIP', 'UserAgent')
18 | LogFormat = 'W3C'
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisFeatureDelegation/DSC_IisFeatureDelegation.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0"), FriendlyName("IisFeatureDelegation")]
2 | class DSC_IisFeatureDelegation : OMI_BaseResource
3 | {
4 | [Key, Description("Specifies the configuration path. This can be either an IIS configuration path in the format computer machine/webroot/apphost, or the IIS module path in this format IIS:\\sites\\Default Web Site.")] String Path;
5 | [Key, Description("Specifies the IIS configuration section to lock or unlock.")] String Filter;
6 | [Required, Description("Determines whether to lock or unlock the specified section."), ValueMap{"Allow", "Deny"}, Values{"Allow", "Deny"}] string OverrideMode;
7 | };
8 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigPropertyCollection/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | The `WebConfigPropertyCollection` DSC resource is used to ensure the value of an
4 | identified property collection item's property in the web.config file.
5 |
6 | >Builds upon the deprecated **WebConfigKeyValue** resource to support all web.config
7 | >elements that contain collections of child items.
8 |
9 | ## Requirements
10 |
11 | * Target machine must be running Windows Server 2012 R2 or later.
12 |
13 | ## Known issues
14 |
15 | All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/WebAdministration/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+WebConfigPropertyCollection).
16 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_IISFeatureDelegation.config.ps1:
--------------------------------------------------------------------------------
1 | configuration DSC_IisFeatureDelegation_AllowDelegation
2 | {
3 | Import-DscResource -ModuleName WebAdministrationDsc
4 |
5 | IisFeatureDelegation AllowDelegation
6 | {
7 | Path = 'MACHINE/WEBROOT/APPHOST'
8 | Filter = '/system.web/customErrors'
9 | OverrideMode = 'Allow'
10 | }
11 | }
12 |
13 | configuration DSC_IisFeatureDelegation_DenyDelegation
14 | {
15 | Import-DscResource -ModuleName WebAdministrationDsc
16 |
17 | IisFeatureDelegation DenyDelegation
18 | {
19 | Path = 'MACHINE/WEBROOT/APPHOST'
20 | Filter = '/system.webServer/defaultDocument'
21 | OverrideMode = 'Deny'
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigProperty/DSC_WebConfigProperty.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0.0"), FriendlyName("WebConfigProperty")]
2 | class Dsc_WebConfigProperty : OMI_BaseResource
3 | {
4 | [Key, Description("Path to website location (IIS or WebAdministration format).")] String WebsitePath;
5 | [Key, Description("Filter used to locate property to update.")] String Filter;
6 | [Key, Description("Name of the property to update.")] String PropertyName;
7 | [Write, Description("Indicates if the property and value should be present or absent. Defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
8 | [Write, Description("Value of the property to update.")] String Value;
9 | };
10 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebSiteDefaults.config.ps1:
--------------------------------------------------------------------------------
1 | [string] $originalValue = (Get-WebConfigurationProperty `
2 | -PSPath 'MACHINE/WEBROOT/APPHOST' `
3 | -Filter 'system.applicationHost/sites/virtualDirectoryDefaults' `
4 | -Name 'allowSubDirConfig').Value
5 |
6 | if ($originalValue -eq "true")
7 | {
8 | $env:PesterVirtualDirectoryDefaults = "false"
9 | }
10 | else
11 | {
12 | $env:PesterVirtualDirectoryDefaults = "true"
13 | }
14 |
15 | configuration DSC_WebSiteDefaults_Config
16 | {
17 | Import-DscResource -ModuleName WebAdministrationDsc
18 |
19 | WebSiteDefaults virtualDirectoryDefaults
20 | {
21 | IsSingleInstance = 'Yes'
22 | AllowSubDirConfig = "$env:PesterVirtualDirectoryDefaults"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_SslSettings.config.ps1:
--------------------------------------------------------------------------------
1 | #requires -Version 4
2 |
3 | configuration DSC_SslSettings_Present
4 | {
5 | Import-DscResource -ModuleName WebAdministrationDsc
6 |
7 | Node $AllNodes.NodeName
8 | {
9 | SslSettings Website
10 | {
11 | Ensure = 'Present'
12 | Name = $Node.Website
13 | Bindings = $Node.Bindings
14 | }
15 | }
16 | }
17 |
18 | configuration DSC_SslSettings_Absent
19 | {
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $AllNodes.NodeName
23 | {
24 | SslSettings Website
25 | {
26 | Ensure = 'Absent'
27 | Name = $Node.Website
28 | Bindings = ''
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisMimeTypeMapping/DSC_IisMimeTypeMapping.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0"), FriendlyName("IisMimeTypeMapping")]
2 | class DSC_IisMimeTypeMapping : OMI_BaseResource
3 | {
4 | [Key, Description("This can be either an IIS configuration path in the format computername/webroot/apphost, or the IIS module path in this format IIS:\\sites\\Default Web Site.")] String ConfigurationPath;
5 | [Key, Description("The file extension to map such as .html or .xml.")] string Extension;
6 | [Key, Description("The MIME type to map that extension to such as text/html.")] string MimeType;
7 | [Write, Description("Ensures that the MIME type mapping is Present or Absent."),ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
8 | };
9 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_Rollover.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_Rollover
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date', 'Time', 'ClientIP', 'UserName', 'ServerIP')
18 | LoglocalTimeRollover = $true
19 | LogPeriod = 'Hourly'
20 | LogFormat = 'W3C'
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_Truncate.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_Truncate
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date', 'Time', 'ClientIP', 'UserName', 'ServerIP')
18 | LoglocalTimeRollover = $true
19 | LogTruncateSize = '2097152'
20 | LogFormat = 'W3C'
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_SslSettings.config.psd1:
--------------------------------------------------------------------------------
1 | #requires -Version 1
2 |
3 | @{
4 | AllNodes = @(
5 | @{
6 | NodeName = 'LocalHost'
7 | PSDscAllowPlainTextPassword = $true
8 | Website = 'WebsiteForSSLSettings'
9 | ApplicationPool = 'DefaultAppPool'
10 | PhysicalPath = 'C:\inetpub\wwwroot'
11 | HTTPSProtocol = 'https'
12 | HTTPSPort = '443'
13 | HTTPSHostname = 'https.website'
14 | CertificateStoreName = 'My'
15 | SslFlags = '1'
16 | Bindings = @('Ssl')
17 | }
18 | )
19 | }
20 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebAppPoolDefaults/DSC_WebAppPoolDefaults.schema.mof:
--------------------------------------------------------------------------------
1 |
2 | [ClassVersion("1.0.0.0"), FriendlyName("WebAppPoolDefaults")]
3 | class DSC_WebAppPoolDefaults : OMI_BaseResource
4 | {
5 | [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
6 | [write, Description("applicationPools/applicationPoolDefaults/managedRuntimeVersion"), ValueMap{"","v2.0","v4.0"}, Values{"","v2.0","v4.0"}] string ManagedRuntimeVersion;
7 | [write, Description("applicationPools/applicationPoolDefaults/processModel/identityType"), ValueMap{"ApplicationPoolIdentity","LocalService","LocalSystem","NetworkService"}, Values{"ApplicationPoolIdentity","LocalService","LocalSystem","NetworkService"}] string IdentityType;
8 | };
9 |
--------------------------------------------------------------------------------
/source/Modules/WebAdministrationDsc.Common/en-US/WebAdministrationDsc.Common.strings.psd1:
--------------------------------------------------------------------------------
1 | # Localized resources for helper module WebAdministrationDsc.Common.
2 |
3 | ConvertFrom-StringData @'
4 | ArrayDoesNotMatch = One or more values in an array does not match the desired state. Details of the changes are below. (WACOMMON0004)
5 | ArrayValueThatDoesNotMatch = {0} - {1} (WACOMMON0005)
6 | PropertyValueOfTypeDoesNotMatch = {0} value does not match. Current value is '{1}', but expected the value '{2}'. (WACOMMON0006)
7 | UnableToCompareType = Unable to compare the type {0} as it is not handled by the Test-DscPropertyState cmdlet. (WACOMMON0007)
8 | StartProcess = Started the process with id {0} using the path '{1}', and with a timeout value of {2} seconds. (WACOMMON0009)
9 | '@
10 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebVirtualDirectory/DSC_WebVirtualDirectory.schema.mof:
--------------------------------------------------------------------------------
1 |
2 | [ClassVersion("1.0.0.0"), FriendlyName("WebVirtualDirectory")]
3 | class DSC_WebVirtualDirectory : OMI_BaseResource
4 | {
5 | [Key, Description("Name of website with which Web Application is associated")] string Website;
6 | [Key, Description("Web application name for the virtual directory")] string WebApplication;
7 | [Key, Description("Name of virtual directory")] string Name;
8 | [Required, Description("Physical path for the virtual directory")] string PhysicalPath;
9 | [Write, Description("Credential to use for accessing the virtual directory"), EmbeddedInstance("MSFT_Credential")] String Credential;
10 | [Write, Description("Whether virtual directory should be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
11 | };
12 |
--------------------------------------------------------------------------------
/source/en-US/about_xWebAdministration.help.txt:
--------------------------------------------------------------------------------
1 | TOPIC
2 | about_WebAdministrationDsc
3 |
4 | SHORT DESCRIPTION
5 | DSC resources for configuring web servers and related components.
6 |
7 | LONG DESCRIPTION
8 | This module contains DSC resources for deploying and configuring web servers and related components.
9 |
10 | EXAMPLES
11 | PS C:\> Get-DscResource -Module about_WebAdministrationDsc
12 |
13 | NOTE:
14 | Thank you to the DSC Community contributors who contributed to this module by
15 | writing code, sharing opinions, and provided feedback.
16 |
17 | TROUBLESHOOTING NOTE:
18 | Go to the Github repository for read about issues, submit a new issue, and read
19 | about new releases. https://github.com/dsccommunity/WebAdministrationDsc
20 |
21 | SEE ALSO
22 | - https://github.com/dsccommunity/WebAdministrationDsc
23 |
24 | KEYWORDS
25 | DSC, DscResource, IIS
26 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebSiteDefaults/DSC_WebSiteDefaults.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0"), FriendlyName("WebSiteDefaults")]
2 | class DSC_WebSiteDefaults : OMI_BaseResource
3 | {
4 | [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
5 | [write, Description("sites/siteDefaults/logFile/logFormat"), ValueMap{"W3C","IIS","NCSA","Custom"}, Values{"W3C","IIS","NCSA","Custom"}] string LogFormat;
6 | [write, Description("sites/siteDefaults/logFile/directory")] string LogDirectory;
7 | [write, Description("sites/siteDefaults/traceFailedRequestsLogging/directory")] string TraceLogDirectory;
8 | [write, Description("sites/applicationDefaults/applicationPool")] string DefaultApplicationPool;
9 | [write, Description("sites/virtualDirectoryDefaults/allowSubDirConfig"), ValueMap{"true","false"}, Values{"true","false"}] string AllowSubDirConfig;
10 | };
11 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebVirtualDirectory.config.psd1:
--------------------------------------------------------------------------------
1 | #requires -Version 1
2 | @{
3 | AllNodes = @(
4 | @{
5 | NodeName = 'LocalHost'
6 | PSDscAllowPlainTextPassword = $true
7 | Website = 'WebsiteForVirtualDirectory'
8 | WebsitePhysicalPath = 'C:\inetpub\wwwroot'
9 | ApplicationPool = 'DefaultAppPool'
10 | Port = '80'
11 | WebApplication = 'WebApplication'
12 | WebApplicationPhysicalPath = "C:\inetpub\webapp"
13 | WebVirtualDirectory = 'VirtualDirectory'
14 | PhysicalPath = 'C:\inetpub\virtualdirectory'
15 | Credential = @{
16 | UserName = 'CONTOSO\JDoe'
17 | Password = '5t6y7u8i'
18 | }
19 | HostName = 'http.website'
20 | }
21 | )
22 | }
23 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebApplicationHandler/Sample_WebApplicationHandler.ps1:
--------------------------------------------------------------------------------
1 | Configuration Example
2 | {
3 | Import-DscResource -ModuleName WebAdministrationDsc
4 |
5 | Node 'localhost'
6 | {
7 |
8 | WebApplicationHandler WebHandlerTest
9 | {
10 | Path = 'MACHINE/WEBROOT/APPHOST'
11 | Name = 'ATest-WebHandler'
12 | PhysicalHandlerPath = '*'
13 | Verb = '*'
14 | Modules = 'IsapiModule'
15 | RequireAccess = 'None'
16 | ScriptProcessor = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
17 | ResourceType = 'Unspecified'
18 | AllowPathInfo = $false
19 | ResponseBufferLimit = 0
20 | Type = $null
21 | PreCondition = $null
22 | Location = 'Default Web Site/TestDir'
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/GitVersion.yml:
--------------------------------------------------------------------------------
1 | mode: ContinuousDelivery
2 | next-version: 3.1.0
3 | major-version-bump-message: '(breaking\schange|breaking|major)\b'
4 | minor-version-bump-message: '(adds?|features?|minor)\b'
5 | patch-version-bump-message: '\s?(fix|patch)'
6 | no-bump-message: '\+semver:\s?(none|skip)'
7 | assembly-informational-format: '{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}'
8 | branches:
9 | master:
10 | tag: preview
11 | regex: ^main$
12 | pull-request:
13 | tag: PR
14 | feature:
15 | tag: useBranchName
16 | increment: Minor
17 | regex: f(eature(s)?)?[\/-]
18 | source-branches: ['master']
19 | hotfix:
20 | tag: fix
21 | increment: Patch
22 | regex: (hot)?fix(es)?[\/-]
23 | source-branches: ['master']
24 |
25 | ignore:
26 | sha: [
27 | e429fb7a2fa7b52d3b86174c3085e1a3d3179a02,
28 | a8975e79bb9e42fb45c337896c7ae6c6c5b25509,
29 | a555b63949f64d2e90b6210c816e5cd0fb969eb6,
30 | 66f4d972148ca61b71db4da020f074906d289851
31 | ]
32 | merge-message-formats: {}
33 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisModule/DSC_IisModule.schema.mof:
--------------------------------------------------------------------------------
1 |
2 | [ClassVersion("1.0.0"), FriendlyName("IisModule")]
3 | class DSC_IisModule : OMI_BaseResource
4 | {
5 | [Key, Description("The path to the module, usually a dll, to be added to IIS.")] String Path;
6 | [Required, Description("The logical name of the module to add to IIS.")] String Name;
7 | [Required, Description("The allowed request Path example: *.php")] String RequestPath;
8 | [Required, Description("The supported verbs for the module.")] String Verb[];
9 | [Write, Description("The IIS Site to register the module.")] String SiteName;
10 | [Write, Description("Should the module be present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
11 | [Write, Description("The type of the module."), ValueMap{"FastCgiModule"}, Values{"FastCgiModule"}] String ModuleType;
12 | [Read, Description("The End Point is setup. Such as a Fast Cgi endpoint.")] Boolean EndPointSetup;
13 | };
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_RemoveDefault.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_RemoveDefault
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
11 |
12 | Node $NodeName
13 | {
14 | # Install the IIS role
15 | WindowsFeature IIS
16 | {
17 | Ensure = 'Present'
18 | Name = 'Web-Server'
19 | }
20 |
21 | # Stop the default website
22 | WebSite DefaultSite
23 | {
24 | Ensure = 'Present'
25 | Name = 'Default Web Site'
26 | State = 'Stopped'
27 | ServerAutoStart = $false
28 | PhysicalPath = 'C:\inetpub\wwwroot'
29 | DependsOn = '[WindowsFeature]IIS'
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_LogCustomFields_EnsurePresentDefault.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_LogCustomFields_EnsurePresentDefault
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent')
18 | LogFormat = 'W3C'
19 | LogTargetW3C = 'File,ETW'
20 | LogCustomFields = @(
21 | DSC_LogCustomField
22 | {
23 | LogFieldName = 'ClientEncoding'
24 | SourceName = 'Accept-Encoding'
25 | SourceType = 'RequestHeader'
26 | }
27 | )
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSiteDefaults/Sample_WebSiteDefaults.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | An example of configuring the website default settings.
4 | .DESCRIPTION
5 | This examples show how to use WebSiteDefaults for configuring the website default settings.
6 | #>
7 | Configuration Sample_WebSiteDefaults
8 | {
9 | param
10 | (
11 | # Target nodes to apply the configuration
12 | [string[]]$NodeName = 'localhost'
13 | )
14 |
15 | # Import the module that defines custom resources
16 | Import-DscResource -Module WebAdministrationDsc
17 |
18 | Node $NodeName
19 | {
20 | WebSiteDefaults SiteDefaults
21 | {
22 | IsSingleInstance = 'Yes'
23 | LogFormat = 'IIS'
24 | LogDirectory = 'C:\inetpub\logs\LogFiles'
25 | TraceLogDirectory = 'C:\inetpub\logs\FailedReqLogFiles'
26 | DefaultApplicationPool = 'DefaultAppPool'
27 | AllowSubDirConfig = 'true'
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | codecov:
2 | require_ci_to_pass: no
3 | # main should be the baseline for reporting
4 | branch: main
5 |
6 | comment:
7 | layout: "reach, diff, flags, files"
8 | behavior: default
9 |
10 | coverage:
11 | range: 50..80
12 | round: down
13 | precision: 0
14 |
15 | status:
16 | project:
17 | default:
18 | # Set the overall project code coverage requirement to 70%
19 | target: 70
20 | patch:
21 | default:
22 | # Set the pull request requirement to not regress overall coverage by more than 5%
23 | # and let codecov.io set the goal for the code changed in the patch.
24 | target: auto
25 | threshold: 5
26 |
27 | # This is not needed if the module only contain class-based resources.
28 | fixes:
29 | - '^\d+\.\d+\.\d+::source' # move path "X.Y.Z" => "source"
30 |
31 | # Use this if there are paths that should not be part of the code coverage, for
32 | # example a deprecated function where tests has been removed.
33 | #ignore:
34 | # - 'source/Public/Get-Deprecated.ps1'
35 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebVirtualDirectory/en-US/DSC_WebVirtualDirectory.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture ="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | VerboseGetTargetResource = Get-TargetResource has been run.
4 | VerboseSetTargetPhysicalPath = Updating PhysicalPath for Web Virtual Directory '{0}'.
5 | VerboseSetTargetCredential = Updating Credential for Web Virtual Directory '{0}'.
6 | VerboseSetTargetCreateVirtualDirectory = Creating new Web Virtual Directory '{0}'.
7 | VerboseSetTargetRemoveVirtualDirectory = Removing existing Virtual Directory '{0}'.
8 | VerboseTestTargetPhysicalPathFalse = Physical path '{0}' for Web Virtual Directory '{1}' is not in desired state.
9 | VerboseTestTargetCredentialFalse = Credential '{0}' for Web Virtual Directory '{1}' is not in desired state.
10 | VerboseTestTargetTrue = Web Virtual Directory is in desired state.
11 | VerboseTestTargetAbsentTrue = Web Virtual Directory '{0}' should be Absent and is Absent.
12 | '@
13 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigPropertyCollection/en-US/DSC_WebConfigPropertyCollection.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | VerboseTargetCheckingTarget = Checking for the existence of property "{0}" in collection item "{1}/{2}" with key "{3}={4}" using filter "{5}" located at "{6}".
4 | VerboseTargetItemNotFound = Collection item "{0}/{1}" with key "{2}={3}" has not been found.
5 | VerboseTargetPropertyNotFound = Property "{0}" has not been found.
6 | VerboseTargetPropertyFound = Property "{0}" has been found.
7 | VerboseSetTargetAddItem = Collection item "{0}/{1}" with key "{2}={3}" does not exist, adding with property "{4}".
8 | VerboseSetTargetEditItem = Collection item "{0}/{1}" with key "{2}={3}" exists, editing property "{4}".
9 | VerboseSetTargetRemoveItem = Property "{0}" exists, removing property.
10 | VerboseTestTargetPropertyValueNotFound = Property "{0}" has not been found with expected value.
11 | '@
12 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_LogCustomFields_EnsureAbsent.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_LogCustomFields_EnsureAbsent
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent')
18 | LogFormat = 'W3C'
19 | LogTargetW3C = 'File,ETW'
20 | LogCustomFields = @(
21 | DSC_LogCustomField
22 | {
23 | LogFieldName = 'ClientEncoding'
24 | SourceName = 'Accept-Encoding'
25 | SourceType = 'RequestHeader'
26 | Ensure = 'Absent'
27 | }
28 | )
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisLogging/Sample_IisLogging_LogCustomFields_EnsurePresentExplicitly.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisLogging_LogCustomFields_EnsurePresentExplicitly
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost'
7 | )
8 |
9 | # Import the module that defines custom resources
10 | Import-DscResource -Module WebAdministrationDsc
11 |
12 | Node $NodeName
13 | {
14 | IisLogging Logging
15 | {
16 | LogPath = 'C:\IISLogFiles'
17 | Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent')
18 | LogFormat = 'W3C'
19 | LogTargetW3C = 'File,ETW'
20 | LogCustomFields = @(
21 | DSC_LogCustomField
22 | {
23 | LogFieldName = 'ClientEncoding'
24 | SourceName = 'Accept-Encoding'
25 | SourceType = 'RequestHeader'
26 | Ensure = 'Present'
27 | }
28 | )
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebAppPoolDefaults/Sample_WebAppPoolDefaults.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | An example of configuring the application pool default settings.
4 | .DESCRIPTION
5 | This examples show how to use WebAppPoolDefaults for configuring the application pool default settings.
6 | The resource is currently limited to configuring the managed runtime version and the identity used for the application pools.
7 | #>
8 | Configuration Sample_WebAppPoolDefaults
9 | {
10 | param
11 | (
12 | # Target nodes to apply the configuration
13 | [string[]]$NodeName = 'localhost'
14 | )
15 |
16 | # Import the module that defines custom resources
17 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
18 |
19 | Node $NodeName
20 | {
21 | # Configures the application pool defaults.
22 | WebAppPoolDefaults PoolDefaults
23 | {
24 | IsSingleInstance = 'Yes'
25 | ManagedRuntimeVersion = 'v4.0'
26 | IdentityType = 'ApplicationPoolIdentity'
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) DSC Community contributors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigProperty/Sample_WebConfigProperty_Remove.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Removes configuration of directory browsing in the default website.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigProperty DSC resource for removing a configuration property.
7 | It will remove the system.webServer/directoryBrowse enabled attribute (if present) in the Web.config file for the default website.
8 | #>
9 | Configuration Sample_WebConfigProperty_Remove
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigProperty "$($NodeName) - Ensure 'directory browsing' is set to disabled - Remove"
25 | {
26 | WebsitePath = 'IIS:\Sites\Default Web Site'
27 | Filter = 'system.webServer/directoryBrowse'
28 | PropertyName = 'enabled'
29 | Ensure = 'Absent'
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/RequiredModules.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | PSDependOptions = @{
3 | AddToPath = $true
4 | Target = 'output\RequiredModules'
5 | Parameters = @{
6 | Repository = 'PSGallery'
7 | }
8 | }
9 |
10 | InvokeBuild = 'latest'
11 | PSScriptAnalyzer = 'latest'
12 | Pester = '4.10.1'
13 | Plaster = 'latest'
14 | ModuleBuilder = 'latest'
15 | ChangelogManagement = 'latest'
16 | Sampler = 'latest'
17 | 'Sampler.GitHubTasks' = 'latest'
18 | MarkdownLinkCheck = 'latest'
19 | 'DscResource.Test' = 'latest'
20 | xDscResourceDesigner = 'latest'
21 | PSPKI = 'latest'
22 |
23 | # Build dependencies needed for using the module
24 | 'DscResource.Common' = 'latest'
25 |
26 | # Analyzer rules
27 | 'DscResource.AnalyzerRules' = 'latest'
28 | 'Indented.ScriptAnalyzerRules' = 'latest'
29 |
30 | # Prerequisite modules for documentation.
31 | 'DscResource.DocGenerator' = 'latest'
32 | PlatyPS = 'latest'
33 | }
34 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigProperty/Sample_WebConfigProperty_Add.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Disables directory browsing in the default website.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigProperty DSC resource for setting a configuration property.
7 | It will set the value of the system.webServer/directoryBrowse enabled attribute to false in the Web.config file for the default website.
8 | #>
9 | Configuration Sample_WebConfigProperty_Add
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigProperty "$($NodeName) - Ensure 'directory browsing' is set to disabled - Add"
25 | {
26 | WebsitePath = 'IIS:\Sites\Default Web Site'
27 | Filter = 'system.webServer/directoryBrowse'
28 | PropertyName = 'enabled'
29 | Value = 'false'
30 | Ensure = 'Present'
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_StopDefault.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | When configuring a new IIS server, several references recommend removing or stopping the default website for security purposes.
4 | This example sets up your IIS web server by installing IIS Windows Feature.
5 | After that, it will stop the default website by setting `State = Stopped`.
6 | #>
7 | Configuration Sample_WebSite_StopDefault
8 | {
9 | param
10 | (
11 | # Target nodes to apply the configuration
12 | [string[]]$NodeName = 'localhost'
13 | )
14 | # Import the module that defines custom resources
15 | Import-DscResource -Module WebAdministrationDsc
16 | Node $NodeName
17 | {
18 | # Install the IIS role
19 | WindowsFeature IIS
20 | {
21 | Ensure = "Present"
22 | Name = "Web-Server"
23 | }
24 | # Stop the default website
25 | WebSite DefaultSite
26 | {
27 | Ensure = "Present"
28 | Name = "Default Web Site"
29 | State = "Stopped"
30 | PhysicalPath = "C:\inetpub\wwwroot"
31 | DependsOn = "[WindowsFeature]IIS"
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebConfigPropertyCollection/DSC_WebConfigPropertyCollection.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0.0"), FriendlyName("WebConfigPropertyCollection")]
2 | class DSC_WebConfigPropertyCollection : OMI_BaseResource
3 | {
4 | [Key, Description("Path to website location (IIS or WebAdministration format).")] String WebsitePath;
5 | [Key, Description("Filter used to locate property collection to update.")] String Filter;
6 | [Key, Description("Name of the property collection to update.")] String CollectionName;
7 | [Key, Description("Name of the property collection item to update.")] String ItemName;
8 | [Key, Description("Name of the key of the property collection item to update.")] String ItemKeyName;
9 | [Key, Description("Value of the key of the property collection item to update.")] String ItemKeyValue;
10 | [Key, Description("Name of the property of the property collection item to update.")] String ItemPropertyName;
11 | [Write, Description("Value of the property of the property collection item to update.")] String ItemPropertyValue;
12 | [Write, Description("Indicates if the property and value of the property collection item should be present or absent. Defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
13 | };
14 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisModule/en-US/DSC_IisModule.strings.psd1:
--------------------------------------------------------------------------------
1 | ConvertFrom-StringData @'
2 | VerboseGetTargetResource = Get-TargetResource has been run.
3 | VerboseSetTargetRemoveHandler = Removing handler.
4 | VerboseSetTargetAddHandler = Adding handler.
5 | VerboseSetTargetAddfastCgi = Adding fastCgi.
6 | VerboseTestTargetResource = Get-TargetResource has been run.
7 | VerboseGetIisHandler = Getting Handler for '{0}' in Site '{1}'.
8 | VerboseTestTargetResourceImplVerb = Matched Verb '{0}'.
9 | VerboseTestTargetResourceImplExtraVerb = Extra Verb '{0}'.
10 | VerboseTestTargetResourceImplRequestPath = RequestPath is '{0}'.
11 | VerboseTestTargetResourceImplPath = Path is '{0}'.
12 | VerboseTestTargetResourceImplresourceStatusRequestPath = StatusRequestPath is '{0}'.
13 | VerboseTestTargetResourceImplresourceStatusPath = StatusPath is '{0}'.
14 | VerboseTestTargetResourceImplModulePresent = Module present is '{0}'.
15 | VerboseTestTargetResourceImplModuleConfigured = ModuleConfigured is '{0}'.
16 | '@
17 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebApplication.config.psd1:
--------------------------------------------------------------------------------
1 | #requires -Version 1
2 | @{
3 | AllNodes = @(
4 | @{
5 | NodeName = 'LocalHost'
6 | PSDscAllowPlainTextPassword = $true
7 | Website = 'WebsiteForWebApplication'
8 | WebApplication = 'WebApplication'
9 | ApplicationType = 'WebsiteApplicationType'
10 | ApplicationPool = 'DefaultAppPool'
11 | PhysicalPath = 'C:\inetpub\wwwroot'
12 | PreloadEnabled = $true
13 | ServiceAutoStartEnabled = $true
14 | ServiceAutoStartProvider = 'WebsiteServiceAutoStartProvider'
15 | AuthenticationInfoAnonymous = $true
16 | AuthenticationInfoBasic = $false
17 | AuthenticationInfoDigest = $false
18 | AuthenticationInfoWindows = $true
19 | HTTPSProtocol = 'https'
20 | HTTPSPort = '443'
21 | HTTPSHostname = 'https.website'
22 | CertificateStoreName = 'My'
23 | SslFlags = '1'
24 | WebApplicationSslFlags = @('Ssl')
25 | EnabledProtocols = @('http', 'net.tcp')
26 | }
27 | )
28 | }
29 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigPropertyCollection/Sample_WebConfigPropertyCollection_Add.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Disables the HTTP TRACE method at the server level.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigPropertyCollection DSC resource for adding a configuration element.
7 | It will add an "add" element to the system.webServer/security/requestFiltering/verbs collection to disable the HTTP TRACE verb.
8 | #>
9 | Configuration Sample_WebConfigPropertyCollection_Add
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigPropertyCollection "$($NodeName) - Disable HTTP TRACE method"
25 | {
26 | WebsitePath = 'MACHINE/WEBROOT/APPHOST'
27 | Filter = 'system.webServer/security/requestFiltering'
28 | CollectionName = 'verbs'
29 | ItemName = 'add'
30 | ItemKeyName = 'verb'
31 | ItemKeyValue = 'TRACE'
32 | ItemPropertyName = 'allowed'
33 | ItemPropertyValue = 'false'
34 | Ensure = 'Present'
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigPropertyCollection/Sample_WebConfigPropertyCollection_Remove.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Removes disabling the HTTP TRACE method at the server level.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigPropertyCollection DSC resource for removing a configuration element.
7 | It will remove the "add" element from the system.webServer/security/requestFiltering/verbs collection (if present) for disabling the HTTP TRACE verb.
8 | #>
9 | Configuration Sample_WebConfigPropertyCollection_Remove
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigPropertyCollection "$($NodeName) - Remove disabling HTTP TRACE method"
25 | {
26 | WebsitePath = 'MACHINE/WEBROOT/APPHOST'
27 | Filter = 'system.webServer/security/requestFiltering'
28 | CollectionName = 'verbs'
29 | ItemName = 'add'
30 | ItemKeyName = 'verb'
31 | ItemKeyValue = 'TRACE'
32 | ItemPropertyName = 'allowed'
33 | Ensure = 'Absent'
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Configuration for probot-stale - https://github.com/probot/stale
2 |
3 | limitPerRun: 30
4 |
5 | pulls:
6 | daysUntilStale: 14
7 | daysUntilClose: false
8 | exemptProjects: true
9 | exemptMilestones: true
10 | staleLabel: abandoned
11 | exemptLabels:
12 | - needs review
13 | - on hold
14 | - waiting for CLA pass
15 |
16 | markComment: >
17 | Labeling this pull request (PR) as abandoned since it has gone 14 days or more
18 | since the last update. An abandoned PR can be continued by another contributor.
19 | The abandoned label will be removed if work on this PR is taken up again.
20 |
21 | issues:
22 | daysUntilStale: 30
23 | daysUntilClose: 40
24 | exemptProjects: true
25 | exemptMilestones: true
26 | staleLabel: stale
27 | exemptLabels:
28 | - bug
29 | - enhancement
30 | - tests
31 | - documentation
32 | - resource proposal
33 | - on hold
34 |
35 | markComment: >
36 | This issue has been automatically marked as stale because
37 | it has not had activity from the community in the last 30 days. It will be
38 | closed if no further activity occurs within 10 days. If the issue is labelled
39 | with any of the work labels (e.g bug, enhancement, documentation, or tests)
40 | then the issue will not auto-close.
41 |
42 | closeComment: >
43 | This issue has been automatically closed because it is has not had activity
44 | from the community in the last 40 days.
45 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigPropertyCollection/Sample_WebConfigPropertyCollection_SingleItemRemove.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Removes making appsettings.json inaccessible to clients.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigPropertyCollection DSC resource for removing a single item configuration element.
7 | It will remove the "add" element from the system.webServer/security/requestFiltering/hiddenSegments collection (if present) for blocking appsettings.json.
8 | #>
9 | Configuration Sample_WebConfigPropertyCollection_SingleItemRemove
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigPropertyCollection "$($NodeName) - Remove blocking appsettings.json"
25 | {
26 | WebsitePath = 'MACHINE/WEBROOT/APPHOST'
27 | Filter = 'system.webServer/security/requestFiltering'
28 | CollectionName = 'hiddenSegments'
29 | ItemName = 'add'
30 | ItemKeyName = '*'
31 | ItemKeyValue = 'appsettings.json'
32 | ItemPropertyName = 'segment'
33 | Ensure = 'Absent'
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebConfigPropertyCollection/Sample_WebConfigPropertyCollection_SingleItemAdd.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Make appsettings.json inaccessible to clients.
4 |
5 | .DESCRIPTION
6 | This example shows how to use the WebConfigPropertyCollection DSC resource for adding a single item configuration element.
7 | It will add an "add" element to the system.webServer/security/requestFiltering/hiddenSegments collection to block appsettings.json.
8 | #>
9 | Configuration Sample_WebConfigPropertyCollection_SingleItemAdd
10 | {
11 | param
12 | (
13 | # Target nodes to apply the configuration.
14 | [Parameter()]
15 | [String[]]
16 | $NodeName = 'localhost'
17 | )
18 |
19 | # Import the modules that define custom resources
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | Node $NodeName
23 | {
24 | WebConfigPropertyCollection "$($NodeName) - Block appsettings.json"
25 | {
26 | WebsitePath = 'MACHINE/WEBROOT/APPHOST'
27 | Filter = 'system.webServer/security/requestFiltering'
28 | CollectionName = 'hiddenSegments'
29 | ItemName = 'add'
30 | ItemKeyName = '*'
31 | ItemKeyValue = 'appsettings.json'
32 | ItemPropertyName = 'segment'
33 | ItemPropertyValue = 'appsettings.json'
34 | Ensure = 'Present'
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | ## Security
2 |
3 | The DSC Community takes the security of our modules seriously, which includes all source code repositories managed through our GitHub organization.
4 |
5 | If you believe you have found a security vulnerability in any DSC Community owned repository, please report it to us as described below.
6 |
7 | ## Reporting Security Issues
8 |
9 | **Please do not report security vulnerabilities through public GitHub issues.**
10 |
11 | Instead, please report them to one or several members of the DSC Community organization.
12 | The easiest way to do so is to send us a direct message via twitter or slack.
13 |
14 | You should receive a response within 48 hours. If for some reason you do not, please follow up to other member of the community.
15 |
16 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
17 |
18 | * Type of issue
19 | * Full paths of source file(s) related to the manifestation of the issue
20 | * The location of the affected source code (tag/branch/commit or direct URL)
21 | * Any special configuration required to reproduce the issue
22 | * Step-by-step instructions to reproduce the issue
23 | * Proof-of-concept or exploit code (if possible)
24 | * Impact of the issue, including how an attacker might exploit the issue
25 |
26 | This information will help us triage your report more quickly.
27 |
28 | ## Preferred Languages
29 |
30 | We prefer all communications to be in English.
31 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebApplication/Sample_WebApplication.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | This shows an example for all possible settings for the WebApplication resource
3 | #>
4 | configuration Sample_WebApplication
5 | {
6 |
7 | param
8 | (
9 | # Target nodes to apply the configuration
10 | [String[]] $NodeName = 'localhost',
11 |
12 | [Parameter(Mandatory)]
13 | [ValidateNotNullOrEmpty()]
14 | [String] $PhysicalPath
15 | )
16 |
17 | Import-DscResource -ModuleName WebAdministrationDsc
18 |
19 | node $NodeName
20 | {
21 | WebApplication WebApplication
22 | {
23 | Website = 'Website'
24 | Ensure = 'Present'
25 | Name = 'WebApplication'
26 | PhysicalPath = $PhysicalPath
27 | WebAppPool = 'DefaultAppPool'
28 | ApplicationType = 'ApplicationType'
29 | AuthenticationInfo = `
30 | DSC_WebApplicationAuthenticationInformation
31 | {
32 | Anonymous = $true
33 | Basic = $false
34 | Digest = $false
35 | Windows = $false
36 | }
37 | PreloadEnabled = $true
38 | ServiceAutoStartEnabled = $true
39 | ServiceAutoStartProvider = 'ServiceAutoStartProvider'
40 | SslFlags = @('Ssl')
41 | EnabledProtocols = @('http', 'net.tcp')
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/WebAdministrationDsc.TestHarness.psm1:
--------------------------------------------------------------------------------
1 | function Invoke-WebAdministrationDscTests() {
2 | param
3 | (
4 | [Parameter(Mandatory = $false)]
5 | [System.String] $TestResultsFile,
6 |
7 | [Parameter(Mandatory = $false)]
8 | [System.String] $DscTestsPath
9 | )
10 |
11 | Write-Verbose 'Commencing WebAdministrationDsc unit tests'
12 |
13 | $repoDir = Join-Path $PSScriptRoot '..' -Resolve
14 |
15 | $testCoverageFiles = @()
16 | Get-ChildItem "$repoDir\DSCResources\**\*.psm1" -Recurse | ForEach-Object {
17 | if ($_.FullName -notlike '*\DSCResource.Tests\*') {
18 | $testCoverageFiles += $_.FullName
19 | }
20 | }
21 |
22 | $testResultSettings = @{ }
23 | if ([String]::IsNullOrEmpty($TestResultsFile) -eq $false) {
24 | $testResultSettings.Add('OutputFormat', 'NUnitXml' )
25 | $testResultSettings.Add('OutputFile', $TestResultsFile)
26 | }
27 |
28 | Import-Module "$repoDir\WebAdministrationDsc.psd1"
29 |
30 | $versionsToTest = (Get-ChildItem (Join-Path $repoDir '\Tests\Unit\')).Name
31 |
32 | $testsToRun = @()
33 | $versionsToTest | ForEach-Object {
34 | $testsToRun += @(@{
35 | 'Path' = "$repoDir\Tests\Unit\$_"
36 | })
37 | }
38 |
39 | if ($PSBoundParameters.ContainsKey('DscTestsPath') -eq $true) {
40 | $testsToRun += @{
41 | 'Path' = $DscTestsPath
42 | }
43 | }
44 |
45 | $results = Invoke-Pester -Script $testsToRun -CodeCoverage $testCoverageFiles -PassThru @testResultSettings
46 |
47 | return $results
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "powershell.codeFormatting.openBraceOnSameLine": false,
3 | "powershell.codeFormatting.newLineAfterOpenBrace": true,
4 | "powershell.codeFormatting.newLineAfterCloseBrace": true,
5 | "powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
6 | "powershell.codeFormatting.whitespaceBeforeOpenParen": true,
7 | "powershell.codeFormatting.whitespaceAroundOperator": true,
8 | "powershell.codeFormatting.whitespaceAfterSeparator": true,
9 | "powershell.codeFormatting.ignoreOneLineBlock": false,
10 | "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
11 | "powershell.codeFormatting.preset": "Custom",
12 | "powershell.codeFormatting.alignPropertyValuePairs": true,
13 | "powershell.developer.bundledModulesPath": "${cwd}/output/RequiredModules",
14 | "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1",
15 | "powershell.scriptAnalysis.enable": true,
16 | "files.trimTrailingWhitespace": true,
17 | "files.trimFinalNewlines": true,
18 | "files.insertFinalNewline": true,
19 | "files.associations": {
20 | "*.ps1xml": "xml"
21 | },
22 | "cSpell.words": [
23 | "COMPANYNAME",
24 | "ICONURI",
25 | "LICENSEURI",
26 | "PROJECTURI",
27 | "RELEASENOTES",
28 | "buildhelpers",
29 | "endregion",
30 | "gitversion",
31 | "icontains",
32 | "keepachangelog",
33 | "notin",
34 | "pscmdlet",
35 | "steppable"
36 | ],
37 | "[markdown]": {
38 | "files.trimTrailingWhitespace": false,
39 | "files.encoding": "utf8"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisFeatureDelegation/Sample_IisFeatureDelegation_IisModulePathFormat.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | This example will install the IIS Windows Feature and unlocks the IIS configuration
4 | sections specified by the Filter setting. This example uses the IIS Module Path format
5 | for the 'Path' setting.
6 | #>
7 | configuration Example
8 | {
9 | param
10 | (
11 | [Parameter()]
12 | [string[]]
13 | $NodeName = 'localhost'
14 | )
15 |
16 | Import-DscResource -Module WebAdministrationDsc
17 | Import-DscResource -Module PSDesiredStateConfiguration
18 |
19 | Node $NodeName
20 | {
21 | # Install the IIS role
22 | WindowsFeature IIS
23 | {
24 | Ensure = 'Present'
25 | Name = 'Web-Server'
26 | }
27 |
28 | # Allow Write access to some section that normally don't have it.
29 | IisFeatureDelegation serverRuntime
30 | {
31 | Filter = '/system.webserver/serverRuntime'
32 | OverrideMode = 'Allow'
33 | Path = 'IIS:\Sites\Default Web Site'
34 | }
35 |
36 | IisFeatureDelegation anonymousAuthentication
37 | {
38 | Filter = '/system.webserver/security/authentication/anonymousAuthentication'
39 | OverrideMode = 'Allow'
40 | Path = 'IIS:\Sites\Default Web Site'
41 | }
42 |
43 | IisFeatureDelegation sessionState
44 | {
45 | Filter = '/system.web/sessionState'
46 | OverrideMode = 'Allow'
47 | Path = 'IIS:\Sites\Default Web Site'
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisFeatureDelegation/Sample_IisFeatureDelegation_IisConfigurationPathFormat.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | This example will install the IIS Windows Feature and unlocks the IIS configuration
4 | sections specified by the Filter setting. This example uses the IIS Configuration Path format
5 | for the 'Path' setting.
6 | #>
7 | configuration Example
8 | {
9 | param
10 | (
11 | [Parameter()]
12 | [string[]]
13 | $NodeName = 'localhost'
14 | )
15 |
16 | Import-DscResource -Module WebAdministrationDsc
17 | Import-DscResource -Module PSDesiredStateConfiguration
18 |
19 | Node $NodeName
20 | {
21 | # Install the IIS role
22 | WindowsFeature IIS
23 | {
24 | Ensure = 'Present'
25 | Name = 'Web-Server'
26 | }
27 |
28 | # Allow Write access to some section that normally don't have it.
29 | IisFeatureDelegation serverRuntime
30 | {
31 | Filter = '/system.webserver/serverRuntime'
32 | OverrideMode = 'Allow'
33 | Path = 'MACHINE/WEBROOT/APPHOST'
34 | }
35 |
36 | IisFeatureDelegation anonymousAuthentication
37 | {
38 | Filter = '/system.webserver/security/authentication/anonymousAuthentication'
39 | OverrideMode = 'Allow'
40 | Path = 'MACHINE/WEBROOT/APPHOST'
41 | }
42 |
43 | IisFeatureDelegation sessionState
44 | {
45 | Filter = '/system.web/sessionState'
46 | OverrideMode = 'Allow'
47 | Path = 'MACHINE/WEBROOT/APPHOST'
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebApplication.config.ps1:
--------------------------------------------------------------------------------
1 | #requires -Version 4
2 | configuration DSC_WebApplication_Present
3 | {
4 | Import-DscResource -ModuleName WebAdministrationDsc
5 |
6 | Node $AllNodes.NodeName
7 | {
8 | WebApplication WebApplication
9 | {
10 | Website = $Node.Website
11 | Ensure = 'Present'
12 | Name = $Node.WebApplication
13 | PhysicalPath = $Node.PhysicalPath
14 | WebAppPool = $Node.ApplicationPool
15 | ApplicationType = $Node.ApplicationType
16 | AuthenticationInfo = `
17 | DSC_WebApplicationAuthenticationInformation
18 | {
19 | Anonymous = $Node.AuthenticationInfoAnonymous
20 | Basic = $Node.AuthenticationInfoBasic
21 | Digest = $Node.AuthenticationInfoDigest
22 | Windows = $Node.AuthenticationInfoWindows
23 | }
24 | PreloadEnabled = $Node.PreloadEnabled
25 | ServiceAutoStartEnabled = $Node.ServiceAutoStartEnabled
26 | ServiceAutoStartProvider = $Node.ServiceAutoStartProvider
27 | SslFlags = $Node.WebApplicationSslFlags
28 | EnabledProtocols = $Node.EnabledProtocols
29 | }
30 | }
31 | }
32 |
33 | configuration DSC_WebApplication_Absent
34 | {
35 | Import-DscResource -ModuleName WebAdministrationDsc
36 |
37 | Node $AllNodes.NodeName
38 | {
39 | WebApplication WebApplication
40 | {
41 | Website = $Node.Website
42 | Ensure = 'Absent'
43 | Name = $Node.WebApplication
44 | PhysicalPath = $Node.PhysicalPath
45 | WebAppPool = $Node.ApplicationPool
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/.vscode/analyzersettings.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | CustomRulePath = '.\output\RequiredModules\DscResource.AnalyzerRules'
3 | IncludeDefaultRules = $true
4 | IncludeRules = @(
5 | # DSC Resource Kit style guideline rules.
6 | 'PSAvoidDefaultValueForMandatoryParameter',
7 | 'PSAvoidDefaultValueSwitchParameter',
8 | 'PSAvoidInvokingEmptyMembers',
9 | 'PSAvoidNullOrEmptyHelpMessageAttribute',
10 | 'PSAvoidUsingCmdletAliases',
11 | 'PSAvoidUsingComputerNameHardcoded',
12 | 'PSAvoidUsingDeprecatedManifestFields',
13 | 'PSAvoidUsingEmptyCatchBlock',
14 | 'PSAvoidUsingInvokeExpression',
15 | 'PSAvoidUsingPositionalParameters',
16 | 'PSAvoidShouldContinueWithoutForce',
17 | 'PSAvoidUsingWMICmdlet',
18 | 'PSAvoidUsingWriteHost',
19 | 'PSDSCReturnCorrectTypesForDSCFunctions',
20 | 'PSDSCStandardDSCFunctionsInResource',
21 | 'PSDSCUseIdenticalMandatoryParametersForDSC',
22 | 'PSDSCUseIdenticalParametersForDSC',
23 | 'PSMisleadingBacktick',
24 | 'PSMissingModuleManifestField',
25 | 'PSPossibleIncorrectComparisonWithNull',
26 | 'PSProvideCommentHelp',
27 | 'PSReservedCmdletChar',
28 | 'PSReservedParams',
29 | 'PSUseApprovedVerbs',
30 | 'PSUseCmdletCorrectly',
31 | 'PSUseOutputTypeCorrectly',
32 | 'PSAvoidGlobalVars',
33 | 'PSAvoidUsingConvertToSecureStringWithPlainText',
34 | 'PSAvoidUsingPlainTextForPassword',
35 | 'PSAvoidUsingUsernameAndPasswordParams',
36 | 'PSDSCUseVerboseMessageInDSCResource',
37 | 'PSShouldProcess',
38 | 'PSUseDeclaredVarsMoreThanAssignments',
39 | 'PSUsePSCredentialType',
40 |
41 | 'Measure-*'
42 | )
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebAppPoolDefaults.config.ps1:
--------------------------------------------------------------------------------
1 | [string] $constPsPath = 'MACHINE/WEBROOT/APPHOST'
2 | [string] $constAPDFilter = 'system.applicationHost/applicationPools/applicationPoolDefaults'
3 | [string] $constSiteFilter = 'system.applicationHost/sites/'
4 |
5 | [string] $originalValue = (Get-WebConfigurationProperty -pspath $constPsPath -filter $constAPDFilter -name managedRuntimeVersion).Value
6 |
7 | configuration DSC_WebAppPoolDefaults_Config
8 | {
9 | Import-DscResource -ModuleName WebAdministrationDsc
10 |
11 | WebAppPoolDefaults PoolDefaults
12 | {
13 | IsSingleInstance = 'Yes'
14 | ManagedRuntimeVersion = $originalValue
15 | }
16 | }
17 |
18 | configuration DSC_WebAppPoolDefaults_ManagedRuntimeVersion
19 | {
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | WebAppPoolDefaults PoolDefaults
23 | {
24 | IsSingleInstance = 'Yes'
25 | ManagedRuntimeVersion = $env:PesterManagedRuntimeVersion
26 | }
27 | }
28 |
29 | configuration DSC_WebAppPoolDefaults_AppPoolIdentityType
30 | {
31 | Import-DscResource -ModuleName WebAdministrationDsc
32 |
33 | WebAppPoolDefaults PoolDefaults
34 | {
35 | IsSingleInstance = 'Yes'
36 | IdentityType = $env:PesterApplicationPoolIdentity
37 | }
38 | }
39 |
40 | configuration DSC_WebAppPoolDefaults_LogFormat
41 | {
42 | Import-DscResource -ModuleName WebAdministrationDsc
43 |
44 | WebSiteDefaults LogFormat
45 | {
46 | IsSingleInstance = 'Yes'
47 | LogFormat = $env:PesterLogFormat
48 | }
49 | }
50 |
51 | configuration DSC_WebAppPoolDefaults_DefaultPool
52 | {
53 | Import-DscResource -ModuleName WebAdministrationDsc
54 |
55 | WebSiteDefaults DefaultPool
56 | {
57 | IsSingleInstance = 'Yes'
58 | DefaultApplicationPool = $env:PesterDefaultPool
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Resource_proposal.yml:
--------------------------------------------------------------------------------
1 | name: New resource proposal
2 | description: If you have a new resource proposal that you think should be added to this resource module.
3 | title: "NewResourceName: New resource proposal"
4 | labels: []
5 | assignees: []
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | Please replace `NewResourceName` in the issue title (above) with your proposed resource name.
11 |
12 | Thank you for contributing and making this resource module better!
13 | - type: textarea
14 | id: description
15 | attributes:
16 | label: Resource proposal
17 | description: Provide information how this resource will/should work and how it will help users.
18 | validations:
19 | required: true
20 | - type: textarea
21 | id: proposedProperties
22 | attributes:
23 | label: Proposed properties
24 | description: |
25 | List all the proposed properties that the resource should have (key, required, write, and/or read). For each property provide a detailed description, the data type, if a default value should be used, and if the property is limited to a set of values.
26 | value: |
27 | Property | Type qualifier | Data type | Description | Default value | Allowed values
28 | --- | --- | --- | --- | --- | ---
29 | PropertyName | Key | String | Detailed description | None | None
30 | validations:
31 | required: true
32 | - type: textarea
33 | id: considerations
34 | attributes:
35 | label: Special considerations or limitations
36 | description: |
37 | Provide any considerations or limitations you can think of that a contributor should take in account when coding the proposed resource, and or what limitations a user will encounter or should consider when using the proposed resource.
38 | validations:
39 | required: true
40 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebConfigProperty.config.ps1:
--------------------------------------------------------------------------------
1 | Configuration DSC_WebConfigProperty_Add
2 | {
3 | Import-DscResource -ModuleName WebAdministrationDsc
4 |
5 | node localhost
6 | {
7 | WebConfigProperty IntegrationTest
8 | {
9 | WebsitePath = $Node.WebsitePath
10 | Filter = $Node.Filter
11 | PropertyName = $Node.PropertyName
12 | Value = $Node.AddValue
13 | Ensure = 'Present'
14 | }
15 | }
16 | }
17 |
18 | Configuration DSC_WebConfigProperty_Update
19 | {
20 | Import-DscResource -ModuleName WebAdministrationDsc
21 |
22 | node localhost
23 | {
24 | WebConfigProperty IntegrationTest
25 | {
26 | WebsitePath = $Node.WebsitePath
27 | Filter = $Node.Filter
28 | PropertyName = $Node.PropertyName
29 | Value = $Node.UpdateValue
30 | Ensure = 'Present'
31 | }
32 | }
33 | }
34 |
35 | Configuration DSC_WebConfigProperty_Integer
36 | {
37 | Import-DscResource -ModuleName WebAdministrationDsc
38 |
39 | node localhost
40 | {
41 | WebConfigProperty IntegrationTest
42 | {
43 | WebsitePath = $Node.WebsitePath
44 | Filter = $Node.IntegerFilter
45 | PropertyName = $Node.IntergerPropertyName
46 | Value = $Node.IntegerValue
47 | Ensure = 'Present'
48 | }
49 | }
50 | }
51 |
52 | Configuration DSC_WebConfigProperty_Remove
53 | {
54 | Import-DscResource -ModuleName WebAdministrationDsc
55 |
56 | node localhost
57 | {
58 | WebConfigProperty IntegrationTest
59 | {
60 | WebsitePath = $Node.WebsitePath
61 | Filter = $Node.Filter
62 | PropertyName = $Node.PropertyName
63 | Ensure = 'Absent'
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebAppPool/en-US/DSC_WebAppPool.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | ErrorAppCmdNonZeroExitCode = AppCmd.exe has exited with error code "{0}".
4 | VerboseAppPoolFound = Application pool "{0}" was found.
5 | VerboseAppPoolNotFound = Application pool "{0}" was not found.
6 | VerboseEnsureNotInDesiredState = The "Ensure" state of application pool "{0}" does not match the desired state.
7 | VerbosePropertyNotInDesiredState = The "{0}" property of application pool "{1}" does not match the desired state.
8 | VerboseCredentialToBeCleared = Custom account credentials of application pool "{0}" need to be cleared because the "identityType" property is not set to "SpecificUser".
9 | VerboseCredentialToBeIgnored = The "Credential" property is only valid when the "identityType" property is set to "SpecificUser".
10 | VerboseResourceInDesiredState = The target resource is already in the desired state. No action is required.
11 | VerboseResourceNotInDesiredState = The target resource is not in the desired state.
12 | VerboseNewAppPool = Creating application pool "{0}".
13 | VerboseRemoveAppPool = Removing application pool "{0}".
14 | VerboseStartAppPool = Starting application pool "{0}".
15 | VerboseStopAppPool = Stopping application pool "{0}".
16 | VerboseSetProperty = Setting the "{0}" property of application pool "{1}".
17 | VerboseClearCredential = Clearing custom account credentials of application pool "{0}" because the "identityType" property is not set to "SpecificUser".
18 | VerboseRestartScheduleValueAdd = Adding value "{0}" to the "restartSchedule" collection of application pool "{1}".
19 | VerboseRestartScheduleValueRemove = Removing value "{0}" from the "restartSchedule" collection of application pool "{1}".
20 | '@
21 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisLogging/en-US/DSC_IisLogging.strings.psd1:
--------------------------------------------------------------------------------
1 | ConvertFrom-StringData @'
2 | VerboseGetTargetResult = Get-TargetResource has been run.
3 | VerboseSetTargetUpdateLogPath = LogPath is not in the desired state and will be updated.
4 | VerboseSetTargetUpdateLogFlags = LogFlags do not match and will be updated.
5 | VerboseSetTargetUpdateLogPeriod = LogPeriod is not in the desired state and will be updated.
6 | VerboseSetTargetUpdateLogTruncateSize = TruncateSize is not in the desired state and will be updated.
7 | VerboseSetTargetUpdateLoglocalTimeRollover = LoglocalTimeRollover is not in the desired state and will be updated.
8 | VerboseSetTargetUpdateLogFormat = LogFormat is not in the desired state and will be updated
9 | VerboseSetTargetUpdateLogTargetW3C = LogTargetW3C is not in the desired state and will be updated
10 | VerboseSetTargetUpdateLogCustomFields = LogCustomFields is not in the desired state and will be updated.
11 | VerboseTestTargetUpdateLogCustomFields = LogCustomFields is not in the desired state and will be updated.
12 | VerboseTestTargetFalseLogPath = LogPath does match desired state.
13 | VerboseTestTargetFalseLogFlags = LogFlags does not match desired state.
14 | VerboseTestTargetFalseLogPeriod = LogPeriod does not match desired state.
15 | VerboseTestTargetFalseLogTruncateSize = LogTruncateSize does not match desired state.
16 | VerboseTestTargetFalseLoglocalTimeRollover = LoglocalTimeRollover does not match desired state.
17 | VerboseTestTargetFalseLogFormat = LogFormat does not match desired state.
18 | VerboseTestTargetFalseLogTargetW3C = LogTargetW3C does not match desired state.
19 | WarningLogPeriod = LogTruncateSize has is an input as will overwrite this desired state.
20 | WarningIncorrectLogFormat = LogFormat is not W3C, as a result LogFlags will not be used.
21 | '@
22 |
--------------------------------------------------------------------------------
/source/WikiSource/Home.md:
--------------------------------------------------------------------------------
1 | # Welcome to the WebAdministrationDsc wiki
2 |
3 | *WebAdministrationDsc v#.#.#*
4 |
5 | Here you will find all the information you need to make use of the WebAdministrationDsc
6 | DSC resources in the latest release. This includes details of the resources
7 | that are available, current capabilities and known issues, and information
8 | to help plan a DSC based implementation of WebAdministrationDsc.
9 |
10 | Please leave comments, feature requests, and bug reports for this module in
11 | the [issues section](https://github.com/dsccommunity/WebAdministrationDsc/issues)
12 | for this repository.
13 |
14 | ## Deprecated resources
15 |
16 | The documentation, examples, unit test, and integration tests have been removed
17 | for these deprecated resources. These resources will be removed
18 | in a future release.
19 |
20 | *No deprecated resources*.
21 |
22 | ## Getting started
23 |
24 | To get started either:
25 |
26 | - Install from the PowerShell Gallery using PowerShellGet by running the
27 | following command:
28 |
29 | ```powershell
30 | Install-Module -Name WebAdministrationDsc -Repository PSGallery
31 | ```
32 |
33 | - Download WebAdministrationDsc from the [PowerShell Gallery](http://www.powershellgallery.com/packages/WebAdministrationDsc/)
34 | and then unzip it to one of your PowerShell modules folders (such as
35 | `$env:ProgramFiles\WindowsPowerShell\Modules`).
36 |
37 | To confirm installation, run the below command and ensure you see the WebAdministrationDsc
38 | DSC resources available:
39 |
40 | ```powershell
41 | Get-DscResource -Module WebAdministrationDsc
42 | ```
43 |
44 | ## Prerequisites
45 |
46 | ### Powershell
47 |
48 | The minimum Windows Management Framework (PowerShell) version required is 5.0
49 | or higher, which ships with Windows 10 or Windows Server 2016,
50 | but can also be installed on Windows 7 SP1, Windows 8.1, Windows Server 2012,
51 | and Windows Server 2012 R2.
52 |
53 | ## Change log
54 |
55 | A full list of changes in each version can be found in the [change log](https://github.com/dsccommunity/WebAdministrationDsc/blob/main/CHANGELOG.md).
56 |
--------------------------------------------------------------------------------
/source/Modules/WebAdministrationDsc.Common/WebAdministrationDsc.Common.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | # Script module or binary module file associated with this manifest.
3 | RootModule = 'WebAdministrationDsc.Common.psm1'
4 |
5 | # Version number of this module.
6 | ModuleVersion = '1.0.0'
7 |
8 | # ID used to uniquely identify this module
9 | GUID = 'e32b82a0-ef75-4a64-9a98-e261758e3b71'
10 |
11 | # Author of this module
12 | Author = 'DSC Community'
13 |
14 | # Company or vendor of this module
15 | CompanyName = 'DSC Community'
16 |
17 | # Copyright statement for this module
18 | Copyright = 'Copyright the DSC Community contributors. All rights reserved.'
19 |
20 | # Description of the functionality provided by this module
21 | Description = 'Functions used by the DSC resources in WebAdministrationDsc.'
22 |
23 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
24 | FunctionsToExport = @(
25 | 'Start-ProcessWithTimeout'
26 | 'Test-DscPropertyState'
27 | 'New-CimCredentialInstance'
28 | 'New-TerminatingError'
29 | 'Get-WebConfigurationPropertyValue'
30 | )
31 |
32 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
33 | CmdletsToExport = @()
34 |
35 | # Variables to export from this module
36 | VariablesToExport = @()
37 |
38 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
39 | AliasesToExport = @()
40 |
41 |
42 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
43 | PrivateData = @{
44 |
45 | PSData = @{
46 |
47 | } # End of PSData hashtable
48 |
49 | } # End of PrivateData hashtable
50 | }
51 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplication/DSC_WebApplication.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0.0"), FriendlyName("WebApplication")]
2 | class DSC_WebApplication : OMI_BaseResource
3 | {
4 | [Key, Description("Name of website with which web application is associated")] String Website;
5 | [Key, Description("Name of web application")] String Name;
6 | [Required, Description("Web application pool for the web application")] String WebAppPool;
7 | [Required, Description("Physical path for the web application directory")] String PhysicalPath;
8 | [Write, Description("Whether web application should be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
9 | [Write, Description("SSLFlags for the application"), ValueMap{"","Ssl","SslNegotiateCert","SslRequireCert","Ssl128"},Values{"","Ssl","SslNegotiateCert","SslRequireCert","Ssl128"}] String SslFlags[];
10 | [write, EmbeddedInstance("DSC_WebApplicationAuthenticationInformation"), Description("Hashtable containing authentication information (Anonymous, Basic, Digest, Windows)")] String AuthenticationInfo;
11 | [Write, Description ("Allows a Application to automatically start without a request")] Boolean PreloadEnabled;
12 | [Write, Description ("Enables Autostart on an Application.")] Boolean ServiceAutoStartEnabled;
13 | [Write, Description ("Adds a AutostartProvider")] String ServiceAutoStartProvider;
14 | [Write, Description ("Adds a AutostartProvider ApplicationType")] String ApplicationType;
15 | [Write, Description ("Adds EnabledProtocols on an Application"), ValueMap{"http","https","net.tcp","net.msmq","net.pipe"},Values{"http","https","net.tcp","net.msmq","net.pipe"}] String EnabledProtocols[];
16 | };
17 |
18 | [ClassVersion("1.0.0")]
19 | class DSC_WebApplicationAuthenticationInformation
20 | {
21 | [Write, Description ("Enable anonymous authentication")] Boolean Anonymous;
22 | [Write, Description ("Enable basic authentication")] Boolean Basic;
23 | [Write, Description ("Enable digest authentication")] Boolean Digest;
24 | [Write, Description ("Enable Windows authentication")] Boolean Windows;
25 | };
26 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebSite.config.psd1:
--------------------------------------------------------------------------------
1 | #requires -Version 1
2 |
3 | @{
4 | AllNodes = @(
5 | @{
6 | NodeName = 'LocalHost'
7 | PSDscAllowPlainTextPassword = $true
8 | Website = 'Website'
9 | ApplicationType = 'WebsiteApplicationType'
10 | ApplicationPool = 'DefaultAppPool'
11 | DefaultPage = 'Website.html'
12 | EnabledProtocols = 'http'
13 | SiteId = 1234
14 | PhysicalPath = 'C:\inetpub\wwwroot'
15 | PreloadEnabled = $true
16 | ServiceAutoStartEnabled = $true
17 | ServiceAutoStartProvider = 'WebsiteServiceAutoStartProvider'
18 | AuthenticationInfoAnonymous = $true
19 | AuthenticationInfoBasic = $false
20 | AuthenticationInfoDigest = $false
21 | AuthenticationInfoWindows = $true
22 | HTTPProtocol = 'http'
23 | HTTPPort = '80'
24 | HTTP1Hostname = 'http1.website'
25 | HTTP2Hostname = 'http2.website'
26 | HTTPSProtocol = 'https'
27 | HTTPSPort = '443'
28 | HTTPSPort2 = '8444'
29 | HTTPSHostname = 'https.website'
30 | CertificateStoreName = 'My'
31 | SslFlags = '1'
32 | LogFieldName1 = 'CustomField1'
33 | SourceName1 = 'Accept-Encoding'
34 | SourceType1 = 'RequestHeader'
35 | LogFieldName2 = 'CustomField2'
36 | SourceName2 = 'Warning'
37 | SourceType2 = 'ResponseHeader'
38 | LogTargetW3C = 'ETW'
39 | LogFormat = 'W3C'
40 | Logflags1 = @('Date','Time','ClientIP','UserName','ServerIP')
41 | Logflags2 = @('Date','Time','ClientIP','ServerIP','UserAgent')
42 | }
43 | )
44 | }
45 |
--------------------------------------------------------------------------------
/source/WebAdministrationDsc.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | # Version number of this module.
3 | moduleVersion = '0.0.1'
4 |
5 | # ID used to uniquely identify this module
6 | GUID = 'b3239f27-d7d3-4ae6-a5d2-d9a1c97d6ae4'
7 |
8 | # Author of this module
9 | Author = 'DSC Community'
10 |
11 | # Company or vendor of this module
12 | CompanyName = 'DSC Community'
13 |
14 | # Copyright statement for this module
15 | Copyright = 'Copyright the DSC Community contributors. All rights reserved.'
16 |
17 | # Description of the functionality provided by this module
18 | Description = 'Module with DSC Resources for Web Administration'
19 |
20 | # Minimum version of the Windows PowerShell engine required by this module
21 | PowerShellVersion = '4.0'
22 |
23 | # Minimum version of the common language runtime (CLR) required by this module
24 | CLRVersion = '4.0'
25 |
26 | # Functions to export from this module
27 | FunctionsToExport = @()
28 |
29 | # Cmdlets to export from this module
30 | CmdletsToExport = @()
31 |
32 | # Variables to export from this module
33 | VariablesToExport = @()
34 |
35 | # Aliases to export from this module
36 | AliasesToExport = @()
37 |
38 | DscResourcesToExport = @()
39 |
40 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
41 | PrivateData = @{
42 |
43 | PSData = @{
44 | Prerelease = ''
45 |
46 | # Tags applied to this module. These help with module discovery in online galleries.
47 | Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource')
48 |
49 | # A URL to the license for this module.
50 | LicenseUri = 'https://github.com/dsccommunity/WebAdministrationDsc/blob/main/LICENSE'
51 |
52 | # A URL to the main website for this project.
53 | ProjectUri = 'https://github.com/dsccommunity/WebAdministrationDsc'
54 |
55 | # A URL to an icon representing this module.
56 | IconUri = 'https://dsccommunity.org/images/DSC_Logo_300p.png'
57 |
58 | # ReleaseNotes of this module
59 | ReleaseNotes = ''
60 |
61 | } # End of PSData hashtable
62 |
63 | } # End of PrivateData hashtable
64 | }
65 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplicationHandler/DSC_WebApplicationHandler.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0.0"), FriendlyName("WebApplicationHandler")]
2 | class DSC_WebApplicationHandler : OMI_BaseResource
3 | {
4 | [Key, Description("Specifies the name of the new request handler.")] String Name;
5 | [Write, Description("Indicates if the application handler exists. Set this property to `Absent` to ensure that the application handler does not exist. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
6 | [Write, Description("Specifies the physical path to the handler. This parameter applies to native modules only.")] String physicalHandlerPath;
7 | [Write, Description("Specifies the HTTP verbs that are handled by the new handler.")] String Verb;
8 | [Required, Write, Description("Specifies an IIS configuration path.")] String Path[];
9 | [Write, Description("Specifies the managed type of the new module. This parameter applies to managed modules only.")] String Type;
10 | [Write, Description("Specifies the modules used for the handler.")] String Modules;
11 | [Write, Description("Specifies the script processor that runs for the module.")] String ScriptProcessor;
12 | [Write, Description("Specifies preconditions for the new handler.")] String PreCondition;
13 | [Write, Description("Specifies the user rights that are required for the new handler."), ValueMap{"None","Read","Write","Script","Execute"}, Values{"None","Read","Write","Script","Execute"}] String RequireAccess;
14 | [Write, Description("Specifies the resource type this handler runs.")] String ResourceType;
15 | [Write, Description("Specifies whether the handler processes full path information in a URI, such as contoso/marketing/imageGallery.aspx. If the value is true, the handler processes the full path, contoso/marketing/imageGallery. If the value is false, the handler processes only the last section of the path, /imageGallery.")] Boolean AllowPathInfo;
16 | [Write, Description("Specifies the maximum size, in bytes, of the response buffer for a request handler runs.")] uint32 ResponseBufferLimit;
17 | [Write, Description("Specifies The location of the configuration setting. Location tags are frequently used for configuration settings that must be set more precisely than per application or per virtual directory.")] String Location;
18 | };
19 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisLogging/DSC_IisLogging.schema.mof:
--------------------------------------------------------------------------------
1 | [ClassVersion("1.0.0"), FriendlyName("IisLogging")]
2 | class DSC_IisLogging : OMI_BaseResource
3 | {
4 | [Key, Description ("The directory to be used for logfiles")] String LogPath;
5 | [Write, Description ("The W3C logging fields"), ValueMap{"Date","Time","ClientIP","UserName","SiteName","ComputerName","ServerIP","Method","UriStem","UriQuery","HttpStatus","Win32Status","BytesSent","BytesRecv","TimeTaken","ServerPort","UserAgent","Cookie","Referer","ProtocolVersion","Host","HttpSubStatus"}, Values{"Date","Time","ClientIP","UserName","SiteName","ComputerName","ServerIP","Method","UriStem","UriQuery","HttpStatus","Win32Status","BytesSent","BytesRecv","TimeTaken","ServerPort","UserAgent","Cookie","Referer","ProtocolVersion","Host","HttpSubStatus"}] String LogFlags[];
6 | [Write, Description ("How often the log file should rollover"), ValueMap{"Hourly","Daily","Weekly","Monthly","MaxSize"}, Values{"Hourly","Daily","Weekly","Monthly","MaxSize"}] String LogPeriod;
7 | [Write, Description ("How large the file should be before it is truncated")] String LogTruncateSize;
8 | [Write, Description ("Use the localtime for file naming and rollover")] Boolean LoglocalTimeRollover;
9 | [Write, Description ("Format of the Logfiles. Only W3C supports LogFlags"), ValueMap{"IIS","W3C","NCSA"}, Values{"IIS","W3C","NCSA"}] String LogFormat;
10 | [Write, Description ("Specifies whether IIS will use Event Tracing or file logging"), ValueMap{"File","ETW","File,ETW"}, Values{"File","ETW","File,ETW"}] String LogTargetW3C;
11 | [Write, EmbeddedInstance("DSC_LogCustomField"), Description("Custom logging field information in the form of an array of embedded instances of DSC_LogCustomField CIM class")] String LogCustomFields[];
12 | };
13 |
14 | [ClassVersion("1.0.0")]
15 | class DSC_LogCustomField
16 | {
17 | [Required, Description("Name for the custom field")] String LogFieldName;
18 | [Required, Description("Name for the source type")] String SourceName;
19 | [Required, Description("Specify the source type"), ValueMap{"RequestHeader","ResponseHeader","ServerVariable"},Values{"RequestHeader","ResponseHeader","ServerVariable"}] String SourceType;
20 | [Write, Description("Indicates if the custom log field should be present or absent. Defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
21 | };
22 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebVirtualDirectory/Sample_WebVirtualDirectory_NewVirtualDirectory.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Create a new web virtual directory on the Default Web Site
4 | .DESCRIPTION
5 | This example shows how to use the WebVirtualDirectory DSC resource to create a new virtual
6 | directory on the Default Web Site.
7 | #>
8 | configuration Sample_WebVirtualDirectory_NewVirtualDirectory
9 | {
10 | param
11 | (
12 | # Target nodes to apply the configuration
13 | [System.String[]]
14 | $NodeName = 'localhost',
15 |
16 | # Name of virtual directory to create
17 | [Parameter(Mandatory)]
18 | [ValidateNotNullOrEmpty()]
19 | [System.String]
20 | $VirtualDirectoryName,
21 |
22 | # Physical path of the virtual directory
23 | [Parameter(Mandatory)]
24 | [ValidateNotNullOrEmpty()]
25 | [System.String]
26 | $PhysicalPath
27 | )
28 |
29 | # Import the module that defines custom resources
30 | Import-DscResource -Module PSDesiredStateConfiguration
31 | Import-DscResource -Module WebAdministrationDsc
32 |
33 | Node $NodeName
34 | {
35 | # Install the IIS role
36 | WindowsFeature IIS
37 | {
38 | Ensure = 'Present'
39 | Name = 'Web-Server'
40 | }
41 |
42 | # Start the default website
43 | WebSite DefaultSite
44 | {
45 | Ensure = 'Present'
46 | Name = 'Default Web Site'
47 | State = 'Started'
48 | PhysicalPath = 'C:\inetpub\wwwroot'
49 | DependsOn = '[WindowsFeature]IIS'
50 | }
51 |
52 | # Copy the virtual directory content
53 | File VirtualDirectoryContent
54 | {
55 | Ensure = 'Present'
56 | DestinationPath = $PhysicalPath
57 | Type = 'Directory'
58 | DependsOn = '[WindowsFeature]IIS'
59 | }
60 |
61 | # Create the new virtual directory
62 | WebVirtualDirectory NewVirtualDirectory
63 | {
64 | Ensure = 'Present'
65 | Website = "Default Web Site"
66 | WebApplication = ''
67 | Name = $VirtualDirectoryName
68 | PhysicalPath = $PhysicalPath
69 | DependsOn = '[File]VirtualDirectoryContent'
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/source/Examples/Resources/IisMimeTypeMapping/Sample_IisMimeTypeMapping_RemoveVideo.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_IisMimeTypeMapping_RemoveVideo
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost',
7 |
8 | # Name of the website to modify
9 | [Parameter(Mandatory)]
10 | [ValidateNotNullOrEmpty()]
11 | [String] $WebSiteName
12 | )
13 |
14 | # Import the module that defines custom resources
15 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
16 |
17 | Node $NodeName
18 | {
19 | # Install the IIS role
20 | WindowsFeature IIS
21 | {
22 | Ensure = 'Present'
23 | Name = 'Web-Server'
24 | }
25 |
26 | # Remove a bunch of Video Mime Type mappings
27 | IisMimeTypeMapping Mp2
28 | {
29 | Ensure = 'Absent'
30 | Extension = '.mp2'
31 | MimeType = 'video/mpeg'
32 | ConfigurationPath = "IIS:\sites\$WebSiteName"
33 | DependsOn = '[WindowsFeature]IIS'
34 | }
35 |
36 | IisMimeTypeMapping Mp4
37 | {
38 | Ensure = 'Absent'
39 | Extension = '.mp4'
40 | MimeType = 'video/mp4'
41 | ConfigurationPath = "IIS:\sites\$WebSiteName"
42 | DependsOn = '[WindowsFeature]IIS'
43 | }
44 |
45 | IisMimeTypeMapping Mpeg
46 | {
47 | Ensure = 'Absent'
48 | Extension = '.mpeg'
49 | MimeType = 'video/mpeg'
50 | ConfigurationPath = "IIS:\sites\$WebSiteName"
51 | DependsOn = '[WindowsFeature]IIS'
52 | }
53 |
54 | # we only allow the mpg and mpe Video extensions on our server
55 | IisMimeTypeMapping Mpg
56 | {
57 | Ensure = 'Present'
58 | Extension = '.mpg'
59 | MimeType = 'video/mpeg'
60 | ConfigurationPath = "IIS:\sites\$WebSiteName"
61 | DependsOn = '[WindowsFeature]IIS'
62 | }
63 |
64 | IisMimeTypeMapping Mpe
65 | {
66 | # Ensure defaults to 'Present'
67 | Extension = '.mpe'
68 | MimeType = 'video/mpeg'
69 | ConfigurationPath = "IIS:\sites\$WebSiteName"
70 | DependsOn = '[WindowsFeature]IIS'
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
12 |
13 | #### Pull Request (PR) description
14 |
15 |
19 |
20 | #### This Pull Request (PR) fixes the following issues
21 |
22 |
30 |
31 | #### Task list
32 |
33 |
40 |
41 | - [ ] Added an entry to the change log under the Unreleased section of the file CHANGELOG.md.
42 | Entry should say what was changed and how that affects users (if applicable), and
43 | reference the issue being resolved (if applicable).
44 | - [ ] Resource documentation added/updated in README.md.
45 | - [ ] Resource parameter descriptions added/updated in README.md, schema.mof and comment-based
46 | help.
47 | - [ ] Comment-based help added/updated.
48 | - [ ] Localization strings added/updated in all localization files as appropriate.
49 | - [ ] Examples appropriately added/updated.
50 | - [ ] Unit tests added/updated. See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines).
51 | - [ ] Integration tests added/updated (where possible). See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines).
52 | - [ ] New/changed code adheres to [DSC Community Style Guidelines](https://dsccommunity.org/styleguidelines).
53 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_IISMimeTypeMapping.config.ps1:
--------------------------------------------------------------------------------
1 | configuration DSC_IisMimeTypeMapping_AddMimeType
2 | {
3 | Import-DscResource -ModuleName WebAdministrationDsc
4 |
5 | IisMimeTypeMapping AddMimeType2
6 | {
7 | ConfigurationPath = ''
8 | Extension = $ConfigurationData.NonNodeData.FileExtension
9 | MimeType = $ConfigurationData.NonNodeData.MimeType
10 | }
11 | }
12 |
13 | configuration DSC_IisMimeTypeMapping_RemoveMimeType
14 | {
15 | Import-DscResource -ModuleName WebAdministrationDsc
16 |
17 | IisMimeTypeMapping RemoveMimeType
18 | {
19 | ConfigurationPath = ''
20 | Extension = $ConfigurationData.NonNodeData.FileExtension
21 | MimeType = $ConfigurationData.NonNodeData.MimeType
22 | Ensure = 'Absent'
23 | }
24 | }
25 |
26 | Configuration DSC_IisMimeTypeMapping_AddMimeTypeNestedPath
27 | {
28 | Import-DscResource -ModuleName WebAdministrationDsc
29 |
30 | IisMimeTypeMapping AddMimeTypeNestedPath
31 | {
32 | ConfigurationPath = $ConfigurationData.NonNodeData.VirtualConfigurationPath
33 | Extension = $ConfigurationData.NonNodeData.FileExtension
34 | MimeType = $ConfigurationData.NonNodeData.MimeType
35 | }
36 | }
37 |
38 | Configuration DSC_IisMimeTypeMapping_RemoveMimeTypeNestedPath
39 | {
40 | Import-DscResource -ModuleName WebAdministrationDsc
41 |
42 | IisMimeTypeMapping RemoveMimeTypeNestedPath
43 | {
44 | ConfigurationPath = $ConfigurationData.NonNodeData.VirtualConfigurationPath
45 | Extension = $ConfigurationData.NonNodeData.FileExtension
46 | MimeType = $ConfigurationData.NonNodeData.MimeType
47 | Ensure = 'Absent'
48 | }
49 | }
50 |
51 | Configuration DSC_IisMimeTypeMapping_AddMimeTypeAtServer
52 | {
53 | Import-DscResource -ModuleName WebAdministrationDsc
54 |
55 | IisMimeTypeMapping AddMimeTypeAtServer
56 | {
57 | ConfigurationPath = $ConfigurationData.NonNodeData.ServerConfigurationPath
58 | Extension = $ConfigurationData.NonNodeData.FileExtension
59 | MimeType = $ConfigurationData.NonNodeData.MimeType
60 | Ensure = 'Present'
61 | }
62 | }
63 |
64 | Configuration DSC_IisMimeTypeMapping_RemoveMimeTypeAtServer
65 | {
66 | Import-DscResource -ModuleName WebAdministrationDsc
67 |
68 | IisMimeTypeMapping AddMimeTypeAtServer
69 | {
70 | ConfigurationPath = $ConfigurationData.NonNodeData.ServerConfigurationPath
71 | Extension = $ConfigurationData.NonNodeData.FileExtension
72 | MimeType = $ConfigurationData.NonNodeData.MimeType
73 | Ensure = 'Absent'
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_NewWebsite.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_NewWebsite
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]]
7 | $NodeName = 'localhost',
8 |
9 | # Name of the website to create
10 | [Parameter(Mandatory = $true)]
11 | [ValidateNotNullOrEmpty()]
12 | [String]
13 | $WebSiteName,
14 |
15 | # Optional Site Id for the website
16 | [Parameter()]
17 | [UInt32]
18 | $SiteId,
19 |
20 | # Source Path for Website content
21 | [Parameter(Mandatory = $true)]
22 | [ValidateNotNullOrEmpty()]
23 | [String]
24 | $SourcePath,
25 |
26 | # Destination path for Website content
27 | [Parameter(Mandatory = $true)]
28 | [ValidateNotNullOrEmpty()]
29 | [String]
30 | $DestinationPath
31 | )
32 |
33 | # Import the module that defines custom resources
34 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
35 |
36 | Node $NodeName
37 | {
38 | # Install the IIS role
39 | WindowsFeature IIS
40 | {
41 | Ensure = 'Present'
42 | Name = 'Web-Server'
43 | }
44 |
45 | # Install the ASP .NET 4.5 role
46 | WindowsFeature AspNet45
47 | {
48 | Ensure = 'Present'
49 | Name = 'Web-Asp-Net45'
50 | }
51 |
52 | # Stop the default website
53 | WebSite DefaultSite
54 | {
55 | Ensure = 'Present'
56 | Name = 'Default Web Site'
57 | State = 'Stopped'
58 | ServerAutoStart = $false
59 | PhysicalPath = 'C:\inetpub\wwwroot'
60 | DependsOn = '[WindowsFeature]IIS'
61 | }
62 |
63 | # Copy the website content
64 | File WebContent
65 | {
66 | Ensure = 'Present'
67 | SourcePath = $SourcePath
68 | DestinationPath = $DestinationPath
69 | Recurse = $true
70 | Type = 'Directory'
71 | DependsOn = '[WindowsFeature]AspNet45'
72 | }
73 |
74 | # Create the new Website
75 | WebSite NewWebsite
76 | {
77 | Ensure = 'Present'
78 | Name = $WebSiteName
79 | SiteId = $SiteId
80 | State = 'Started'
81 | ServerAutoStart = $true
82 | PhysicalPath = $DestinationPath
83 | DependsOn = '[File]WebContent'
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebVirtualDirectory/Sample_WebVirtualDirectory_NewVirtualDirectory_WithUncPath.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Create a new web virtual directory on the Default Web Site
4 | .DESCRIPTION
5 | This example shows how to use the WebVirtualDirectory DSC resource to create a new virtual
6 | directory on the Default Web Site with a UNC path that requires credentials.
7 | #>
8 | configuration Sample_WebVirtualDirectory_NewVirtualDirectory_WithUncPath
9 | {
10 | param
11 | (
12 | # Target nodes to apply the configuration
13 | [System.String[]]
14 | $NodeName = 'localhost',
15 |
16 | # Name of virtual directory to create
17 | [Parameter(Mandatory)]
18 | [ValidateNotNullOrEmpty()]
19 | [System.String]
20 | $VirtualDirectoryName,
21 |
22 | # Physical path of the virtual directory
23 | [Parameter(Mandatory)]
24 | [ValidateNotNullOrEmpty()]
25 | [System.String]
26 | $PhysicalPath,
27 |
28 | # Credential to use for the virtual directory
29 | [Parameter(Mandatory)]
30 | [ValidateNotNullOrEmpty()]
31 | [PSCredential]
32 | $Credential
33 | )
34 |
35 | # Import the module that defines custom resources
36 | Import-DscResource -Module PSDesiredStateConfiguration
37 | Import-DscResource -Module WebAdministrationDsc
38 |
39 | Node $NodeName
40 | {
41 | # Install the IIS role
42 | WindowsFeature IIS
43 | {
44 | Ensure = 'Present'
45 | Name = 'Web-Server'
46 | }
47 |
48 | # Start the default website
49 | WebSite DefaultSite
50 | {
51 | Ensure = 'Present'
52 | Name = 'Default Web Site'
53 | State = 'Started'
54 | PhysicalPath = 'C:\inetpub\wwwroot'
55 | DependsOn = '[WindowsFeature]IIS'
56 | }
57 |
58 | # Copy the virtual directory content
59 | File VirtualDirectoryContent
60 | {
61 | Ensure = 'Present'
62 | DestinationPath = $PhysicalPath
63 | Type = 'Directory'
64 | DependsOn = '[WindowsFeature]IIS'
65 | }
66 |
67 | # Create the new virtual directory
68 | WebVirtualDirectory NewVirtualDirectory
69 | {
70 | Ensure = 'Present'
71 | Website = "Default Web Site"
72 | WebApplication = ''
73 | Name = $VirtualDirectoryName
74 | PhysicalPath = $PhysicalPath
75 | DependsOn = '[File]VirtualDirectoryContent'
76 | Credential = $Credential
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebVirtualDirectory.config.ps1:
--------------------------------------------------------------------------------
1 | #requires -Version 4
2 | configuration DSC_WebVirtualDirectory_Initialize
3 | {
4 | Import-DscResource -ModuleName WebAdministrationDsc
5 |
6 | Node $AllNodes.NodeName
7 | {
8 | WebSite Website
9 | {
10 | Ensure = 'Present'
11 | Name = $Node.Website
12 | PhysicalPath = $Node.WebsitePhysicalPath
13 | ApplicationPool = $Node.ApplicationPool
14 | BindingInfo = DSC_WebBindingInformation
15 | {
16 | Protocol = 'http'
17 | Port = $Node.Port
18 | HostName = $Node.Hostname
19 | IPAddress = '*'
20 | }
21 | }
22 |
23 | File WebApplicationDirectory
24 | {
25 | Ensure = 'Present'
26 | DestinationPath = $Node.WebApplicationPhysicalPath
27 | Type = 'Directory'
28 | }
29 |
30 | WebApplication WebApplication
31 | {
32 | Name = $Node.WebApplication
33 | Website = $Node.Website
34 | WebAppPool = $Node.ApplicationPool
35 | PhysicalPath = $Node.WebApplicationPhysicalPath
36 | DependsOn = '[File]WebApplicationDirectory','[WebSite]Website'
37 | }
38 |
39 | File WebVirtualDirectory
40 | {
41 | Ensure = 'Present'
42 | DestinationPath = $Node.PhysicalPath
43 | Type = 'Directory'
44 | }
45 | }
46 | }
47 |
48 | configuration DSC_WebVirtualDirectory_Present
49 | {
50 | Import-DscResource -ModuleName WebAdministrationDsc
51 |
52 | Node $AllNodes.NodeName
53 | {
54 | WebVirtualDirectory WebVirtualDirectory
55 | {
56 | Ensure = 'Present'
57 | Website = $Node.Website
58 | WebApplication = $Node.WebApplication
59 | Name = $Node.WebVirtualDirectory
60 | PhysicalPath = $Node.PhysicalPath
61 | Credential = New-Object -TypeName PSCredential -ArgumentList (
62 | $Node.Credential.UserName,
63 | ($Node.Credential.Password | ConvertTo-SecureString -AsPlainText -Force)
64 | )
65 | }
66 | }
67 | }
68 |
69 | configuration DSC_WebVirtualDirectory_Absent
70 | {
71 | Import-DscResource -ModuleName WebAdministrationDsc
72 |
73 | Node $AllNodes.NodeName
74 | {
75 | WebVirtualDirectory WebVirtualDirectory
76 | {
77 | Ensure = 'Absent'
78 | Website = $Node.Website
79 | WebApplication = $Node.WebApplication
80 | Name = $Node.WebVirtualDirectory
81 | PhysicalPath = $Node.PhysicalPath
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_NewWebsiteFromConfigurationData.ps1:
--------------------------------------------------------------------------------
1 | Configuration Sample_WebSite_NewWebsiteFromConfigurationData
2 | {
3 | # Import the module that defines custom resources
4 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
5 |
6 | # Dynamically find the applicable nodes from configuration data
7 | Node $AllNodes.where{ $_.Role -eq 'Web' }.NodeName
8 | {
9 | # Install the IIS role
10 | WindowsFeature IIS
11 | {
12 | Ensure = 'Present'
13 | Name = 'Web-Server'
14 | }
15 |
16 | # Install the ASP .NET 4.5 role
17 | WindowsFeature AspNet45
18 | {
19 | Ensure = 'Present'
20 | Name = 'Web-Asp-Net45'
21 | }
22 |
23 | # Stop an existing website (set up in Sample_WebSite_Default)
24 | WebSite DefaultSite
25 | {
26 | Ensure = 'Present'
27 | Name = 'Default Web Site'
28 | State = 'Stopped'
29 | ServerAutoStart = $false
30 | PhysicalPath = $Node.DefaultWebSitePath
31 | DependsOn = '[WindowsFeature]IIS'
32 | }
33 |
34 | # Copy the website content
35 | File WebContent
36 | {
37 | Ensure = 'Present'
38 | SourcePath = $Node.SourcePath
39 | DestinationPath = $Node.DestinationPath
40 | Recurse = $true
41 | Type = 'Directory'
42 | DependsOn = '[WindowsFeature]AspNet45'
43 | }
44 |
45 | # Create a new website
46 | WebSite BakeryWebSite
47 | {
48 | Ensure = 'Present'
49 | Name = $Node.WebsiteName
50 | State = 'Started'
51 | ServerAutoStart = $true
52 | PhysicalPath = $Node.DestinationPath
53 | DependsOn = '[File]WebContent'
54 | }
55 | }
56 | }
57 |
58 | # Hashtable to define the environmental data
59 | $ConfigurationData = @{
60 | # Node specific data
61 | AllNodes = @(
62 |
63 | # All the WebServers have the following identical information
64 | @{
65 | NodeName = '*'
66 | WebsiteName = 'FourthCoffee'
67 | SourcePath = 'C:\BakeryWebsite\'
68 | DestinationPath = 'C:\inetpub\FourthCoffee'
69 | DefaultWebSitePath = 'C:\inetpub\wwwroot'
70 | },
71 |
72 | @{
73 | NodeName = 'WebServer1.fourthcoffee.com'
74 | Role = 'Web'
75 | },
76 |
77 | @{
78 | NodeName = 'WebServer2.fourthcoffee.com'
79 | Role = 'Web'
80 | }
81 | );
82 | }
83 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_WithSSLFlags.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_WithSSLFlags
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]] $NodeName = 'localhost',
7 |
8 | # Name of the website to create
9 | [Parameter(Mandatory)]
10 | [ValidateNotNullOrEmpty()]
11 | [String] $WebSiteName,
12 |
13 | # Source Path for Website content
14 | [Parameter(Mandatory)]
15 | [ValidateNotNullOrEmpty()]
16 | [String] $SourcePath,
17 |
18 | # Destination path for Website content
19 | [Parameter(Mandatory)]
20 | [ValidateNotNullOrEmpty()]
21 | [String] $DestinationPath
22 | )
23 |
24 | # Import the module that defines custom resources
25 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
26 |
27 | Node $NodeName
28 | {
29 | # Install the IIS role
30 | WindowsFeature IIS
31 | {
32 | Ensure = "Present"
33 | Name = "Web-Server"
34 | }
35 |
36 | # Install the ASP .NET 4.5 role
37 | WindowsFeature AspNet45
38 | {
39 | Ensure = "Present"
40 | Name = "Web-Asp-Net45"
41 | }
42 |
43 | # Stop the default website
44 | WebSite DefaultSite
45 | {
46 | Ensure = "Present"
47 | Name = "Default Web Site"
48 | State = "Stopped"
49 | ServerAutoStart = $false
50 | PhysicalPath = "C:\inetpub\wwwroot"
51 | DependsOn = "[WindowsFeature]IIS"
52 | }
53 |
54 | # Copy the website content
55 | File WebContent
56 | {
57 | Ensure = "Present"
58 | SourcePath = $SourcePath
59 | DestinationPath = $DestinationPath
60 | Recurse = $true
61 | Type = "Directory"
62 | DependsOn = "[WindowsFeature]AspNet45"
63 | }
64 |
65 | # Create the new Website
66 | # Have it set to the CertificateThumbprint
67 | # and set that the Server Name Indication is required
68 | WebSite NewWebsite
69 | {
70 | Ensure = "Present"
71 | Name = $WebSiteName
72 | State = "Started"
73 | PhysicalPath = $DestinationPath
74 | DependsOn = "[File]WebContent"
75 | BindingInfo = DSC_WebBindingInformation
76 | {
77 | Protocol = 'https'
78 | Port = '443'
79 | CertificateStoreName = 'My'
80 | CertificateThumbprint = 'BB84DE3EC423DDDE90C08AB3C5A828692089493C'
81 | HostName = $WebSiteName
82 | IPAddress = '*'
83 | SSLFlags = '1'
84 | }
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebSiteDefaults.Integration.Tests.ps1:
--------------------------------------------------------------------------------
1 |
2 | $script:dscModuleName = 'WebAdministrationDsc'
3 | $script:dscResourceName = 'DSC_WebSiteDefaults'
4 |
5 | try
6 | {
7 | Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
8 | }
9 | catch [System.IO.FileNotFoundException]
10 | {
11 | throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
12 | }
13 |
14 | $script:testEnvironment = Initialize-TestEnvironment `
15 | -DSCModuleName $script:dscModuleName `
16 | -DSCResourceName $script:dscResourceName `
17 | -ResourceType 'Mof' `
18 | -TestType 'Integration'
19 |
20 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelper\CommonTestHelper.psm1') -Force
21 |
22 | $tempName = "$($script:dscResourceName)_" + (Get-Date).ToString("yyyyMMdd_HHmmss")
23 |
24 | try
25 | {
26 | $null = Backup-WebConfiguration -Name $tempName
27 |
28 | $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
29 | . $ConfigFile
30 |
31 | Describe "$($script:dscResourceName)_Integration" {
32 | #region DEFAULT TESTS
33 | It 'Should compile without throwing' {
34 | {
35 | Invoke-Expression -Command "$($script:dscResourceName)_Config -OutputPath `$TestDrive"
36 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
37 | } | Should not throw
38 | }
39 |
40 | It 'should be able to call Get-DscConfiguration without throwing' {
41 | { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
42 | }
43 | #endregion
44 |
45 | It 'Changing Default virtualDirectoryDefaults' -test {
46 | function GetSiteValue([string]$path,[string]$name)
47 | {
48 | return (Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/$path" -name $name).value
49 | }
50 |
51 | # get the current value
52 |
53 | [string] $originalValue = (Get-WebConfigurationProperty `
54 | -PSPath 'MACHINE/WEBROOT/APPHOST' `
55 | -Filter 'system.applicationHost/sites/virtualDirectoryDefaults' `
56 | -Name 'allowSubDirConfig').Value
57 |
58 | Invoke-Expression -Command "$($script:dscResourceName)_Config -OutputPath `$TestDrive"
59 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
60 |
61 | $changedValue = (Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -filter 'system.applicationHost/sites/virtualDirectoryDefaults' -name 'allowSubDirConfig').Value
62 | $changedValue | should be $env:PesterVirtualDirectoryDefaults
63 | }
64 | }
65 | }
66 | finally
67 | {
68 | Restore-WebConfigurationWrapper -Name $tempName -Verbose
69 |
70 | Remove-WebConfigurationBackup -Name $tempName -Verbose
71 |
72 | Restore-TestEnvironment -TestEnvironment $script:testEnvironment -Verbose
73 | }
74 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_NewWebsite_UsingCertificateSubject.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .DESCRIPTION
3 | When specifying a HTTPS web binding you can also specify a certifcate subject, for cases where the certificate
4 | is being generated by the same configuration using something like xCertReq.
5 | #>
6 | Configuration Sample_WebSite_NewWebsite_UsingCertificateSubject
7 | {
8 | param
9 | (
10 | # Target nodes to apply the configuration
11 | [string[]]
12 | $NodeName = 'localhost',
13 | # Name of the website to create
14 | [Parameter(Mandatory = $true)]
15 | [ValidateNotNullOrEmpty()]
16 | [String]
17 | $WebSiteName,
18 | # Source Path for Website content
19 | [Parameter(Mandatory = $true)]
20 | [ValidateNotNullOrEmpty()]
21 | [String]
22 | $SourcePath,
23 | # Destination path for Website content
24 | [Parameter(Mandatory = $true)]
25 | [ValidateNotNullOrEmpty()]
26 | [String]
27 | $DestinationPath
28 | )
29 |
30 | # Import the module that defines custom resources
31 | Import-DscResource -Module WebAdministrationDsc
32 | Node $NodeName
33 | {
34 | # Install the IIS role
35 | WindowsFeature IIS
36 | {
37 | Ensure = 'Present'
38 | Name = 'Web-Server'
39 | }
40 |
41 | # Install the ASP .NET 4.5 role
42 | WindowsFeature AspNet45
43 | {
44 | Ensure = 'Present'
45 | Name = 'Web-Asp-Net45'
46 | }
47 |
48 | # Stop the default website
49 | WebSite DefaultSite
50 | {
51 | Ensure = 'Present'
52 | Name = 'Default Web Site'
53 | State = 'Stopped'
54 | PhysicalPath = 'C:\inetpub\wwwroot'
55 | DependsOn = '[WindowsFeature]IIS'
56 | }
57 |
58 | # Copy the website content
59 | File WebContent
60 | {
61 | Ensure = 'Present'
62 | SourcePath = $SourcePath
63 | DestinationPath = $DestinationPath
64 | Recurse = $true
65 | Type = 'Directory'
66 | DependsOn = '[WindowsFeature]AspNet45'
67 | }
68 |
69 | # Create the new Website with HTTPS
70 | WebSite NewWebsite
71 | {
72 | Ensure = 'Present'
73 | Name = $WebSiteName
74 | State = 'Started'
75 | PhysicalPath = $DestinationPath
76 | BindingInfo = @(
77 | DSC_WebBindingInformation
78 | {
79 | Protocol = 'HTTPS'
80 | Port = 8444
81 | CertificateSubject = 'CN=CertificateSubject'
82 | CertificateStoreName = 'My'
83 | }
84 | )
85 | DependsOn = '[File]WebContent'
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_WebApplication/en-US/DSC_WebApplication.strings.psd1:
--------------------------------------------------------------------------------
1 | # culture="en-US"
2 | ConvertFrom-StringData -StringData @'
3 | ErrorWebApplicationTestAutoStartProviderFailure = Desired AutoStartProvider is not valid due to a conflicting Global Property. Ensure that the serviceAutoStartProvider is a unique key.
4 | VerboseGetTargetResource = Get-TargetResource has been run.
5 | VerboseSetTargetAbsent = Removing existing Web Application "{0}".
6 | VerboseSetTargetPresent = Creating new Web application "{0}".
7 | VerboseSetTargetPhysicalPath = Updating physical path for Web application "{0}".
8 | VerboseSetTargetWebAppPool = Updating application pool for Web application "{0}".
9 | VerboseSetTargetSslFlags = Updating SslFlags for Web application "{0}".
10 | VerboseSetTargetAuthenticationInfo = Updating AuthenticationInfo for Web application "{0}".
11 | VerboseSetTargetPreload = Updating Preload for Web application "{0}".
12 | VerboseSetTargetAutostart = Updating AutoStart for Web application "{0}".
13 | VerboseSetTargetIISAutoStartProviders = Updating AutoStartProviders for IIS.
14 | VerboseSetTargetWebApplicationAutoStartProviders = Updating AutoStartProviders for Web application "{0}".
15 | VerboseSetTargetEnabledProtocols = Updating EnabledProtocols for Web application "{0}".
16 | VerboseTestTargetFalseAbsent = Web application "{0}" is absent and should not absent.
17 | VerboseTestTargetFalsePresent = Web application $Name should be absent and is not absent.
18 | VerboseTestTargetFalsePhysicalPath = Physical path for web application "{0}" does not match desired state.
19 | VerboseTestTargetFalseWebAppPool = Web application pool for web application "{0}" does not match desired state.
20 | VerboseTestTargetFalseSslFlags = SslFlags for web application "{0}" are not in the desired state.
21 | VerboseTestTargetFalseAuthenticationInfo = AuthenticationInfo for web application "{0}" is not in the desired state.
22 | VerboseTestTargetFalsePreload = Preload for web application "{0}" is not in the desired state.
23 | VerboseTestTargetFalseAutostart = Autostart for web application "{0}" is not in the desired state.
24 | VerboseTestTargetFalseIISAutoStartProviders = AutoStartProviders for IIS are not in the desired state.
25 | VerboseTestTargetFalseWebApplicationAutoStartProviders = AutoStartProviders for web application "{0}" are not in the desired state.
26 | VerboseTestTargetFalseEnabledProtocols = EnabledProtocols for web application "{0}" are not in the desired state.
27 | '@
28 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_WithCustomLogFields_EnsurePresentDefault.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_WithCustomLogFields_EnsurePresentDefault
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]]
7 | $NodeName = 'localhost',
8 |
9 | # Name of the website to create
10 | [Parameter(Mandatory = $true)]
11 | [ValidateNotNullOrEmpty()]
12 | [String]
13 | $WebSiteName,
14 |
15 | # Optional Site Id for the website
16 | [Parameter()]
17 | [UInt32]
18 | $SiteId,
19 |
20 | # Source Path for Website content
21 | [Parameter(Mandatory = $true)]
22 | [ValidateNotNullOrEmpty()]
23 | [String]
24 | $SourcePath,
25 |
26 | # Destination path for Website content
27 | [Parameter(Mandatory = $true)]
28 | [ValidateNotNullOrEmpty()]
29 | [String]
30 | $DestinationPath
31 | )
32 |
33 | # Import the module that defines custom resources
34 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
35 |
36 | Node $NodeName
37 | {
38 | # Install the IIS role
39 | WindowsFeature IIS
40 | {
41 | Ensure = 'Present'
42 | Name = 'Web-Server'
43 | }
44 |
45 | # Install the ASP .NET 4.5 role
46 | WindowsFeature AspNet45
47 | {
48 | Ensure = 'Present'
49 | Name = 'Web-Asp-Net45'
50 | }
51 |
52 | # Stop the default website
53 | WebSite DefaultSite
54 | {
55 | Ensure = 'Present'
56 | Name = 'Default Web Site'
57 | State = 'Stopped'
58 | ServerAutoStart = $false
59 | PhysicalPath = 'C:\inetpub\wwwroot'
60 | DependsOn = '[WindowsFeature]IIS'
61 | }
62 |
63 | # Copy the website content
64 | File WebContent
65 | {
66 | Ensure = 'Present'
67 | SourcePath = $SourcePath
68 | DestinationPath = $DestinationPath
69 | Recurse = $true
70 | Type = 'Directory'
71 | DependsOn = '[WindowsFeature]AspNet45'
72 | }
73 |
74 | # Create the new Website
75 | WebSite NewWebsite
76 | {
77 | Ensure = 'Present'
78 | Name = $WebSiteName
79 | SiteId = $SiteId
80 | State = 'Started'
81 | ServerAutoStart = $true
82 | PhysicalPath = $DestinationPath
83 | DependsOn = '[File]WebContent'
84 | LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent')
85 | LogFormat = 'W3C'
86 | LogCustomFields = @(
87 | DSC_LogCustomFieldInformation
88 | {
89 | LogFieldName = 'ClientEncoding'
90 | SourceName = 'Accept-Encoding'
91 | SourceType = 'RequestHeader'
92 | }
93 | )
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_WithCustomLogFields_EnsureAbsent.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_WithCustomLogFields_EnsureAbsent
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]]
7 | $NodeName = 'localhost',
8 |
9 | # Name of the website to create
10 | [Parameter(Mandatory = $true)]
11 | [ValidateNotNullOrEmpty()]
12 | [String]
13 | $WebSiteName,
14 |
15 | # Optional Site Id for the website
16 | [Parameter()]
17 | [UInt32]
18 | $SiteId,
19 |
20 | # Source Path for Website content
21 | [Parameter(Mandatory = $true)]
22 | [ValidateNotNullOrEmpty()]
23 | [String]
24 | $SourcePath,
25 |
26 | # Destination path for Website content
27 | [Parameter(Mandatory = $true)]
28 | [ValidateNotNullOrEmpty()]
29 | [String]
30 | $DestinationPath
31 | )
32 |
33 | # Import the module that defines custom resources
34 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
35 |
36 | Node $NodeName
37 | {
38 | # Install the IIS role
39 | WindowsFeature IIS
40 | {
41 | Ensure = 'Present'
42 | Name = 'Web-Server'
43 | }
44 |
45 | # Install the ASP .NET 4.5 role
46 | WindowsFeature AspNet45
47 | {
48 | Ensure = 'Present'
49 | Name = 'Web-Asp-Net45'
50 | }
51 |
52 | # Stop the default website
53 | WebSite DefaultSite
54 | {
55 | Ensure = 'Present'
56 | Name = 'Default Web Site'
57 | State = 'Stopped'
58 | ServerAutoStart = $false
59 | PhysicalPath = 'C:\inetpub\wwwroot'
60 | DependsOn = '[WindowsFeature]IIS'
61 | }
62 |
63 | # Copy the website content
64 | File WebContent
65 | {
66 | Ensure = 'Present'
67 | SourcePath = $SourcePath
68 | DestinationPath = $DestinationPath
69 | Recurse = $true
70 | Type = 'Directory'
71 | DependsOn = '[WindowsFeature]AspNet45'
72 | }
73 |
74 | # Create the new Website
75 | WebSite NewWebsite
76 | {
77 | Ensure = 'Present'
78 | Name = $WebSiteName
79 | SiteId = $SiteId
80 | State = 'Started'
81 | ServerAutoStart = $true
82 | PhysicalPath = $DestinationPath
83 | DependsOn = '[File]WebContent'
84 | LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent')
85 | LogFormat = 'W3C'
86 | LogCustomFields = @(
87 | DSC_LogCustomFieldInformation
88 | {
89 | LogFieldName = 'ClientEncoding'
90 | SourceName = 'Accept-Encoding'
91 | SourceType = 'RequestHeader'
92 | Ensure = 'Absent'
93 | }
94 | )
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_WithCustomLogFields_EnsurePresentExplicitly.ps1:
--------------------------------------------------------------------------------
1 | configuration Sample_WebSite_WithCustomLogFields_EnsurePresentExplicitly
2 | {
3 | param
4 | (
5 | # Target nodes to apply the configuration
6 | [String[]]
7 | $NodeName = 'localhost',
8 |
9 | # Name of the website to create
10 | [Parameter(Mandatory = $true)]
11 | [ValidateNotNullOrEmpty()]
12 | [String]
13 | $WebSiteName,
14 |
15 | # Optional Site Id for the website
16 | [Parameter()]
17 | [UInt32]
18 | $SiteId,
19 |
20 | # Source Path for Website content
21 | [Parameter(Mandatory = $true)]
22 | [ValidateNotNullOrEmpty()]
23 | [String]
24 | $SourcePath,
25 |
26 | # Destination path for Website content
27 | [Parameter(Mandatory = $true)]
28 | [ValidateNotNullOrEmpty()]
29 | [String]
30 | $DestinationPath
31 | )
32 |
33 | # Import the module that defines custom resources
34 | Import-DscResource -Module WebAdministrationDsc, PSDesiredStateConfiguration
35 |
36 | Node $NodeName
37 | {
38 | # Install the IIS role
39 | WindowsFeature IIS
40 | {
41 | Ensure = 'Present'
42 | Name = 'Web-Server'
43 | }
44 |
45 | # Install the ASP .NET 4.5 role
46 | WindowsFeature AspNet45
47 | {
48 | Ensure = 'Present'
49 | Name = 'Web-Asp-Net45'
50 | }
51 |
52 | # Stop the default website
53 | WebSite DefaultSite
54 | {
55 | Ensure = 'Present'
56 | Name = 'Default Web Site'
57 | State = 'Stopped'
58 | ServerAutoStart = $false
59 | PhysicalPath = 'C:\inetpub\wwwroot'
60 | DependsOn = '[WindowsFeature]IIS'
61 | }
62 |
63 | # Copy the website content
64 | File WebContent
65 | {
66 | Ensure = 'Present'
67 | SourcePath = $SourcePath
68 | DestinationPath = $DestinationPath
69 | Recurse = $true
70 | Type = 'Directory'
71 | DependsOn = '[WindowsFeature]AspNet45'
72 | }
73 |
74 | # Create the new Website
75 | WebSite NewWebsite
76 | {
77 | Ensure = 'Present'
78 | Name = $WebSiteName
79 | SiteId = $SiteId
80 | State = 'Started'
81 | ServerAutoStart = $true
82 | PhysicalPath = $DestinationPath
83 | DependsOn = '[File]WebContent'
84 | LogFlags = @('Date','Time','ClientIP','ServerIP','UserAgent')
85 | LogFormat = 'W3C'
86 | LogCustomFields = @(
87 | DSC_LogCustomFieldInformation
88 | {
89 | LogFieldName = 'ClientEncoding'
90 | SourceName = 'Accept-Encoding'
91 | SourceType = 'RequestHeader'
92 | Ensure = 'Present'
93 | }
94 | )
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebApplication/Sample_WebApplication_NewWebApplication.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Create a new web application on the Default Web Site
4 | .DESCRIPTION
5 | This example shows how to use the WebApplication DSC resource to create a new web application.
6 | #>
7 | Configuration Sample_WebApplication_NewWebApplication
8 | {
9 | param
10 | (
11 | # Target nodes to apply the configuration
12 | [String[]] $NodeName = 'localhost',
13 |
14 | # Destination path for Website content
15 | [Parameter(Mandatory)]
16 | [ValidateNotNullOrEmpty()]
17 | [String] $DestinationPath
18 | )
19 |
20 | # Import the module that defines custom resources
21 | Import-DscResource -Module PSDesiredStateConfiguration
22 | Import-DscResource -Module WebAdministrationDsc
23 |
24 | Node $NodeName
25 | {
26 | # Install the IIS role
27 | WindowsFeature IIS
28 | {
29 | Ensure = 'Present'
30 | Name = 'Web-Server'
31 | }
32 |
33 | # Install the ASP .NET 4.5 role
34 | WindowsFeature AspNet45
35 | {
36 | Ensure = 'Present'
37 | Name = 'Web-Asp-Net45'
38 | }
39 |
40 | # Start the Default Web Site
41 | WebSite DefaultSite
42 | {
43 | Ensure = 'Present'
44 | Name = 'Default Web Site'
45 | State = 'Started'
46 | PhysicalPath = 'C:\inetpub\wwwroot'
47 | DependsOn = '[WindowsFeature]IIS'
48 | }
49 |
50 | # Create a new application pool for the application
51 | WebAppPool SampleAppPool
52 | {
53 | Ensure = 'Present'
54 | Name = 'SampleAppPool'
55 | }
56 |
57 | # Clone the wwwroot folder to the destination
58 | File WebContent
59 | {
60 | Ensure = 'Present'
61 | SourcePath = 'C:\inetpub\wwwroot'
62 | DestinationPath = $DestinationPath
63 | Recurse = $true
64 | Type = 'Directory'
65 | DependsOn = '[WindowsFeature]IIS'
66 | }
67 |
68 | # Create a new web application with Windows Authentication
69 | WebApplication SampleApplication
70 | {
71 | Ensure = 'Present'
72 | Name = 'SampleApplication'
73 | WebAppPool = 'SampleAppPool'
74 | Website = 'Default Web Site'
75 | PreloadEnabled = $true
76 | ServiceAutoStartEnabled = $true
77 | AuthenticationInfo = DSC_WebApplicationAuthenticationInformation
78 | {
79 | Anonymous = $false
80 | Basic = $false
81 | Digest = $false
82 | Windows = $true
83 | }
84 | SslFlags = ''
85 | PhysicalPath = $DestinationPath
86 | DependsOn = '[WebSite]DefaultSite','[WebAppPool]SampleAppPool'
87 | }
88 | }
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Problem_with_resource.yml:
--------------------------------------------------------------------------------
1 | name: Problem with a resource
2 | description: If you have a problem, bug, or enhancement with a resource in this resource module.
3 | labels: []
4 | assignees: []
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Please prefix the issue title (above) with the resource name, e.g. 'ResourceName: Short description of my issue'!
10 |
11 | Your feedback and support is greatly appreciated, thanks for contributing!
12 | - type: textarea
13 | id: description
14 | attributes:
15 | label: Problem description
16 | description: Details of the scenario you tried and the problem that is occurring.
17 | validations:
18 | required: true
19 | - type: textarea
20 | id: logs
21 | attributes:
22 | label: Verbose logs
23 | description: |
24 | Verbose logs showing the problem. **NOTE! Sensitive information should be obfuscated.** _Will be automatically formatted as plain text._
25 | placeholder: |
26 | Paste verbose logs here
27 | render: text
28 | validations:
29 | required: true
30 | - type: textarea
31 | id: configuration
32 | attributes:
33 | label: DSC configuration
34 | description: |
35 | The DSC configuration that is used to reproduce the issue (as detailed as possible). **NOTE! Sensitive information should be obfuscated.** _Will be automatically formatted as PowerShell code._
36 | placeholder: |
37 | Paste DSC configuration here
38 | render: powershell
39 | validations:
40 | required: true
41 | - type: textarea
42 | id: suggestedSolution
43 | attributes:
44 | label: Suggested solution
45 | description: Do you have any suggestions how to solve the issue?
46 | validations:
47 | required: true
48 | - type: textarea
49 | id: targetNodeOS
50 | attributes:
51 | label: Operating system the target node is running
52 | description: |
53 | Please provide as much as possible about the target node, for example edition, version, build, and language. _Will be automatically formatted as plain text._
54 |
55 | On OS with WMF 5.1 the following command can help get this information: `Get-ComputerInfo -Property @('OsName','OsOperatingSystemSKU','OSArchitecture','WindowsVersion','WindowsBuildLabEx','OsLanguage','OsMuiLanguages')`
56 | placeholder: |
57 | Add operating system information here
58 | render: text
59 | validations:
60 | required: true
61 | - type: textarea
62 | id: targetNodePS
63 | attributes:
64 | label: PowerShell version and build the target node is running
65 | description: |
66 | Please provide the version and build of PowerShell the target node is running. _Will be automatically formatted as plain text._
67 |
68 | To help with this information, please run this command: `$PSVersionTable`
69 | placeholder: |
70 | Add PowerShell information here
71 | render: text
72 | validations:
73 | required: true
74 | - type: textarea
75 | id: moduleVersion
76 | attributes:
77 | label: WebAdministrationDsc version
78 | description: |
79 | Please provide the version of the WebAdministrationDsc module that was used. _Will be automatically formatted as plain text._
80 |
81 | To help with this information, please run this command: `Get-Module -Name 'WebAdministrationDsc' -ListAvailable | ft Name,Version,Path`
82 | placeholder: |
83 | Add module information here
84 | render: text
85 | validations:
86 | required: true
87 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebSite/Sample_WebSite_NewWebsite_UsingCertificateThumbprint.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .DESCRIPTION
3 | While setting up IIS and stopping the default website is interesting, it isn�t quite useful yet.
4 | After all, people typically use IIS to set up websites of their own with custom protocol and bindings.
5 | Fortunately, using DSC, adding another website is as simple as using the File and WebSite resources to
6 | copy the website content and configure the website.
7 | #>
8 | Configuration Sample_WebSite_NewWebsite_UsingCertificateThumbprint
9 | {
10 | param
11 | (
12 | # Target nodes to apply the configuration
13 | [string[]]
14 | $NodeName = 'localhost',
15 | # Name of the website to create
16 | [Parameter(Mandatory = $true)]
17 | [ValidateNotNullOrEmpty()]
18 | [String]
19 | $WebSiteName,
20 | # Source Path for Website content
21 | [Parameter(Mandatory = $true)]
22 | [ValidateNotNullOrEmpty()]
23 | [String]
24 | $SourcePath,
25 | # Destination path for Website content
26 | [Parameter(Mandatory = $true)]
27 | [ValidateNotNullOrEmpty()]
28 | [String]
29 | $DestinationPath
30 | )
31 |
32 | # Import the module that defines custom resources
33 | Import-DscResource -Module WebAdministrationDsc
34 | Node $NodeName
35 | {
36 | # Install the IIS role
37 | WindowsFeature IIS
38 | {
39 | Ensure = 'Present'
40 | Name = 'Web-Server'
41 | }
42 |
43 | # Install the ASP .NET 4.5 role
44 | WindowsFeature AspNet45
45 | {
46 | Ensure = 'Present'
47 | Name = 'Web-Asp-Net45'
48 | }
49 |
50 | # Stop the default website
51 | WebSite DefaultSite
52 | {
53 | Ensure = 'Present'
54 | Name = 'Default Web Site'
55 | State = 'Stopped'
56 | PhysicalPath = 'C:\inetpub\wwwroot'
57 | DependsOn = '[WindowsFeature]IIS'
58 | }
59 |
60 | # Copy the website content
61 | File WebContent
62 | {
63 | Ensure = 'Present'
64 | SourcePath = $SourcePath
65 | DestinationPath = $DestinationPath
66 | Recurse = $true
67 | Type = 'Directory'
68 | DependsOn = '[WindowsFeature]AspNet45'
69 | }
70 |
71 | # Create the new Website with HTTPS
72 | WebSite NewWebsite
73 | {
74 | Ensure = 'Present'
75 | Name = $WebSiteName
76 | State = 'Started'
77 | PhysicalPath = $DestinationPath
78 | BindingInfo = @(
79 | DSC_WebBindingInformation
80 | {
81 | Protocol = 'HTTPS'
82 | Port = 8443
83 | CertificateThumbprint = '71AD93562316F21F74606F1096B85D66289ED60F'
84 | CertificateStoreName = 'WebHosting'
85 | }
86 | DSC_WebBindingInformation
87 | {
88 | Protocol = 'HTTPS'
89 | Port = 8444
90 | CertificateThumbprint = 'DEDDD963B28095837F558FE14DA1FDEFB7FA9DA7'
91 | CertificateStoreName = 'My'
92 | }
93 | )
94 | DependsOn = '[File]WebContent'
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/source/Examples/Resources/WebAppPool/Sample_WebAppPool.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Create and configure an application pool.
4 | .DESCRIPTION
5 | This example shows how to use the WebAppPool DSC resource to create and configure an application pool.
6 | #>
7 |
8 | Configuration Sample_WebAppPool
9 | {
10 | param
11 | (
12 | [String[]]$NodeName = 'localhost'
13 | )
14 |
15 | Import-DscResource -ModuleName WebAdministrationDsc
16 |
17 | Node $NodeName
18 | {
19 | WebAppPool SampleAppPool
20 | {
21 | Name = 'SampleAppPool'
22 | Ensure = 'Present'
23 | State = 'Started'
24 | autoStart = $true
25 | CLRConfigFile = ''
26 | enable32BitAppOnWin64 = $false
27 | enableConfigurationOverride = $true
28 | managedPipelineMode = 'Integrated'
29 | managedRuntimeLoader = 'webengine4.dll'
30 | managedRuntimeVersion = 'v4.0'
31 | passAnonymousToken = $true
32 | startMode = 'OnDemand'
33 | queueLength = 1000
34 | cpuAction = 'NoAction'
35 | cpuLimit = 90000
36 | cpuResetInterval = (New-TimeSpan -Minutes 5).ToString()
37 | cpuSmpAffinitized = $false
38 | cpuSmpProcessorAffinityMask = 4294967295
39 | cpuSmpProcessorAffinityMask2 = 4294967295
40 | identityType = 'ApplicationPoolIdentity'
41 | idleTimeout = (New-TimeSpan -Minutes 20).ToString()
42 | idleTimeoutAction = 'Terminate'
43 | loadUserProfile = $true
44 | logEventOnProcessModel = 'IdleTimeout'
45 | logonType = 'LogonBatch'
46 | manualGroupMembership = $false
47 | maxProcesses = 1
48 | pingingEnabled = $true
49 | pingInterval = (New-TimeSpan -Seconds 30).ToString()
50 | pingResponseTime = (New-TimeSpan -Seconds 90).ToString()
51 | setProfileEnvironment = $false
52 | shutdownTimeLimit = (New-TimeSpan -Seconds 90).ToString()
53 | startupTimeLimit = (New-TimeSpan -Seconds 90).ToString()
54 | orphanActionExe = ''
55 | orphanActionParams = ''
56 | orphanWorkerProcess = $false
57 | loadBalancerCapabilities = 'HttpLevel'
58 | rapidFailProtection = $true
59 | rapidFailProtectionInterval = (New-TimeSpan -Minutes 5).ToString()
60 | rapidFailProtectionMaxCrashes = 5
61 | autoShutdownExe = ''
62 | autoShutdownParams = ''
63 | disallowOverlappingRotation = $false
64 | disallowRotationOnConfigChange = $false
65 | logEventOnRecycle = 'Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory'
66 | restartMemoryLimit = 0
67 | restartPrivateMemoryLimit = 0
68 | restartRequestsLimit = 0
69 | restartTimeLimit = (New-TimeSpan -Minutes 1440).ToString()
70 | restartSchedule = @('00:00:00', '08:00:00', '16:00:00')
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_IISLogging.config.ps1:
--------------------------------------------------------------------------------
1 | configuration DSC_IisLogging_Rollover
2 | {
3 | Import-DscResource -ModuleName WebAdministrationDsc
4 |
5 | IisLogging Logging
6 | {
7 | LogPath = 'C:\IISLogFiles'
8 | Logflags = @('Date','Time','ClientIP','UserName','ServerIP')
9 | LoglocalTimeRollover = $true
10 | LogPeriod = 'Hourly'
11 | LogFormat = 'W3C'
12 | LogTargetW3C = 'File,ETW'
13 | LogCustomFields = @(
14 | DSC_LogCustomField
15 | {
16 | LogFieldName = 'ClientEncoding'
17 | SourceName = 'Accept-Encoding'
18 | SourceType = 'RequestHeader'
19 | }
20 | DSC_LogCustomField
21 | {
22 | LogFieldName = 'X-Powered-By'
23 | SourceName = 'ASP.NET'
24 | SourceType = 'ResponseHeader'
25 | }
26 | )
27 | }
28 | }
29 |
30 | configuration DSC_IisLogging_Truncate
31 | {
32 | Import-DscResource -ModuleName WebAdministrationDsc
33 |
34 | IisLogging Logging
35 | {
36 | LogPath = 'C:\IISLogFiles'
37 | Logflags = @('Date','Time','ClientIP','UserName','ServerIP')
38 | LoglocalTimeRollover = $true
39 | LogTruncateSize = '2097152'
40 | LogFormat = 'W3C'
41 | LogTargetW3C = 'File,ETW'
42 | LogCustomFields = @(
43 | DSC_LogCustomField
44 | {
45 | LogFieldName = 'ClientEncoding'
46 | SourceName = 'Accept-Encoding'
47 | SourceType = 'RequestHeader'
48 | }
49 | DSC_LogCustomField
50 | {
51 | LogFieldName = 'X-Powered-By'
52 | SourceName = 'ASP.NET'
53 | SourceType = 'ResponseHeader'
54 | }
55 | )
56 | }
57 | }
58 |
59 | configuration DSC_IisLogging_LogFlags
60 | {
61 | Import-DscResource -ModuleName WebAdministrationDsc
62 |
63 | IisLogging Logging
64 | {
65 | LogPath = 'C:\IISLogFiles'
66 | Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent')
67 | LoglocalTimeRollover = $true
68 | LogTruncateSize = '2097152'
69 | LogFormat = 'W3C'
70 | LogTargetW3C = 'File,ETW'
71 | LogCustomFields = @(
72 | DSC_LogCustomField
73 | {
74 | LogFieldName = 'ClientEncoding'
75 | SourceName = 'Accept-Encoding'
76 | SourceType = 'RequestHeader'
77 | }
78 | DSC_LogCustomField
79 | {
80 | LogFieldName = 'X-Powered-By'
81 | SourceName = 'ASP.NET'
82 | SourceType = 'ResponseHeader'
83 | }
84 | )
85 | }
86 | }
87 |
88 | configuration DSC_IisLogging_LogCustomFields
89 | {
90 | Import-DscResource -ModuleName WebAdministrationDsc
91 |
92 | IisLogging Logging
93 | {
94 | LogPath = 'C:\IISLogFiles'
95 | Logflags = @('Date','Time','ClientIP','ServerIP','UserAgent')
96 | LoglocalTimeRollover = $true
97 | LogTruncateSize = '2097152'
98 | LogFormat = 'W3C'
99 | LogTargetW3C = 'File,ETW'
100 | LogCustomFields = @(
101 | DSC_LogCustomField
102 | {
103 | LogFieldName = 'ClientEncoding'
104 | SourceName = 'Accept-Encoding'
105 | SourceType = 'RequestHeader'
106 | Ensure = 'Absent'
107 | }
108 | DSC_LogCustomField
109 | {
110 | LogFieldName = 'X-Powered-By'
111 | SourceName = 'ASP.NET'
112 | SourceType = 'ResponseHeader'
113 | Ensure = 'Absent'
114 | }
115 | )
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/tests/TestHelper/CommonTestHelper.psm1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Wrapper for Restore-WebConfiguration to be able to retry on errors.
4 |
5 | .PARAMETER Name
6 | The name of the backup to restore.
7 |
8 | .NOTES
9 | - This wrapper is a workaround for the error:
10 |
11 | IOException: The process cannot access the file
12 | 'C:\windows\system32\inetsrv\mbschema.xml' because
13 | it is being used by another process.
14 |
15 | - Addresses Issue #385: xWebConfigPropertyCollection: Timing issue in integration tests
16 |
17 | IOException: The process cannot access the file
18 | 'C:\windows\system32\inetsrv\config\applicationHost.config'
19 | because it is being used by another process.
20 | #>
21 | function Restore-WebConfigurationWrapper
22 | {
23 | [CmdletBinding()]
24 | param
25 | (
26 | [Parameter(Mandatory = $true)]
27 | [System.String]
28 | $Name
29 | )
30 |
31 | $retryCount = 1
32 | $backupRestored = $false
33 |
34 | do
35 | {
36 | try
37 | {
38 | Write-Verbose -Message ('Restoring web configuration - attempt {0}' -f $retryCount)
39 |
40 | Restore-WebConfiguration -Name $Name
41 |
42 | Write-Verbose -Message ('Successfully restored web configuration' -f $retryCount)
43 |
44 | $backupRestored = $true
45 | }
46 | catch [System.IO.IOException], [System.ComponentModel.Win32Exception]
47 | {
48 | # On the fifth try, throw an error.
49 | if ($retryCount -eq 5)
50 | {
51 | throw $_
52 | }
53 |
54 | Write-Verbose -Message ('Failed to restore web configuration. Retrying in 5 seconds. For reference the error message was "{0}".' -f $_)
55 |
56 | $retryCount += 1
57 |
58 | Start-Sleep -Seconds 5
59 | }
60 | catch
61 | {
62 | throw $_
63 | }
64 | } while (-not $backupRestored)
65 |
66 | # Wait a bit for the restore to free resources.
67 | Start-Sleep -Seconds 10
68 | }
69 |
70 | function Reset-DscLcm
71 | {
72 | [CmdletBinding()]
73 | param ()
74 |
75 | Write-Verbose -Message 'Resetting DSC LCM.'
76 |
77 | Stop-DscConfiguration -Force -ErrorAction SilentlyContinue
78 | Remove-DscConfigurationDocument -Stage Current -Force
79 | Remove-DscConfigurationDocument -Stage Pending -Force
80 | Remove-DscConfigurationDocument -Stage Previous -Force
81 | }
82 |
83 | <#
84 | .SYNOPSIS
85 | Cleanup after unit tests.
86 |
87 | .PARAMETER TestEnvironment
88 | The TestEnvironment returned by Initialize-TestEnvironment.
89 |
90 | .NOTES
91 | - Remove-Module MockWebAdministrationWindowsFeature
92 | - Remove mocks based on MockWebAdministrationWindowsFeature
93 | - Restore-TestEnvironment
94 | #>
95 | function Invoke-UnitTestCleanup
96 | {
97 | [CmdletBinding()]
98 | param
99 | (
100 | [Parameter(Mandatory = $true)]
101 | [ValidateNotNullOrEmpty()]
102 | [Hashtable]
103 | $TestEnvironment
104 | )
105 |
106 | if (Get-Module -Name 'MockWebAdministrationWindowsFeature')
107 | {
108 | Write-Information 'Removing MockWebAdministrationWindowsFeature module...'
109 | Remove-Module -Name 'MockWebAdministrationWindowsFeature'
110 | }
111 |
112 | $mocks = (Get-ChildItem Function:) | Where-Object { $_.Source -eq 'MockWebAdministrationWindowsFeature' }
113 |
114 | if ($mocks)
115 | {
116 | Write-Information 'Removing MockWebAdministrationWindowsFeature functions...'
117 | $mocks | Remove-Item
118 | }
119 |
120 | Restore-TestEnvironment -TestEnvironment $TestEnvironment
121 | }
122 |
123 | Export-ModuleMember -Function `
124 | Restore-WebConfigurationWrapper, `
125 | Reset-DscLcm, `
126 | Invoke-UnitTestCleanup
127 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "_runner": "terminal",
4 | "windows": {
5 | "options": {
6 | "shell": {
7 | "executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
8 | "args": [
9 | "-NoProfile",
10 | "-ExecutionPolicy",
11 | "Bypass",
12 | "-Command"
13 | ]
14 | }
15 | }
16 | },
17 | "linux": {
18 | "options": {
19 | "shell": {
20 | "executable": "/usr/bin/pwsh",
21 | "args": [
22 | "-NoProfile",
23 | "-Command"
24 | ]
25 | }
26 | }
27 | },
28 | "osx": {
29 | "options": {
30 | "shell": {
31 | "executable": "/usr/local/bin/pwsh",
32 | "args": [
33 | "-NoProfile",
34 | "-Command"
35 | ]
36 | }
37 | }
38 | },
39 | "tasks": [
40 | {
41 | "label": "build",
42 | "type": "shell",
43 | "command": "&${cwd}/build.ps1",
44 | "args": [],
45 | "presentation": {
46 | "echo": true,
47 | "reveal": "always",
48 | "focus": true,
49 | "panel": "new",
50 | "clear": false
51 | },
52 | "runOptions": {
53 | "runOn": "default"
54 | },
55 | "problemMatcher": [
56 | {
57 | "owner": "powershell",
58 | "fileLocation": [
59 | "absolute"
60 | ],
61 | "severity": "error",
62 | "pattern": [
63 | {
64 | "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
65 | "message": 1
66 | },
67 | {
68 | "regexp": "(.*)",
69 | "code": 1
70 | },
71 | {
72 | "regexp": ""
73 | },
74 | {
75 | "regexp": "^.*,\\s*(.*):\\s*line\\s*(\\d+).*",
76 | "file": 1,
77 | "line": 2
78 | }
79 | ]
80 | }
81 | ]
82 | },
83 | {
84 | "label": "test",
85 | "type": "shell",
86 | "command": "&${cwd}/build.ps1",
87 | "args": ["-AutoRestore","-Tasks","test"],
88 | "presentation": {
89 | "echo": true,
90 | "reveal": "always",
91 | "focus": true,
92 | "panel": "dedicated",
93 | "showReuseMessage": true,
94 | "clear": false
95 | },
96 | "problemMatcher": [
97 | {
98 | "owner": "powershell",
99 | "fileLocation": [
100 | "absolute"
101 | ],
102 | "severity": "error",
103 | "pattern": [
104 | {
105 | "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
106 | "message": 1
107 | },
108 | {
109 | "regexp": "(.*)",
110 | "code": 1
111 | },
112 | {
113 | "regexp": ""
114 | },
115 | {
116 | "regexp": "^.*,\\s*(.*):\\s*line\\s*(\\d+).*",
117 | "file": 1,
118 | "line": 2
119 | }
120 | ]
121 | }
122 | ]
123 | }
124 | ]
125 | }
126 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebAppPool.Integration.Tests.ps1:
--------------------------------------------------------------------------------
1 | #requires -Version 4.0
2 |
3 | $script:dscModuleName = 'WebAdministrationDsc'
4 | $script:dscResourceName = 'DSC_WebAppPool'
5 |
6 | try
7 | {
8 | Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
9 | }
10 | catch [System.IO.FileNotFoundException]
11 | {
12 | throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
13 | }
14 |
15 | $script:testEnvironment = Initialize-TestEnvironment `
16 | -DSCModuleName $script:dscModuleName `
17 | -DSCResourceName $script:dscResourceName `
18 | -ResourceType 'Mof' `
19 | -TestType 'Integration'
20 |
21 | # Test Setup
22 | if ((Get-Service -Name 'W3SVC').Status -ne 'Running')
23 | {
24 | Start-Service -Name 'W3SVC'
25 | }
26 |
27 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelper\CommonTestHelper.psm1') -Force
28 |
29 | $tempName = "$($script:dscResourceName)_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
30 |
31 | try
32 | {
33 | # Create configuration backup
34 |
35 | $null = Backup-WebConfiguration -Name $tempName
36 |
37 | #region Integration Tests
38 |
39 | $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
40 | . $ConfigFile
41 |
42 | Describe "$($script:dscResourceName)_Integration" {
43 |
44 | $ConfigData = @{
45 | AllNodes = @(
46 | @{
47 | NodeName = '*'
48 | PSDscAllowPlainTextPassword = $true
49 | }
50 | @{
51 | NodeName = 'localhost'
52 | }
53 | )
54 | }
55 |
56 | #region Default Tests
57 | It 'Should compile the MOF without throwing' {
58 | {
59 | & "$($script:DSCResourceName)_Integration" `
60 | -OutputPath $TestDrive `
61 | -ConfigurationData $ConfigData
62 | } | Should -Not -Throw
63 | }
64 |
65 | It 'Should apply the MOF without throwing' {
66 | {
67 | Reset-DscLcm
68 |
69 | Start-DscConfiguration `
70 | -Path $TestDrive `
71 | -ComputerName localhost `
72 | -Wait `
73 | -Verbose `
74 | -Force `
75 | -ErrorAction Stop
76 | } | Should -Not -Throw
77 | }
78 |
79 | It 'Should be able to call Get-DscConfiguration without throwing' {
80 | { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
81 | }
82 |
83 | #endregion
84 |
85 | It 'Should have set the resource and all the parameters should match' {
86 |
87 | $currentConfiguration = Get-DscConfiguration
88 |
89 | foreach ($parameter in $TestParameters.GetEnumerator())
90 | {
91 | Write-Verbose -Message "The $($parameter.Name) property should be set."
92 |
93 | if ($parameter.Name -eq 'Credential')
94 | {
95 | $appPool = Get-WebConfiguration -Filter '/system.applicationHost/applicationPools/add' |
96 | Where-Object -FilterScript {$_.name -eq $TestParameters['Name']}
97 |
98 | $appPool.processModel.userName |
99 | Should Be $TestParameters['Credential'].UserName
100 |
101 | $appPool.processModel.password |
102 | Should Be $TestParameters['Credential'].GetNetworkCredential().Password
103 | }
104 | else
105 | {
106 | $currentConfiguration."$($parameter.Name)" |
107 | Should Be $TestParameters[$parameter.Name]
108 | }
109 | }
110 |
111 | }
112 |
113 | It 'Actual configuration should match the desired configuration' {
114 | Test-DscConfiguration -Verbose | Should Be $true
115 | }
116 |
117 | }
118 |
119 | #endregion
120 | }
121 | finally
122 | {
123 | Restore-WebConfigurationWrapper -Name $tempName -Verbose
124 |
125 | Remove-WebConfigurationBackup -Name $tempName -Verbose
126 |
127 | Restore-TestEnvironment -TestEnvironment $script:testEnvironment -Verbose
128 | }
129 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebConfigPropertyCollection.config.ps1:
--------------------------------------------------------------------------------
1 |
2 | Configuration DSC_WebConfigPropertyCollection_Add
3 | {
4 | Import-DscResource -ModuleName WebAdministrationDsc
5 |
6 | node localhost
7 | {
8 | WebConfigPropertyCollection IntegrationTest
9 | {
10 | WebsitePath = $Node.WebsitePath
11 | Filter = $Node.Filter
12 | CollectionName = $Node.CollectionName
13 | ItemName = $Node.ItemName
14 | ItemKeyName = $Node.ItemKeyName
15 | ItemKeyValue = $Node.ItemKeyValue
16 | ItemPropertyName = $Node.ItemPropertyName
17 | ItemPropertyValue = $Node.ItemPropertyValueAdd
18 | Ensure = 'Present'
19 | }
20 | }
21 | }
22 |
23 | Configuration DSC_WebConfigPropertyCollection_Update
24 | {
25 | Import-DscResource -ModuleName WebAdministrationDsc
26 |
27 | node localhost
28 | {
29 | WebConfigPropertyCollection IntegrationTest
30 | {
31 | WebsitePath = $Node.WebsitePath
32 | Filter = $Node.Filter
33 | CollectionName = $Node.CollectionName
34 | ItemName = $Node.ItemName
35 | ItemKeyName = $Node.ItemKeyName
36 | ItemKeyValue = $Node.ItemKeyValue
37 | ItemPropertyName = $Node.ItemPropertyName
38 | ItemPropertyValue = $Node.ItemPropertyValueUpdate
39 | Ensure = 'Present'
40 | }
41 | }
42 | }
43 |
44 | Configuration DSC_WebConfigPropertyCollection_Remove
45 | {
46 | Import-DscResource -ModuleName WebAdministrationDsc
47 |
48 | node localhost
49 | {
50 | WebConfigPropertyCollection IntegrationTest
51 | {
52 | WebsitePath = $Node.WebsitePath
53 | Filter = $Node.Filter
54 | CollectionName = $Node.CollectionName
55 | ItemName = $Node.ItemName
56 | ItemKeyName = $Node.ItemKeyName
57 | ItemKeyValue = $Node.ItemKeyValue
58 | ItemPropertyName = $Node.ItemPropertyName
59 | Ensure = 'Absent'
60 | }
61 | }
62 | }
63 |
64 | Configuration DSC_WebConfigPropertyCollection_Integer
65 | {
66 | Import-DscResource -ModuleName WebAdministrationDsc
67 |
68 | node localhost
69 | {
70 | WebConfigPropertyCollection IntegrationTest
71 | {
72 | WebsitePath = $Node.WebsitePath
73 | Filter = $Node.IntegerFilter
74 | CollectionName = $Node.IntegerCollectionName
75 | ItemName = $Node.ItemName
76 | ItemKeyName = $Node.IntegerItemKeyName
77 | ItemKeyValue = $Node.IntegerItemKeyValue
78 | ItemPropertyName = $Node.IntegerItemPropertyName
79 | ItemPropertyValue = $Node.IntegerItemPropertyValue
80 | Ensure = 'Present'
81 | }
82 | }
83 | }
84 |
85 | Configuration DSC_WebConfigPropertyCollection_SingleItemAdd
86 | {
87 | Import-DscResource -ModuleName WebAdministrationDsc
88 |
89 | node localhost
90 | {
91 | WebConfigPropertyCollection IntegrationTest
92 | {
93 | WebsitePath = $Node.WebsitePath
94 | Filter = $Node.SingleItemFilter
95 | CollectionName = $Node.SingleItemCollectionName
96 | ItemName = $Node.ItemName
97 | ItemKeyName = $Node.SingleItemKeyName
98 | ItemKeyValue = $Node.SingleItemKeyValue
99 | ItemPropertyName = $Node.SingleItemPropertyName
100 | ItemPropertyValue = $Node.SingleItemPropertyValue
101 | Ensure = 'Present'
102 | }
103 | }
104 | }
105 |
106 | Configuration DSC_WebConfigPropertyCollection_SingleItemRemove
107 | {
108 | Import-DscResource -ModuleName WebAdministrationDsc
109 |
110 | node localhost
111 | {
112 | WebConfigPropertyCollection IntegrationTest
113 | {
114 | WebsitePath = $Node.WebsitePath
115 | Filter = $Node.SingleItemFilter
116 | CollectionName = $Node.SingleItemCollectionName
117 | ItemName = $Node.ItemName
118 | ItemKeyName = $Node.SingleItemKeyName
119 | ItemKeyValue = $Node.SingleItemKeyValue
120 | ItemPropertyName = $Node.SingleItemPropertyName
121 | Ensure = 'Absent'
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_SslSettings.Integration.Tests.ps1:
--------------------------------------------------------------------------------
1 | $script:dscModuleName = 'WebAdministrationDsc'
2 | $script:dscResourceName = 'DSC_SslSettings'
3 |
4 | try
5 | {
6 | Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
7 | }
8 | catch [System.IO.FileNotFoundException]
9 | {
10 | throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
11 | }
12 |
13 | $script:testEnvironment = Initialize-TestEnvironment `
14 | -DSCModuleName $script:dscModuleName `
15 | -DSCResourceName $script:dscResourceName `
16 | -ResourceType 'Mof' `
17 | -TestType 'Integration'
18 |
19 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelper\CommonTestHelper.psm1') -Force
20 |
21 | $tempName = "$($script:dscResourceName)_" + (Get-Date).ToString('yyyyMMdd_HHmmss')
22 |
23 | try
24 | {
25 | $null = Backup-WebConfiguration -Name $tempName
26 |
27 | # Now that WebAdministrationDsc should be discoverable load the configuration data
28 | $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
29 | . $configFile
30 |
31 | $DSCConfig = Import-LocalizedData -BaseDirectory $PSScriptRoot -FileName "$($script:dscResourceName).config.psd1"
32 |
33 | #region HelperFunctions
34 |
35 | # Function needed to test SslFlags
36 | function Get-SslFlags
37 | {
38 | [CmdletBinding()]
39 | param
40 | (
41 | [Parameter(Mandatory = $true)]
42 | [String] $Website
43 |
44 | )
45 |
46 | Get-WebConfiguration `
47 | -PSPath IIS:\Sites `
48 | -Location "$Website" `
49 | -Filter 'system.webserver/security/access' | `
50 | ForEach-Object { $_.sslFlags }
51 | }
52 |
53 | #endregion
54 |
55 | # Create a new website for the SSLSettings
56 |
57 | New-Website -Name $DSCConfig.AllNodes.Website `
58 | -Id 200 `
59 | -PhysicalPath $DSCConfig.AllNodes.PhysicalPath `
60 | -ApplicationPool $DSCConfig.AllNodes.AppPool `
61 | -SslFlags $DSCConfig.AllNodes.SslFlags `
62 | -Port $DSCConfig.AllNodes.HTTPSPort `
63 | -IPAddress '*' `
64 | -HostHeader $DSCConfig.AllNodes.HTTPSHostname `
65 | -Ssl `
66 | -Force `
67 | -ErrorAction Stop
68 |
69 | Describe "$($script:dscResourceName)_Present" {
70 | #region DEFAULT TESTS
71 | It 'Should compile without throwing' {
72 | {
73 | Invoke-Expression -Command "$($script:dscResourceName)_Present -ConfigurationData `$DSCConfig -OutputPath `$TestDrive"
74 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
75 | } | Should not throw
76 | }
77 |
78 | It 'should be able to call Get-DscConfiguration without throwing' {
79 | { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
80 | }
81 | #endregion
82 |
83 | It 'Should add SSLBindings to a Website' -test {
84 |
85 | Invoke-Expression -Command "$($script:dscResourceName)_Present -ConfigurationData `$DSCConfg -OutputPath `$TestDrive"
86 |
87 | # Test SslFlags
88 | Get-SslFlags -Website $DSCConfig.AllNodes.Website | Should Be $DSCConfig.AllNodes.Bindings
89 |
90 | }
91 |
92 | }
93 |
94 | Describe "$($script:dscResourceName)_Absent" {
95 | #region DEFAULT TESTS
96 | It 'Should compile without throwing' {
97 | {
98 | Invoke-Expression -Command "$($script:dscResourceName)_Absent -ConfigurationData `$DSCConfig -OutputPath `$TestDrive"
99 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
100 | } | Should not throw
101 | }
102 |
103 | It 'should be able to call Get-DscConfiguration without throwing' {
104 | { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
105 | }
106 | #endregion
107 |
108 | It 'Should remove SSLBindings from a Website' -test {
109 |
110 | Invoke-Expression -Command "$($script:dscResourceName)_Absent -ConfigurationData `$DSCConfg -OutputPath `$TestDrive"
111 |
112 | # Test SslFlags
113 | Get-SslFlags -Website $DSCConfig.AllNodes.Website | Should BeNullOrEmpty
114 |
115 | }
116 |
117 | }
118 |
119 | }
120 | finally
121 | {
122 | Restore-WebConfigurationWrapper -Name $tempName -Verbose
123 |
124 | Remove-WebConfigurationBackup -Name $tempName -Verbose
125 |
126 | Restore-TestEnvironment -TestEnvironment $script:testEnvironment -Verbose
127 | }
128 |
--------------------------------------------------------------------------------
/source/Examples/Resources/Sample_EndToEndWebAdministration.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .DESCRIPTION
3 | This example shows how to use the WebAdministrationDsc in an end to end scenario.
4 | #>
5 | configuration Sample_EndToEndWebAdministration
6 | {
7 | param
8 | (
9 | # Target nodes to apply the configuration
10 | [Parameter()]
11 | [String[]]
12 | $NodeName='localhost',
13 |
14 | [Parameter(Mandatory=$true)]
15 | [ValidateNotNullOrEmpty()]
16 | [String]
17 | $WebAppPoolName,
18 |
19 | [Parameter(Mandatory=$true)]
20 | [ValidateNotNullOrEmpty()]
21 | [String]
22 | $WebSiteName,
23 |
24 | [Parameter(Mandatory=$true)]
25 | [ValidateNotNullOrEmpty()]
26 | [String]
27 | $PhysicalPathWebSite,
28 |
29 | [Parameter(Mandatory=$true)]
30 | [ValidateNotNullOrEmpty()]
31 | [String]
32 | $WebApplicationName,
33 |
34 | [Parameter(Mandatory=$true)]
35 | [ValidateNotNullOrEmpty()]
36 | [String]
37 | $PhysicalPathWebApplication,
38 |
39 | [Parameter(Mandatory=$true)]
40 | [ValidateNotNullOrEmpty()]
41 | [String]
42 | $WebVirtualDirectoryName,
43 |
44 | [Parameter(Mandatory=$true)]
45 | [ValidateNotNullOrEmpty()]
46 | [String]
47 | $PhysicalPathVirtualDir,
48 |
49 | [Parameter(Mandatory=$true)]
50 | [ValidateNotNullOrEmpty()]
51 | [String]
52 | $Port
53 |
54 | )
55 | Import-DscResource -ModuleName PSDesiredStateConfiguration
56 | Import-DscResource -ModuleName WebAdministrationDsc
57 |
58 | node $NodeName
59 | {
60 | # Create a Web Application Pool
61 | WebAppPool NewWebAppPool
62 | {
63 | Name = $WebAppPoolName
64 | Ensure = "Present"
65 | State = "Started"
66 | }
67 |
68 | #Create physical path website
69 | file NewWebsitePath
70 | {
71 | DestinationPath = $PhysicalPathWebSite
72 | Type = "Directory"
73 | Ensure = "Present"
74 | }
75 |
76 | #Create physical path web application
77 | file NewWebApplicationPath
78 | {
79 | DestinationPath = $PhysicalPathWebApplication
80 | Type = "Directory"
81 | Ensure = "Present"
82 | }
83 |
84 | #Create physical path virtual directory
85 | file NewVirtualDirectoryPath
86 | {
87 | DestinationPath = $PhysicalPathVirtualDir
88 | Type = "Directory"
89 | Ensure = "Present"
90 | }
91 |
92 | #Create a New Website with Port
93 | WebSite NewWebSite
94 | {
95 | Name = $WebSiteName
96 | Ensure = "Present"
97 | BindingInfo = DSC_WebBindingInformation
98 | {
99 | Protocol = "http"
100 | Port = $Port
101 | }
102 |
103 | PhysicalPath = $PhysicalPathWebSite
104 | State = "Started"
105 | DependsOn = @("[WebAppPool]NewWebAppPool", "[File]NewWebsitePath")
106 | }
107 |
108 | #Create a new Web Application
109 | WebApplication NewWebApplication
110 | {
111 | Name = $WebApplicationName
112 | Website = $WebSiteName
113 | WebAppPool = $WebAppPoolName
114 | PhysicalPath = $PhysicalPathWebApplication
115 | Ensure = "Present"
116 | DependsOn = @("[WebSite]NewWebSite", "[File]NewWebApplicationPath")
117 | }
118 |
119 | #Create a new virtual Directory
120 | WebVirtualDirectory NewVirtualDir
121 | {
122 | Name = $WebVirtualDirectoryName
123 | Website = $WebSiteName
124 | WebApplication = $WebApplicationName
125 | PhysicalPath = $PhysicalPathVirtualDir
126 | Ensure = "Present"
127 | DependsOn = @("[WebApplication]NewWebApplication", "[File]NewVirtualDirectoryPath")
128 | }
129 |
130 | #Create an empty web.config file
131 | File CreateWebConfig
132 | {
133 | DestinationPath = $PhysicalPathWebSite + "\web.config"
134 | Contents = "
135 |
136 | "
137 | Ensure = "Present"
138 | DependsOn = @("[WebVirtualDirectory]NewVirtualDir")
139 | }
140 |
141 | #Add a webApplicationHandler
142 | WebApplicationHandler WebHandlerTest
143 | {
144 | Name = 'ATest-WebHandler'
145 | Path = '*'
146 | Verb = '*'
147 | Modules = 'IsapiModule'
148 | RequireAccess = 'None'
149 | ScriptProcessor = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
150 | ResourceType = 'Unspecified'
151 | AllowPathInfo = $false
152 | ResponseBufferLimit = 0
153 | PhysicalHandlerPath = $PhysicalPathWebApplication
154 | type = $null
155 | PreCondition = $null
156 | Location = 'Default Web Site/TestDir'
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_SslSettings/DSC_SslSettings.psm1:
--------------------------------------------------------------------------------
1 | $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
2 |
3 | # Import the WebAdministrationDsc Common Modules
4 | Import-Module -Name (Join-Path -Path $modulePath `
5 | -ChildPath (Join-Path -Path 'WebAdministrationDsc.Common' `
6 | -ChildPath 'WebAdministrationDsc.Common.psm1'))
7 |
8 | Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common')
9 |
10 | # Import Localization Strings
11 | $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
12 |
13 | <#
14 | .SYNOPSIS
15 | This will return a hashtable of results including Name, Bindings, and Ensure
16 | #>
17 | function Get-TargetResource
18 | {
19 | [CmdletBinding()]
20 | [OutputType([System.Collections.Hashtable])]
21 | param
22 | (
23 | [Parameter(Mandatory = $true)]
24 | [String] $Name,
25 |
26 | [Parameter(Mandatory = $true)]
27 | [AllowEmptyString()]
28 | [ValidateSet('','Ssl','SslNegotiateCert','SslRequireCert','Ssl128')]
29 | [String[]] $Bindings
30 | )
31 |
32 | Assert-Module -ModuleName WebAdministration
33 |
34 | $ensure = 'Absent'
35 |
36 | try
37 | {
38 | $params = @{
39 | PSPath = 'MACHINE/WEBROOT/APPHOST'
40 | Location = $Name
41 | Filter = 'system.webServer/security/access'
42 | Name = 'sslFlags'
43 | }
44 |
45 | $sslSettings = Get-WebConfigurationProperty @params
46 |
47 | # If SSL is configured at all this will be a String else
48 | # it willl be a configuration object.
49 | if ($sslSettings.GetType().FullName -eq 'System.String')
50 | {
51 | $Bindings = $sslSettings.Split(',')
52 | $ensure = 'Present'
53 | }
54 | }
55 | catch [Exception]
56 | {
57 | $errorMessage = $script:localizedData.UnableToFindConfig
58 | New-TerminatingError -ErrorId 'UnableToFindConfig'`
59 | -ErrorMessage $errorMessage`
60 | -ErrorCategory 'InvalidResult'
61 | }
62 |
63 | Write-Verbose -Message $script:localizedData.VerboseGetTargetResource
64 |
65 | return @{
66 | Name = $Name
67 | Bindings = $Bindings
68 | Ensure = $ensure
69 | }
70 | }
71 |
72 | <#
73 | .SYNOPSIS
74 | This will update the desired state based on the Bindings passed in
75 | #>
76 | function Set-TargetResource
77 | {
78 | [CmdletBinding()]
79 | param
80 | (
81 | [Parameter(Mandatory = $true)]
82 | [String] $Name,
83 |
84 | [Parameter(Mandatory = $true)]
85 | [AllowEmptyString()]
86 | [ValidateSet('','Ssl','SslNegotiateCert','SslRequireCert','Ssl128')]
87 | [String[]] $Bindings,
88 |
89 | [Parameter()]
90 | [ValidateSet('Present','Absent')]
91 | [String] $Ensure = 'Present'
92 | )
93 |
94 | Assert-Module -ModuleName WebAdministration
95 |
96 | if ($Ensure -eq 'Absent' -or $Bindings.toLower().Contains('none'))
97 | {
98 | $params = @{
99 | PSPath = 'MACHINE/WEBROOT/APPHOST'
100 | Location = $Name
101 | Filter = 'system.webServer/security/access'
102 | Name = 'sslFlags'
103 | Value = ''
104 | }
105 |
106 | Write-Verbose -Message ($script:localizedData.SettingsslConfig -f $Name, 'None')
107 | Set-WebConfigurationProperty @params
108 | }
109 |
110 | else
111 | {
112 | $sslBindings = $Bindings -join ','
113 | $params = @{
114 | PSPath = 'MACHINE/WEBROOT/APPHOST'
115 | Location = $Name
116 | Filter = 'system.webServer/security/access'
117 | Name = 'sslFlags'
118 | Value = $sslBindings
119 | }
120 |
121 | Write-Verbose -Message ($script:localizedData.SettingsslConfig -f $Name, $params.Value)
122 | Set-WebConfigurationProperty @params
123 | }
124 | }
125 |
126 | <#
127 | .SYNOPSIS
128 | This tests the desired state. If the state is not correct it will return $false.
129 | If the state is correct it will return $true
130 | #>
131 | function Test-TargetResource
132 | {
133 | [CmdletBinding()]
134 | [OutputType([System.Boolean])]
135 | param
136 | (
137 | [Parameter(Mandatory = $true)]
138 | [String] $Name,
139 |
140 | [Parameter(Mandatory = $true)]
141 | [AllowEmptyString()]
142 | [ValidateSet('','Ssl','SslNegotiateCert','SslRequireCert','Ssl128')]
143 | [String[]] $Bindings,
144 |
145 | [Parameter()]
146 | [ValidateSet('Present','Absent')]
147 | [String] $Ensure = 'Present'
148 | )
149 |
150 | $sslSettings = Get-TargetResource -Name $Name -Bindings $Bindings
151 |
152 | if ($Ensure -eq 'Present' -and $sslSettings.Ensure -eq 'Present')
153 | {
154 | $sslComp = Compare-Object -ReferenceObject $Bindings `
155 | -DifferenceObject $sslSettings.Bindings `
156 | -PassThru
157 | if ($null -eq $sslComp)
158 | {
159 | Write-Verbose -Message ($script:localizedData.sslBindingsCorrect -f $Name)
160 | return $true;
161 | }
162 | }
163 |
164 | if ($Ensure -eq 'Absent' -and $sslSettings.Ensure -eq 'Absent')
165 | {
166 | Write-Verbose -Message ($script:localizedData.sslBindingsAbsent -f $Name)
167 | return $true;
168 | }
169 |
170 | return $false;
171 | }
172 |
173 | Export-ModuleMember -Function *-TargetResource
174 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebAppPoolDefaults.Integration.Tests.ps1:
--------------------------------------------------------------------------------
1 |
2 | $script:dscModuleName = 'WebAdministrationDsc'
3 | $script:dscResourceName = 'DSC_WebAppPoolDefaults'
4 |
5 | try
6 | {
7 | Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
8 | }
9 | catch [System.IO.FileNotFoundException]
10 | {
11 | throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
12 | }
13 |
14 | $script:testEnvironment = Initialize-TestEnvironment `
15 | -DSCModuleName $script:dscModuleName `
16 | -DSCResourceName $script:dscResourceName `
17 | -ResourceType 'Mof' `
18 | -TestType 'Integration'
19 |
20 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelper\CommonTestHelper.psm1') -Force
21 |
22 | $tempName = "$($script:dscResourceName)_" + (Get-Date).ToString("yyyyMMdd_HHmmss")
23 |
24 | try
25 | {
26 | # some constants
27 | [string]$constPsPath = 'MACHINE/WEBROOT/APPHOST'
28 | [string]$constAPDFilter = 'system.applicationHost/applicationPools/applicationPoolDefaults'
29 | [string]$constSiteFilter = 'system.applicationHost/sites/'
30 |
31 | $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
32 | . $ConfigFile
33 |
34 | $null = Backup-WebConfiguration -Name $tempName
35 |
36 | function Get-SiteValue([string]$path,[string]$name)
37 | {
38 | return (Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/$path" -name $name).value
39 | }
40 |
41 | Describe "$($script:dscResourceName)_Integration" {
42 | It 'Should compile without throwing' {
43 | {
44 | Invoke-Expression -Command "$($script:dscResourceName)_Config -OutputPath `$TestDrive"
45 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
46 | } | Should not throw
47 | }
48 |
49 | It 'Should be able to call Get-DscConfiguration without throwing' {
50 | { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
51 | }
52 |
53 | It 'Changing ManagedRuntimeVersion' {
54 | {
55 | # get the current value
56 | [string] $originalValue = (Get-WebConfigurationProperty -pspath $constPsPath -filter $constAPDFilter -name managedRuntimeVersion)
57 |
58 | # We are using environment variables here, because a inline PowerShell variable was empty after executing Start-DscConfiguration
59 |
60 | # change the value to something else
61 | if ($originalValue -eq 'v4.0')
62 | {
63 | $env:PesterManagedRuntimeVersion = 'v2.0'
64 | }
65 | else
66 | {
67 | $env:PesterManagedRuntimeVersion = 'v4.0'
68 | }
69 |
70 | Invoke-Expression -Command "$($script:dscResourceName)_ManagedRuntimeVersion -OutputPath `$TestDrive"
71 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
72 | } | should not throw
73 |
74 | # get the configured value again
75 | $changedValue = (Get-WebConfigurationProperty -pspath $constPsPath -filter $constAPDFilter -name managedRuntimeVersion).Value
76 |
77 | # compare it to the one we just tried to set.
78 | $changedValue | should be $env:PesterManagedRuntimeVersion
79 | }
80 |
81 | It 'Changing IdentityType' {
82 | # get the current value
83 | [string] $originalValue = (Get-WebConfigurationProperty `
84 | -PSPath $constPsPath `
85 | -Filter $constAPDFilter/processModel `
86 | -Name identityType)
87 |
88 | if ($originalValue -eq 'ApplicationPoolIdentity')
89 | {
90 | $env:PesterApplicationPoolIdentity = 'LocalService'
91 | }
92 | else
93 | {
94 | $env:PesterApplicationPoolIdentity = 'ApplicationPoolIdentity'
95 | }
96 |
97 | # Compile the MOF File
98 | {
99 | Invoke-Expression -Command "$($script:dscResourceName)_AppPoolIdentityType -OutputPath `$TestDrive"
100 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
101 | } | Should not throw
102 |
103 | $changedValue = (Get-WebConfigurationProperty -PSPath $constPsPath -Filter $constAPDFilter/processModel -Name identityType)
104 |
105 | $changedValue | Should Be $env:PesterApplicationPoolIdentity
106 | }
107 |
108 |
109 | It 'Changing LogFormat' {
110 | [string] $originalValue = Get-SiteValue 'logFile' 'logFormat'
111 |
112 | if ($originalValue -eq 'W3C')
113 | {
114 | $env:PesterLogFormat = 'IIS'
115 | }
116 | else
117 | {
118 | $env:PesterLogFormat = 'W3C'
119 | }
120 |
121 | # Compile the MOF File
122 | {
123 | Invoke-Expression -Command "$($script:dscResourceName)_LogFormat -OutputPath `$TestDrive"
124 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
125 | } | Should not throw
126 |
127 | $changedValue = Get-SiteValue 'logFile' 'logFormat'
128 |
129 | $changedValue | Should Be $env:PesterALogFormat
130 | }
131 |
132 | It 'Changing Default AppPool' {
133 | # get the current value
134 |
135 | [string] $originalValue = Get-SiteValue 'applicationDefaults' 'applicationPool'
136 |
137 | $env:PesterDefaultPool = 'DefaultAppPool'
138 | # Compile the MOF File
139 | {
140 | Invoke-Expression -Command "$($script:dscResourceName)_DefaultPool -OutputPath `$TestDrive"
141 | Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
142 | } | Should not throw
143 |
144 | $changedValue = Get-SiteValue 'applicationDefaults' 'applicationPool'
145 | $changedValue | should be $env:PesterDefaultPool
146 | }
147 |
148 | }
149 | }
150 | finally
151 | {
152 | Restore-WebConfigurationWrapper -Name $tempName -Verbose
153 |
154 | Remove-WebConfigurationBackup -Name $tempName -Verbose
155 |
156 | Restore-TestEnvironment -TestEnvironment $script:testEnvironment -Verbose
157 | }
158 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_IISFeatureDelegation.Integration.Tests.ps1:
--------------------------------------------------------------------------------
1 | $script:dscModuleName = 'WebAdministrationDsc'
2 | $script:dscResourceName = 'DSC_IisFeatureDelegation'
3 |
4 | try
5 | {
6 | Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
7 | }
8 | catch [System.IO.FileNotFoundException]
9 | {
10 | throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
11 | }
12 |
13 | $script:testEnvironment = Initialize-TestEnvironment `
14 | -DSCModuleName $script:dscModuleName `
15 | -DSCResourceName $script:dscResourceName `
16 | -ResourceType 'Mof' `
17 | -TestType 'Integration'
18 |
19 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelper\CommonTestHelper.psm1') -Force
20 |
21 | $tempName = "$($script:dscResourceName)_" + (Get-Date).ToString('yyyyMMdd_HHmmss')
22 |
23 | try
24 | {
25 | #region Integration Tests
26 | $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
27 | . $configFile
28 |
29 | $null = Backup-WebConfiguration -Name $tempName
30 |
31 | Describe "$($script:dscResourceName)_Integration" {
32 | $startDscConfigurationParameters = @{
33 | Path = $TestDrive
34 | ComputerName = 'localhost'
35 | Wait = $true
36 | Verbose = $true
37 | Force = $true
38 | ErrorAction = 'Stop'
39 | }
40 |
41 | Context 'Allow Feature Delegation'{
42 | $currentOverrideMode = (Get-WebConfiguration -Filter '/system.web/customErrors' -Pspath iis:\ -Metadata).Metadata.effectiveOverrideMode
43 | $configurationName = "$($script:dscResourceName)_AllowDelegation"
44 | #For this test we want the target section to start at effectiveOverrideMode 'Deny'
45 | If ( $currentOverrideMode -ne 'Deny')
46 | {
47 | Set-WebConfiguration -Filter '/system.web/customErrors' -PsPath 'MACHINE/WEBROOT/APPHOST' -Metadata 'overrideMode' -Value 'Deny'
48 | }
49 |
50 | It 'Should compile and apply the MOF without throwing' {
51 | {
52 | & $configurationName -OutputPath $TestDrive
53 |
54 | Start-DscConfiguration @startDscConfigurationParameters
55 | } | Should Not Throw
56 | }
57 |
58 | It 'Should be set to Allow Feature Delegation'{
59 | (Get-WebConfiguration -Filter '/system.web/customErrors' -Pspath 'MACHINE/WEBROOT/APPHOST' -Metadata).Metadata.effectiveOverrideMode | Should Be 'Allow'
60 | }
61 |
62 | It 'Should be able to call Get-DscConfiguration without throwing' {
63 | { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
64 | }
65 |
66 | It 'Should return $true for Test-DscConfiguration' {
67 | Test-DscConfiguration | Should Be $true
68 | }
69 |
70 | It 'Should have set the resource and all the parameters should match' {
71 | $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
72 | $_.ConfigurationName -eq $configurationName
73 | } | Where-Object -FilterScript {
74 | $_.ResourceId -eq '[IisFeatureDelegation]AllowDelegation'
75 | }
76 |
77 | $resourceCurrentState.Filter | Should Be '/system.web/customErrors'
78 | $resourceCurrentState.OverrideMode | Should Be 'Allow'
79 | $resourceCurrentState.Path | Should Be 'MACHINE/WEBROOT/APPHOST'
80 | }
81 | }
82 |
83 | Context 'Deny Feature Delegation'{
84 | $currentOverrideMode = (Get-WebConfiguration -Filter 'system.webServer/defaultDocument' -Pspath 'MACHINE/WEBROOT/APPHOST' -Metadata).Metadata.effectiveOverrideMode
85 | $configurationName = "$($script:dscResourceName)_DenyDelegation"
86 | #For this test we want the target section to start at effectiveOverrideMode 'Allow'
87 | If ( $currentOverrideMode -ne 'Allow')
88 | {
89 | Set-WebConfiguration -Filter 'system.webServer/defaultDocument' -PsPath 'MACHINE/WEBROOT/APPHOST' -Metadata 'overrideMode' -Value 'Allow'
90 | }
91 |
92 | $siteName = (Get-ChildItem -Path iis:\sites | Select-Object -First 1).Name
93 | $testAddWebConfigurationProperty = @{
94 | PSPath = "MACHINE/WEBROOT/APPHOST/$siteName"
95 | Filter = 'system.webServer/defaultDocument/files'
96 | Name = '.'
97 | Value = 'pesterpage.cgi'
98 | }
99 |
100 | It 'Should compile and apply the MOF without throwing' {
101 | {
102 | & $configurationName -OutputPath $TestDrive
103 |
104 | Start-DscConfiguration @startDscConfigurationParameters
105 | } | Should Not Throw
106 | }
107 |
108 | It 'Should be able to call Get-DscConfiguration without throwing' {
109 | { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
110 | }
111 |
112 | It 'Should return $true for Test-DscConfiguration' {
113 | Test-DscConfiguration | Should Be $true
114 | }
115 |
116 | It 'Should Deny Feature Delegation' {
117 | { Add-WebConfigurationProperty @testAddWebConfigurationProperty } | Should Throw
118 | }
119 |
120 | It 'Should have set the resource and all the parameters should match' {
121 | $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
122 | $_.ConfigurationName -eq $configurationName
123 | } | Where-Object -FilterScript {
124 | $_.ResourceId -eq '[IisFeatureDelegation]DenyDelegation'
125 | }
126 |
127 | $resourceCurrentState.Filter | Should Be '/system.webServer/defaultDocument'
128 | $resourceCurrentState.OverrideMode | Should Be 'Deny'
129 | $resourceCurrentState.Path | Should Be 'MACHINE/WEBROOT/APPHOST'
130 | }
131 | }
132 | #endregion
133 | }
134 | }
135 | finally
136 | {
137 | Restore-WebConfigurationWrapper -Name $tempName -Verbose
138 |
139 | Remove-WebConfigurationBackup -Name $tempName -Verbose
140 |
141 | Restore-TestEnvironment -TestEnvironment $script:testEnvironment -Verbose
142 | }
143 |
--------------------------------------------------------------------------------
/source/DSCResources/DSC_IisFeatureDelegation/DSC_IisFeatureDelegation.psm1:
--------------------------------------------------------------------------------
1 | $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
2 |
3 | # Import the WebAdministrationDsc Common Modules
4 | Import-Module -Name (Join-Path -Path $modulePath `
5 | -ChildPath (Join-Path -Path 'WebAdministrationDsc.Common' `
6 | -ChildPath 'WebAdministrationDsc.Common.psm1'))
7 |
8 | Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common')
9 |
10 | # Import Localization Strings
11 | $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
12 |
13 | <#
14 | .SYNOPSIS
15 | This will return a hashtable of results
16 |
17 | .PARAMETER Filter
18 | Specifies the IIS configuration section to lock or unlock.
19 |
20 | .PARAMETER Path
21 | Specifies the configuration path. This can be either an IIS configuration path in the format
22 | computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
23 |
24 | .PARAMETER OverrideMode
25 | Determines whether to lock or unlock the specified section.
26 | #>
27 | function Get-TargetResource
28 | {
29 | [CmdletBinding()]
30 | [OutputType([Hashtable])]
31 | param
32 | (
33 | [Parameter(Mandatory = $true)]
34 | [ValidateNotNullOrEmpty()]
35 | [String]
36 | $Filter,
37 |
38 | [Parameter(Mandatory = $true)]
39 | [ValidateNotNullOrEmpty()]
40 | [ValidateSet('Allow', 'Deny')]
41 | [String]
42 | $OverrideMode,
43 |
44 | [Parameter(Mandatory = $true)]
45 | [ValidateNotNullOrEmpty()]
46 | [String]
47 | $Path
48 | )
49 |
50 | [String] $currentOverrideMode = Get-OverrideMode -Filter $Filter -Path $Path
51 |
52 | Write-Verbose -Message $script:localizedData.VerboseGetTargetResource
53 |
54 | return @{
55 | Path = $Path
56 | Filter = $Filter
57 | OverrideMode = $currentOverrideMode
58 | }
59 | }
60 |
61 | <#
62 | .SYNOPSIS
63 | This will set the resource to the desired state.
64 |
65 | .PARAMETER Filter
66 | Specifies the IIS configuration section to lock or unlock.
67 |
68 | .PARAMETER Path
69 | Specifies the configuration path. This can be either an IIS configuration path in the format
70 | computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
71 |
72 | .PARAMETER OverrideMode
73 | Determines whether to lock or unlock the specified section.
74 | #>
75 | function Set-TargetResource
76 | {
77 | [CmdletBinding()]
78 | param
79 | (
80 | [Parameter(Mandatory = $true)]
81 | [ValidateNotNullOrEmpty()]
82 | [String]
83 | $Filter,
84 |
85 | [Parameter(Mandatory = $true)]
86 | [ValidateNotNullOrEmpty()]
87 | [ValidateSet('Allow', 'Deny')]
88 | [String]
89 | $OverrideMode,
90 |
91 | [Parameter(Mandatory = $true)]
92 | [ValidateNotNullOrEmpty()]
93 | [String]
94 | $Path
95 | )
96 |
97 | Write-Verbose -Message ( $script:localizedData.VerboseSetTargetResource -f $Filter, $OverrideMode )
98 |
99 | Set-WebConfiguration -Filter $Filter -PsPath $Path -Metadata 'overrideMode' -Value $OverrideMode
100 | }
101 |
102 | <#
103 | .SYNOPSIS
104 | This will return whether the resource is in desired state.
105 |
106 | .PARAMETER Filter
107 | Specifies the IIS configuration section to lock or unlock.
108 |
109 | .PARAMETER OverrideMode
110 | Determines whether to lock or unlock the specified section.
111 |
112 | .PARAMETER Path
113 | Specifies the configuration path. This can be either an IIS configuration path in the format
114 | computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
115 |
116 | #>
117 | function Test-TargetResource
118 | {
119 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "",
120 | Justification = 'Verbose messaging in helper function')]
121 | [CmdletBinding()]
122 | [OutputType([System.Boolean])]
123 | param
124 | (
125 | [Parameter(Mandatory = $true)]
126 | [ValidateNotNullOrEmpty()]
127 | [String]
128 | $Filter,
129 |
130 | [Parameter(Mandatory = $true)]
131 | [ValidateNotNullOrEmpty()]
132 | [ValidateSet('Allow', 'Deny')]
133 | [String]
134 | $OverrideMode,
135 |
136 | [Parameter(Mandatory = $true)]
137 | [ValidateNotNullOrEmpty()]
138 | [String]
139 | $Path
140 | )
141 |
142 | [String] $currentOverrideMode = Get-OverrideMode -Filter $Filter -Path $Path
143 |
144 | if ($currentOverrideMode -eq $OverrideMode)
145 | {
146 | return $true
147 | }
148 |
149 | return $false
150 | }
151 |
152 | #region Helper functions
153 | <#
154 | .SYNOPSIS
155 | This will return the current override mode for the specified configsection.
156 |
157 | .PARAMETER Filter
158 | Specifies the IIS configuration section.
159 |
160 | .PARAMETER Path
161 | Specifies the configuration path. This can be either an IIS configuration path in the format
162 | computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
163 |
164 | #>
165 | function Get-OverrideMode
166 | {
167 | [CmdletBinding()]
168 | [OutputType([System.String])]
169 | param
170 | (
171 | [Parameter(Mandatory = $true)]
172 | [ValidateNotNullOrEmpty()]
173 | [String]
174 | $Filter,
175 |
176 | [Parameter(Mandatory = $true)]
177 | [ValidateNotNullOrEmpty()]
178 | [String]
179 | $Path
180 | )
181 |
182 | Assert-Module -ModuleName WebAdministration
183 |
184 | Write-Verbose -Message ( $script:localizedData.GetOverrideMode -f $Filter )
185 |
186 | $webConfig = Get-WebConfiguration -PsPath $Path -Filter $Filter -Metadata
187 |
188 | $currentOverrideMode = $webConfig.Metadata.effectiveOverrideMode
189 |
190 | if ($currentOverrideMode -notmatch "^(Allow|Deny)$")
191 | {
192 | $errorMessage = $($script:localizedData.UnableToGetConfig) -f $Filter
193 | New-TerminatingError -ErrorId UnableToGetConfig `
194 | -ErrorMessage $errorMessage `
195 | -ErrorCategory:InvalidResult
196 | }
197 |
198 | return $currentOverrideMode
199 | }
200 | #endregion
201 |
202 | Export-ModuleMember -function *-TargetResource
203 |
--------------------------------------------------------------------------------
/tests/Integration/DSC_WebApplicationHandler.config.ps1:
--------------------------------------------------------------------------------
1 | $ConfigurationData = @{
2 | AllNodes = @(
3 | @{
4 | NodeName = 'LocalHost'
5 | Path = 'MACHINE/WEBROOT/APPHOST'
6 | Location = 'Webtest'
7 | Name = 'ATest-WebHandler'
8 | PhysicalHandlerPath = '*'
9 | Verb = '*'
10 | Modules = 'IsapiModule'
11 | RequireAccess = 'None'
12 | ScriptProcessor = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
13 | ResourceType = 'Unspecified'
14 | AllowPathInfo = $false
15 | ResponseBufferLimit = 0
16 | PhysicalPath = "C:\Temp"
17 | Type = 'SampleHandler'
18 | PreCondition = 'IsapiModule'
19 | VirtualDirectoryName = 'TestDir'
20 | }
21 | )
22 | }
23 |
24 | Configuration DSC_WebApplicationHandler_AddHandler
25 | {
26 | Import-DSCResource -ModuleName WebAdministrationDsc
27 |
28 | Node 'localhost'
29 | {
30 | WebApplicationHandler WebHandlerTest
31 | {
32 | Path = $ConfigurationData.AllNodes.Path
33 | Name = $ConfigurationData.AllNodes.Name
34 | PhysicalHandlerPath = $ConfigurationData.AllNodes.PhysicalHandlerPath
35 | Verb = $ConfigurationData.AllNodes.Verb
36 | Modules = $ConfigurationData.AllNodes.Modules
37 | RequireAccess = $ConfigurationData.AllNodes.RequireAccess
38 | ScriptProcessor = $ConfigurationData.AllNodes.ScriptProcessor
39 | ResourceType = $ConfigurationData.AllNodes.ResourceType
40 | AllowPathInfo = $ConfigurationData.AllNodes.AllowPathInfo
41 | ResponseBufferLimit = $ConfigurationData.AllNodes.ResponseBufferLimit
42 | Type = $ConfigurationData.AllNodes.Type
43 | PreCondition = $ConfigurationData.AllNodes.PreCondition
44 | Location = "Default Web Site/$($ConfigurationData.AllNodes.VirtualDirectoryName)"
45 | Ensure = 'Present'
46 | }
47 | }
48 | }
49 |
50 | Configuration DSC_WebApplicationHandler_RemoveHandler
51 | {
52 | Import-DSCResource -ModuleName PSDesiredStateConfiguration
53 | Import-DSCResource -ModuleName WebAdministrationDsc
54 |
55 | Node 'localhost'
56 | {
57 | WebApplicationHandler WebHandlerTest
58 | {
59 | Path = $ConfigurationData.AllNodes.Path
60 | Name = $ConfigurationData.AllNodes.Name
61 | PhysicalHandlerPath = $ConfigurationData.AllNodes.PhysicalHandlerPath
62 | Verb = $ConfigurationData.AllNodes.Verb
63 | Modules = $ConfigurationData.AllNodes.Modules
64 | RequireAccess = $ConfigurationData.AllNodes.RequireAccess
65 | ScriptProcessor = $ConfigurationData.AllNodes.ScriptProcessor
66 | ResourceType = $ConfigurationData.AllNodes.ResourceType
67 | AllowPathInfo = $ConfigurationData.AllNodes.AllowPathInfo
68 | ResponseBufferLimit = $ConfigurationData.AllNodes.ResponseBufferLimit
69 | Type = $ConfigurationData.AllNodes.Type
70 | PreCondition = $ConfigurationData.AllNodes.PreCondition
71 | Location = "Default Web Site/$($ConfigurationData.AllNodes.VirtualDirectoryName)"
72 | Ensure = 'Absent'
73 | }
74 | }
75 | }
76 |
77 | $ConfigurationDataExcludedOptionalParameters = @{
78 | AllNodes = @(
79 | @{
80 | NodeName = 'LocalHost'
81 | Path = 'MACHINE/WEBROOT/APPHOST'
82 | Location = 'Webtest'
83 | Name = 'AnotherTest-WebHandler'
84 | PhysicalHandlerPath = '*'
85 | Verb = '*'
86 | Modules = 'IsapiModule'
87 | ScriptProcessor = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
88 | PhysicalPath = "C:\Temp"
89 | Type = 'SampleHandler'
90 | VirtualDirectoryName = 'TestDir'
91 | }
92 | )
93 | }
94 |
95 | Configuration DSC_WebApplicationHandler_AddHandlerExcludedOptionalParameters
96 | {
97 | Import-DSCResource -ModuleName WebAdministrationDsc
98 |
99 | Node 'localhost'
100 | {
101 | WebApplicationHandler WebHandlerTest
102 | {
103 | Path = $ConfigurationDataExcludedOptionalParameters.AllNodes.Path
104 | Name = $ConfigurationDataExcludedOptionalParameters.AllNodes.Name
105 | PhysicalHandlerPath = $ConfigurationDataExcludedOptionalParameters.AllNodes.PhysicalHandlerPath
106 | Verb = $ConfigurationDataExcludedOptionalParameters.AllNodes.Verb
107 | Modules = $ConfigurationDataExcludedOptionalParameters.AllNodes.Modules
108 | ScriptProcessor = $ConfigurationDataExcludedOptionalParameters.AllNodes.ScriptProcessor
109 | Type = $ConfigurationDataExcludedOptionalParameters.AllNodes.Type
110 | Location = "Default Web Site/$($ConfigurationDataExcludedOptionalParameters.AllNodes.VirtualDirectoryName)"
111 | Ensure = 'Present'
112 | }
113 | }
114 | }
115 |
116 | Configuration DSC_WebApplicationHandler_RemoveHandlerExcludedOptionalParameters
117 | {
118 | Import-DSCResource -ModuleName WebAdministrationDsc
119 |
120 | Node 'localhost'
121 | {
122 | WebApplicationHandler WebHandlerTest
123 | {
124 | Path = $ConfigurationDataExcludedOptionalParameters.AllNodes.Path
125 | Name = $ConfigurationDataExcludedOptionalParameters.AllNodes.Name
126 | PhysicalHandlerPath = $ConfigurationDataExcludedOptionalParameters.AllNodes.PhysicalHandlerPath
127 | Verb = $ConfigurationDataExcludedOptionalParameters.AllNodes.Verb
128 | Modules = $ConfigurationDataExcludedOptionalParameters.AllNodes.Modules
129 | ScriptProcessor = $ConfigurationDataExcludedOptionalParameters.AllNodes.ScriptProcessor
130 | Type = $ConfigurationDataExcludedOptionalParameters.AllNodes.Type
131 | Location = "Default Web Site/$($ConfigurationDataExcludedOptionalParameters.AllNodes.VirtualDirectoryName)"
132 | Ensure = 'Absent'
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------