diff --git a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 index 989ec2d71..84a378a7a 100644 --- a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 +++ b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 @@ -380,4 +380,36 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting WebApplicationHandler...' + $handlers = Get-WebConfigurationProperty -Filter 'system.webServer/handlers/Add' -Name '.' + + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach ($handler in $handlers) + { + Write-Information " [$i/$($handlers.Count)] $($handler.name)" + $params = @{ + Name = $handler.name + Path = 'IIS://' + Location = $handler.location + } + + $results = Get-TargetResource @params + [void]$sb.AppendLine(' WebApplicationHandler ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ + } + return $sb.ToString() +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 index a4cc72ec4..faaec3d4c 100644 --- a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 +++ b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 @@ -915,6 +915,40 @@ function Test-TargetResource } } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISHandler...' + + $handlers = Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' ` + -Filter 'system.webServer/handlers/*' ` + -Name '.' + + $i = 1 + $sb = [System.Text.StringBuilder]::new() + foreach ($handler in $handlers) + { + $params = @{ + Name = $handler.name + Ensure = 'Present' + } + + $results = Get-TargetResource @params + Write-Information " [$i/$($handlers.Count)] $($handler.name)" + [void]$sb.AppendLine(' xIISHandler ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ + } + return $sb.ToString() +} + #region Helper Functions function Get-Handler diff --git a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 index fb2780fac..e54e2a1fc 100644 --- a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 +++ b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 @@ -153,6 +153,49 @@ function Test-TargetResource return $false } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISFeatureDelegation...' + + $configSections = Get-WebConfiguration -Filter 'system.webServer/*' -Metadata -Recurse + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach ($section in $configSections) + { + if ($null -ne $section.SectionPath) + { + Write-Information " [$i/$($configSections.Count)] $($section.SectionPath.Remove(0,1))" + $params = @{ + Filter = $section.SectionPath.Remove(0,1) + Path = 'MACHINE/WEBROOT/APPHOST' + OverrideMode = 'Deny' + } + + try + { + $results = Get-TargetResource @params + [void]$sb.AppendLine(' xIISFeatureDelegation ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + } + catch + { + Write-Error $_ + } + } + $i++ + } + + return $sb.ToString() +} + #region Helper functions <# .SYNOPSIS diff --git a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 index 9ce053274..7342d2f0d 100644 --- a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 +++ b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 @@ -398,6 +398,33 @@ function Test-TargetResource } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISLogging...' + + $LogSettings = Get-WebConfiguration -Filter '/system.applicationHost/sites/siteDefaults/Logfile' + + $params = @{ + LogPath = $LogSettings.directory + } + $sb = [System.Text.StringBuilder]::new() + $results = Get-TargetResource @params + $results.LogFlags = $results.LogFlags.Split(',') + [void]$sb.AppendLine(' xIISLogging ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + + return $sb.ToString() + +} + #region Helper functions <# diff --git a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 index ec3380ce2..d3dba3f1c 100644 --- a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 +++ b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 @@ -228,6 +228,39 @@ function Test-TargetResource return $desiredConfigurationMatch } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISMimeTypeMapping...' + + $MimeMap = Get-WebConfiguration -Filter 'system.webServer/staticContent/mimeMap' + + $i = 1 + $sb = [System.Text.StringBuilder]::new() + foreach ($mimeType in $MimeMap) + { + Write-Information " [$i/$($MimeMap.Count)] $($mimeType.mimeType)" + $params =@{ + ConfigurationPath = $mimeType.PSPath + Extension = $mimeType.fileExtension + MimeType = $mimeType.mimeType + Ensure = 'Present' + } + $results = Get-TargetResource @params + [void]$sb.AppendLine(' xIISMimeTypeMapping ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $module + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ + } + return $sb.ToString() +} + #region Helper Functions <# diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 37b7e8e43..3e45b5000 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -1,27 +1,6 @@ # Load the Helper Module Import-Module -Name "$PSScriptRoot\..\Helper.psm1" -# Localized messages -data LocalizedData -{ - # culture="en-US" - ConvertFrom-StringData -StringData @' - VerboseGetTargetResource = Get-TargetResource has been run. - VerboseSetTargetRemoveHandler = Removing handler - VerboseSetTargetAddHandler = Adding handler. - VerboseSetTargetAddfastCgi = Adding fastCgi. - VerboseTestTargetResource = Get-TargetResource has been run. - VerboseGetIisHandler = Getting Handler for {0} in Site {1} - VerboseTestTargetResourceImplVerb = Matched Verb {0} - VerboseTestTargetResourceImplExtraVerb = Extra Verb {0} - VerboseTestTargetResourceImplRequestPath = RequestPath is {0} - VerboseTestTargetResourceImplPath = Path is {0} - VerboseTestTargetResourceImplresourceStatusRequestPath = StatusRequestPath is {0} - VerboseTestTargetResourceImplresourceStatusPath = StatusPath is {0} - VerboseTestTargetResourceImplModulePresent = Module present is {0} - VerboseTestTargetResourceImplModuleConfigured = ModuleConfigured is {0} -'@ -} function Get-TargetResource { <# @@ -34,74 +13,52 @@ function Get-TargetResource param ( [Parameter(Mandatory = $true)] - [String] $Path, - - [Parameter(Mandatory = $true)] - [String] $Name, + [System.String] + $Name, [Parameter(Mandatory = $true)] - [String] $RequestPath, + [System.String] + $SiteName, [Parameter(Mandatory = $true)] - [String[]] $Verb, + [System.String] + $Code, [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', - - [Parameter()] - [String] $SiteName + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure= "Present" ) - Assert-Module - - $currentVerbs = @() - $Ensure = 'Absent' - - $modulePresent = $false; - - $handler = Get-IisHandler -Name $Name -SiteName $SiteName - - if($handler ) - { - $Ensure = 'Present' - $modulePresent = $true; - } - - foreach($thisVerb in $handler.Verb) - { - $currentVerbs += $thisVerb - } - - $fastCgiSetup = $false + Assert-Module + Write-Verbose "Calling Get-TargetResource for $Name" + # We are looking at the root, therefore remove the asterik + if ('*' -eq $SiteName) + { + $SiteName = "" + } + $module = Get-WebManagedModule -Name $Name -Location $SiteName - if($handler.Modules -eq 'FastCgiModule') - { - $fastCgi = Get-WebConfiguration /system.webServer/fastCgi/* ` - -PSPath (Get-IisSitePath ` - -SiteName $SiteName) | ` - Where-Object{$_.FullPath -ieq $handler.ScriptProcessor} - if($fastCgi) - { - $fastCgiSetup = $true - } + if($null -eq $module) + { + $returnValue = @{ + Name = $Name + SiteName = $SiteName + Code = $Code + Ensure = "Absent" } - - Write-Verbose -Message $LocalizedData.VerboseGetTargetResource - + } + else + { $returnValue = @{ - Path = $handler.ScriptProcessor - Name = $handler.Name - RequestPath = $handler.Path - Verb = $currentVerbs - SiteName = $SiteName - Ensure = $Ensure - ModuleType = $handler.Modules - EndPointSetup = $fastCgiSetup + Name = $module.Name + SiteName = $SiteName + Code = $module.Type + Ensure = "Present" } + } - $returnValue - + $returnValue } function Set-TargetResource @@ -114,70 +71,36 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure, - - [Parameter(Mandatory = $true)] - [String] $Path, - [Parameter(Mandatory = $true)] [String] $Name, [Parameter(Mandatory = $true)] - [String] $RequestPath, + [String] $SiteName, [Parameter(Mandatory = $true)] - [String[]] $Verb, - - [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', + [String] $Code, [Parameter()] - [String] $SiteName + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure= "Present" ) - $getParameters = Get-PSBoundParameters -FunctionParameters $PSBoundParameters - $resourceStatus = Get-TargetResource @GetParameters - $resourceTests = Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus - if($resourceTests.Result) - { - return - } + $resourceStatus = Get-TargetResource @PSBoundParameters - if($Ensure -eq 'Present') + if ($Ensure -eq 'Present' -and $resourceStatus.Ensure -eq 'Absent') { - if($resourceTests.ModulePresent -and -not $resourceTests.ModuleConfigured) - { - Write-Verbose -Message $LocalizedData.VerboseSetTargetRemoveHandler - Remove-IisHandler - } - - if(-not $resourceTests.ModulePresent -or -not $resourceTests.ModuleConfigured) - { - Write-Verbose -Message $LocalizedData.VerboseSetTargetAddHandler - Add-webconfiguration /system.webServer/handlers iis:\ -Value @{ - Name = $Name - Path = $RequestPath - Verb = $Verb -join ',' - Module = $ModuleType - ScriptProcessor = $Path - } - } + Write-Verbose "Setting Configuration" - if(-not $resourceTests.EndPointSetup) - { - Write-Verbose -Message $LocalizedData.VerboseSetTargetAddfastCgi - Add-WebConfiguration /system.webServer/fastCgi iis:\ -Value @{ - FullPath = $Path - } - } + New-WebManagedModule -Name $Name -Location $SiteName -Type $Code + } + elseif ($Ensure -eq 'Present' -and $resourceStatus.Ensure -eq 'Present') + { + Set-WebManagedModule -Name $Name -Location $SiteName -Type $Code } else { - Write-Verbose -Message $LocalizedData.VerboseSetTargetRemoveHandler - Remove-IisHandler + Remove-WebManagedModule -Location $SiteName -Name $NAme } } @@ -193,233 +116,104 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure, - - [Parameter(Mandatory = $true)] - [String] $Path, - [Parameter(Mandatory = $true)] - [String] $Name, + [System.String] + $Name, [Parameter(Mandatory = $true)] - [String] $RequestPath, + [System.String] + $SiteName, [Parameter(Mandatory = $true)] - [String[]] $Verb, - - [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', + [System.String] + $Code, [Parameter()] - [String] $SiteName - ) - - $getParameters = Get-PSBoundParameters -FunctionParameters $PSBoundParameters - $resourceStatus = Get-TargetResource @GetParameters - - Write-Verbose -Message $LocalizedData.VerboseTestTargetResource - - return (Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus).Result -} - -#region Helper Functions - -function Get-PSBoundParameters -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [Hashtable] $FunctionParameters + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = "Present" ) + $resourceStatus = Get-TargetResource @PSBoundParameters - [Hashtable] $getParameters = @{} - foreach($key in $FunctionParameters.Keys) + $result = $true + if ($resourceStatus.Ensure -ne $Ensure -or $resourceStatus.SiteName -ne $SiteName -or $resourceStatus.Code -ne $Code) { - if($key -ine 'Ensure') - { - $getParameters.Add($key, $FunctionParameters.$key) | Out-Null - } + return $false } - - return $getParameters + Write-Verbose "Testing $Name" + return $result } -function Get-IisSitePath +function Export-TargetResource { - [OutputType([System.String])] [CmdletBinding()] - param - ( - [Parameter()] - [String] $SiteName - ) - - if (-not $SiteName) - { - return 'IIS:\' - } - else - { - return Join-Path 'IIS:\sites\' $SiteName - } -} - -function Get-IisHandler -{ - <# - .NOTES - Get a list on IIS handlers - #> - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] $Name, - - [Parameter()] - [String] $SiteName - ) - - Write-Verbose -Message ($LocalizedData.VerboseGetIisHandler -f $Name,$SiteName) - return Get-Webconfiguration -Filter 'System.WebServer/handlers/*' ` - -PSPath (Get-IisSitePath ` - -SiteName $SiteName) | ` - Where-Object{$_.Name -ieq $Name} -} - -function Remove-IisHandler -{ - <# - .NOTES - Remove an IIS Handler - #> - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] $Name, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] + [OutputType([System.String])] + param() - [Parameter()] - [String] $SiteName - ) + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISModule...' - $handler = Get-IisHandler @PSBoundParameters + $Modules = Get-WebManagedModule - if($handler) + Write-Information ' Modules Defined at Root Level:' + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach ($Module in $Modules) { - Clear-WebConfiguration -PSPath $handler.PSPath ` - -Filter $handler.ItemXPath ` - -Location $handler.Location + Write-Information " [$i/$($Modules.Count)] $($Module.Name)" + $params = @{ + Name = $Module.Name + SiteName = '*' + Code = $Module.Type + Ensure = 'Present' + } + $results = Get-TargetResource @params + [void]$sb.AppendLine(' xIISModule ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $dscmodule + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ } -} -function Test-TargetResourceImpl -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [String] $Path, - - [Parameter(Mandatory = $true)] - [String] $Name, - - [Parameter(Mandatory = $true)] - [String] $RequestPath, - - [Parameter(Mandatory = $true)] - [String[]] $Verb, - - [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', - - [Parameter()] - [String] $SiteName, - - [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure, + $sites = Get-Website - [Parameter(Mandatory = $true)] - [HashTable] $resourceStatus - ) - - $matchedVerbs = @() - $mismatchVerbs =@() - foreach($thisVerb in $resourceStatus.Verb) + foreach ($site in $sites) { - if($Verb -icontains $thisVerb) + Write-Information " Modules Defined at Site Level {$($site.Name)}" + + try { - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplVerb ` - -f $Verb) - $matchedVerbs += $thisVerb + $Modules = Get-WebManagedModule -Location $site.Name + $i = 1 + foreach ($Module in $Modules) + { + Write-Information " [$i/$($Modules.Count)] $($Module.Name)" + $params =@{ + Name = $Module.Name + SiteName = $site.Name + Code = $Module.Type + Ensure = 'Present' + } + $results = Get-TargetResource @params + [void]$sb.AppendLine(' xIISModule ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $dscmodule + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ + } } - else + catch { - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplExtraVerb ` - -f $Verb) - $mismatchVerbs += $thisVerb + Write-Verbose "Modules in site $site.Name are being override at a parent level." } } - - $modulePresent = $false - if($resourceStatus.Name.Length -gt 0) - { - $modulePresent = $true - } - - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplRequestPath ` - -f $RequestPath) - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplPath ` - -f $Path) - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplresourceStatusRequestPath ` - -f $($resourceStatus.RequestPath)) - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplresourceStatusPath ` - -f $($resourceStatus.Path)) - - $moduleConfigured = $false - if($modulePresent -and ` - $mismatchVerbs.Count -eq 0 -and ` - $matchedVerbs.Count-eq $Verb.Count -and ` - $resourceStatus.Path -eq $Path -and ` - $resourceStatus.RequestPath -eq $RequestPath) - { - $moduleConfigured = $true - } - - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplModulePresent ` - -f $ModulePresent) - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplModuleConfigured ` - -f $ModuleConfigured) - if($moduleConfigured -and ($ModuleType -ne 'FastCgiModule' -or $resourceStatus.EndPointSetup)) - { - return @{ - Result = $true - ModulePresent = $modulePresent - ModuleConfigured = $moduleConfigured - } - } - else - { - return @{ - Result = $false - ModulePresent = $modulePresent - ModuleConfigured = $moduleConfigured - } - } + return $sb.ToString() } +#region Helper Functions + #endregion diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof index 135e12d76..41f8fcb66 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof @@ -2,14 +2,10 @@ [ClassVersion("1.0.0"), FriendlyName("xIisModule")] class MSFT_xIisModule : OMI_BaseResource { - [Key, Description("The path to the module, usually a dll, to be added to IIS.")] String Path; - [Required, Description("The logical name of the module to add to IIS.")] String Name; - [Required, Description("The allowed request Path example: *.php")] String RequestPath; - [Required, Description("The supported verbs for the module.")] String Verb[]; - [Write, Description("The IIS Site to register the module.")] String SiteName; + [Key, Description("The logical name of the module to add to IIS.")] String Name; + [Key, Description("The IIS Site to register the module. Use '*' to specify the server's root.")] String SiteName; + [Required, Description("The code associated with the module to register")] String Code; [Write, Description("Should the module be present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("The type of the module."), ValueMap{"FastCgiModule"}, Values{"FastCgiModule"}] String ModuleType; - [Read, Description("The End Point is setup. Such as a Fast Cgi endpoint.")] Boolean EndPointSetup; }; diff --git a/DSCResources/MSFT_xIisModule/xIisModuleDesigner.ps1 b/DSCResources/MSFT_xIisModule/xIisModuleDesigner.ps1 deleted file mode 100644 index 3f9c39c61..000000000 --- a/DSCResources/MSFT_xIisModule/xIisModuleDesigner.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -$diff = join-Path ${env:ProgramFiles(x86)} "Beyond compare 2\bc2.exe" -$friendlyName = "xIisModule" -$resourceName = "MSFT_$friendlyName" -$classVersion = "1.0.0" - -$scriptRoot = Split-Path $MyInvocation.MyCommand.Path -$originalModuleRoot = join-Path $scriptroot "..\.." -$originalModuleRootPath = Resolve-Path $originalModuleRoot -$moduleRoot = Join-Path $env:temp "$($originalModuleRootPath.path | split-path -Leaf)Temp" - -$resources = @() - -#Key properties -$resources += New-xDscResourceProperty -Name Path -Type String -Attribute Key -Description "The path to the module, usually a dll, to be added to IIS." - - -#Required Properites -$resources += New-xDscResourceProperty -Name Name -Type String -Attribute Required -Description "The logical name of the module to add to IIS." -$resources += New-xDscResourceProperty -Name RequestPath -Type String -Attribute Required -Description "The allowed request Path example: *.php" -$resources += New-xDscResourceProperty -Name Verb -Type String[] -Attribute Required -Description "The supported verbs for the module." - -#Write Properties -$resources += New-xDscResourceProperty -Name SiteName -Type String -Attribute Write -Description "The IIS Site to register the module." -$resources += New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -Description "Should the module be present or absent." -ValidateSet @("Present","Absent") -$resources += New-xDscResourceProperty -Name ModuleType -Type String -Attribute Write -Description "The type of the module." -ValidateSet @("FastCgiModule") - -#Read Properties -$resources += New-xDscResourceProperty -Name EndPointSetup -Type Boolean -Attribute Read -Description "The End Point is setup. Such as a Fast Cgi endpoint." - - - -Write-Verbose "updating..." -Verbose - -# Create a New template resource to a temporary folder -New-xDscResource -Property $resources -ClassVersion $classVersion -Name $resourceName -Path $moduleRoot -FriendlyName $friendlyName - - -# Use your favorite diff program to compare and merge the current resource and the existing resource - -if((test-Path $diff)) -{ - &$diff $originalModuleRoot $moduleRoot -} -else -{ - Write-Warning "Diff propgram not found!`r`nUse your favorite diff program to compare and merge:`r`n `t$($originalModuleRootPath.path)`r`n and:`r`n `t$moduleRoot" -} - - - diff --git a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 index 51103734e..51ad5f384 100644 --- a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 +++ b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 @@ -174,4 +174,36 @@ function Test-TargetResource return $false; } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xSSLSettings...' + + $sb = [System.Text.StringBuilder]::new() + + $websites = Get-Website + $i = 1 + foreach($site in $websites) + { + $params = @{ + Name = $site.Name + Bindings = '' + } + $results = Get-TargetResource @params + Write-Information " [$i/$($websites.Count)] Reading SSL Setting for site {$($site.Name)}" + [void]$sb.AppendLine(' xSSLSettings ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $i++ + } + + return $sb.ToString() +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 index a5368df53..ad5b4bf64 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -977,6 +977,50 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebAppPool...' + + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + $appPools = Get-WebConfiguration -Filter '/system.applicationHost/applicationPools/add' + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach($appPool in $appPools) + { + Write-Information " [$i/$($appPools.Length)] $($appPool.Name)" + <# Setting Primary Keys #> + $params.Name = $appPool.Name + Write-Verbose 'Key parameters as follows' + $params | ConvertTo-Json | Write-Verbose + + $results = Get-TargetResource @params + + if($appPool.ProcessModel -eq 'SpecificUser') + { + $results.Credential = "`$Creds" + $appPool.ProcessModel.username + } + else + { + $results.Remove('Credential') + } + + Write-Verbose 'All Parameters with values' + $results | ConvertTo-Json | Write-Verbose + [void]$sb.AppendLine(' xWebAppPool ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + } + return $sb.ToString() +} + #region Helper Functions function Get-Property diff --git a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 index 1919de41b..34abdd7c9 100644 --- a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 +++ b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 @@ -121,6 +121,29 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebAppPoolDefaults...' + $sb = [System.Text.StringBuilder]::new() + $params = @{ + ApplyTo = 'Machine' + } + $results = Get-TargetResource @params + $results.Add('ApplyTo', 'Machine') + + [void]$sb.AppendLine(' xWebAppPoolDefaults ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + return $sb.ToString() +} + #region Helper Functions function Confirm-Value diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index 9e7cae8fc..34724f674 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -504,6 +504,88 @@ function Confirm-UniqueEnabledProtocols return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebApplication...' + + $webSites = Get-WebSite + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach ($website in $webSites) + { + Write-Information " [$i/$($webSites.Count)] Site {$($webSite.Name)}" + $webApplications = Get-WebApplication -Site $website.name + + if($webApplications) + { + $j = 1 + foreach ($webapplication in $webApplications) + { + $authSb = [System.Text.StringBuilder]::new() + Write-Information "[$j/$($webApplications.Count)] $($webApplication.Path)" + + <# Setting Primary Keys #> + $params =@{ + Name = $webapplication.Path + Website = $website.Name + WebAppPool = $webapplication.ApplicationPool + PhysicalPath = '*' + } + <# Setting Required Keys #> + #$params.WebAppPool = $webapplication.applicationpool + #$params.PhysicalPath = $webapplication.PhysicalPath + Write-Verbose 'Key parameters as follows' + $params | ConvertTo-Json | Write-Verbose + + $results = Get-TargetResource @params + Write-Verbose 'All Parameters as follows' + $results | ConvertTo-Json | Write-Verbose + + [void]$authSb.AppendLine( 'MSFT_xWebApplicationAuthenticationInformation') + [void]$authSb.AppendLine(' {') + + $AuthenticationTypes = @('BasicAuthentication','AnonymousAuthentication','DigestAuthentication','WindowsAuthentication') + + foreach ($authenticationtype in $AuthenticationTypes) + { + Remove-Variable -Name location -ErrorAction SilentlyContinue + Remove-Variable -Name prop -ErrorAction SilentlyContinue + $location = $website.Name + $webapplication.Path + $prop = Get-WebConfigurationProperty ` + -Filter "/system.WebServer/security/authentication/$authenticationtype" ` + -Name 'enabled' ` + -PSPath "IIS:\Sites\$location" + Write-Verbose "$authenticationtype : $($prop.Value)" + [void]$authSb.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) + } + [void]$authSb.AppendLine(' }') + + $results.AuthenticationInfo = $authSb.ToString() + $results.SslFlags = $results.SslFlags.Split(',') + $results.EnabledProtocols = $results.EnabledProtocols.Split(',') + + Write-Verbose 'All Parameters with values' + $results | ConvertTo-Json | Write-Verbose + + [void]$sb.AppendLine(' xWebApplication ' + (New-GUID).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $dscBlock = Convert-DSCStringParamToVariable -DSCBlock $dscBlock -ParameterName 'AuthenticationInfo' + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $j++ + } + } + $i++ + } + return $sb.ToString() +} + #region Helper Functions <# @@ -635,7 +717,7 @@ function Get-SslFlags ) $SslFlags = Get-WebConfiguration ` - -PSPath IIS:\Sites ` + -PSPath 'IIS:\Sites' ` -Location $Location ` -Filter 'system.webserver/security/access' | ` ForEach-Object { $_.sslFlags } diff --git a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 index 60efcf45d..975b40e7b 100644 --- a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 +++ b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 @@ -242,6 +242,49 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebConfigKeyValue...' + + $webSites = Get-Website + + $i = 1 + $sb = [System.Text.StringBuilder]::new() + foreach ($site in $webSites) + { + Write-Information " [$i/$($webSites.Count)] Scanning Keys for WebSite {$($site.Name)}" + $keys = Get-WebConfiguration -Filter '/appSettings/*' -PSPath "IIS:/Sites/$($site.Name)" + + $j = 1 + foreach ($key in $keys) + { + Write-Information " [$j/$($keys.Count)] $($key.Key)" + $params = @{ + WebsitePath = "IIS:/Sites/$($site.Name)" + ConfigSection = 'AppSettings' + Key = $key.Key + } + $results = Get-TargetResource @params + $results.Add('WebsitePath', "IIS:/Sites/$($site.Name)") + $results.Add('ConfigSection', 'AppSettings') + + [void]$sb.AppendLine(' xWebConfigKeyValue ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $j++ + } + $i++ + } + return $sb.ToString() +} + # region Helper Functions function Add-Item diff --git a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 index 5ec082c9a..5f9ba8542 100644 --- a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 +++ b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 @@ -252,6 +252,18 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebConfigProperty is not supported by ReverseDSC.' + + return '' +} + # region Helper Functions <# diff --git a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 index efb4a9c7e..b438e1d00 100644 --- a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 +++ b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 @@ -426,6 +426,17 @@ function Test-TargetResource } } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebConfigPropertyCollection is not supported by ReverseDSC' + return '' +} + # region Helper Functions <# diff --git a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 index 2953601f3..e39938421 100644 --- a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 +++ b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 @@ -35,11 +35,11 @@ function Get-TargetResource return @{ LogFormat = (Get-Value 'siteDefaults/logFile' 'logFormat') - TraceLogDirectory = ( Get-Value 'siteDefaults/traceFailedRequestsLogging' 'directory') - DefaultApplicationPool = (Get-Value 'applicationDefaults' 'applicationPool') - AllowSubDirConfig = (Get-Value 'virtualDirectoryDefaults' 'allowSubDirConfig') + TraceLogDirectory = (Get-Value 'siteDefaults/traceFailedRequestsLogging' 'directory').value + DefaultApplicationPool = (Get-Value 'applicationDefaults' 'applicationPool').value + AllowSubDirConfig = (Get-Value 'virtualDirectoryDefaults' 'allowSubDirConfig').value ApplyTo = 'Machine' - LogDirectory = (Get-Value 'siteDefaults/logFile' 'directory') + LogDirectory = (Get-Value 'siteDefaults/logFile' 'directory').value } } @@ -169,6 +169,29 @@ function Test-TargetResource } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebSiteDefaults...' + $sb = [System.Text.StringBuilder]::new() + + $params = @{ + ApplyTo = 'Machine' + } + $results = Get-TargetResource @params + + [void]$sb.AppendLine(' xWebSiteDefaults ' + (New-GUID).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + return $sb.ToString() +} + #region Helper Functions function Confirm-Value diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index 86db784c3..40abb6bd2 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -210,4 +210,66 @@ function Test-TargetResource return $false } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebVirtualDirectory...' + $webSites = Get-WebSite + + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach($website in $webSites) + { + Write-Information " [$i/$($webSites.Count)] Getting Virtual Directories from WebSite {$($website.Name)}" + Write-Verbose "WebSite: $($website.name)" + $webVirtualDirectories = Get-WebVirtualDirectory -Site $website.name + + if($webVirtualDirectories) + { + $j =1 + foreach($webvirtualdirectory in $webVirtualDirectories) + { + Write-Information " [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)" + Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)" + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + <# Setting Primary Keys #> + if ($null -ne $webvirtualdirectory.Name) + { + $params.Name = $webvirtualdirectory.Name + } + else + { + $params.Name = $webvirtualdirectory.Path + } + $params.PhysicalPath = $webvirtualdirectory.PhysicalPath + $params.WebApplication = '' + $params.Website = $website.Name + <# Setting Required Keys #> + #$params.PhysicalPath = $webapplication.PhysicalPath + Write-Verbose 'Key parameters as follows' + $params | ConvertTo-Json | Write-Verbose + + $results = Get-TargetResource @params + + Write-Verbose 'All Parameters with values' + $results | ConvertTo-Json | Write-Verbose + + [void]$sb.AppendLine(' xWebVirtualDirectory ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + $j++ + } + } + $i++ + } + return $sb.ToString() +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 154c9509c..8bfdae8ef 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1119,6 +1119,135 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param() + + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebSite...' + + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + $webSites = Get-WebSite + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach($website in $webSites) + { + Write-Information " [$i/$($webSites.Count)] $($website.Name)" + <# Setting Primary Keys #> + $params.Name = $website.Name + Write-Verbose 'Key parameters as follows' + $params | ConvertTo-Json | Write-Verbose + + $results = Get-TargetResource @params + Write-Verbose 'All Parameters as follows' + $results | ConvertTo-Json | Write-Verbose + + $results.BindingInfo = @(); + + foreach($binding in $website.Bindings.Collection) + { + $bindingContent = [System.Text.StringBuilder]::new() + [void]$bindingContent.AppendLine('MSFT_xWebBindingInformation') + [void]$bindingContent.AppendLine(' {') + [void]$bindingContent.AppendLine(" Protocol = '$($binding.Protocol)'") + [void]$bindingContent.AppendLine(" SslFlags = $($binding.sslFlags)") + + if ($binding.protocol -match '^http') + { + $bindingInfo = $binding.bindingInformation.split(':') + $ipAddress = $bindingInfo[0] + $port = $bindingInfo[1] + $hostName = $bindingInfo[2] + [void]$bindingContent.AppendLine(" IPAddress = '$ipAddress'") + [void]$bindingContent.AppendLine(" Port = $port") + if (-not [System.String]::IsNullOrEmpty($hostName)) + { + [void]$bindingContent.AppendLine(" Hostname = '$hostName'") + } + if ($binding.CertificateStoreName -eq 'My' -or $binding.CertificateStoreName -eq 'WebHosting') + { + if ($null -ne $binding.CertificateHash -and '' -ne $binding.CertificateHash) + { + [void]$bindingContent.AppendLine(" CertificateThumbprint = '$($binding.CertificateHash)'") + } + [void]$bindingContent.AppendLine(" CertificateStoreName = '$($binding.CertificateStoreName)'") + } + } + else + { + [void]$bindingContent.AppendLine(" BindingInformation = '$($binding.bindingInformation)'") + } + + [void]$bindingContent.AppendLine(' }') + + $results.BindingInfo += $bindingContent.ToString() + } + + $results.LogCustomFields = @(); + + [string]$LogCustomFields = $null + $logSB = [System.Text.StringBuilder]::new() + foreach ($customfield in $webSite.logfile.customFields.Collection) + { + [void]$logSB.AppendLine('MSFT_LogCustomFieldInformation') + [void]$logSB.AppendLine('{') + [void]$logSB.AppendLine(" logFieldName = `"$($customfield.logFieldName)`"") + [void]$logSB.AppendLine(" sourceName = `"$($customfield.sourceName)`"") + [void]$logSB.AppendLine(" sourceType = `"$($customfield.sourceType)`"") + [void]$logSB.AppendLine('}') + } + + $results.LogCustomFields = $logSB.ToString() + $authSB = [System.Text.StringBuilder]::new() + [void]$authSB.AppendLine(' MSFT_xWebAuthenticationInformation') + [void]$authSB.AppendLine(' {') + + $AuthenticationTypes = @('BasicAuthentication','AnonymousAuthentication','DigestAuthentication','WindowsAuthentication') + + foreach ($authenticationtype in $AuthenticationTypes) + { + Remove-Variable -Name location -ErrorAction SilentlyContinue + Remove-Variable -Name prop -ErrorAction SilentlyContinue + $location = $website.Name + $prop = Get-WebConfigurationProperty ` + -Filter /system.WebServer/security/authentication/$authenticationtype ` + -Name enabled ` + -Location $location + Write-Verbose '$authenticationtype : $($prop.Value)' + [void]$authSB.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) + } + [void]$authSB.Append(' }') + + $results.AuthenticationInfo = $authSB.ToString() + $results.LogFlags = $results.LogFlags.Split(',') + + if ($null -eq $results.ServiceAutoStartProvider) + { + $results.Remove("ServiceAutoStartProvider") + } + if ([System.String]::IsNullOrEmpty($results.LogCustomFields)) + { + $results.Remove("LogCustomFields") + } + + Write-Verbose 'All Parameters with values' + $results | ConvertTo-Json | Write-Verbose + + [void]$sb.AppendLine(' xWebSite ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $dscBlock = Convert-DSCStringParamToVariable -DSCBlock $dscBlock -ParameterName "BindingInfo" -ISCIMArray $true + $dscBlock = Convert-DSCStringParamToVariable -DSCBlock $dscBlock -ParameterName "AuthenticationInfo" -ISCIMArray $true + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(' }') + } + + return $sb.ToString() +} + #region Helper Functions <# diff --git a/Modules/ReverseDSCCollector.psm1 b/Modules/ReverseDSCCollector.psm1 new file mode 100644 index 000000000..1c1d9a51b --- /dev/null +++ b/Modules/ReverseDSCCollector.psm1 @@ -0,0 +1,79 @@ +function Export-WebAdministrationConfiguration +{ + [CmdletBinding()] + [OutputType([System.String])] + param( + [Parameter()] + [System.String] + $Path + ) + + $sb = [System.Text.StringBuilder]::new() + [void]$sb.AppendLine("Configuration WebAdministrationConfiguration") + [void]$sb.AppendLine("{") + [void]$sb.AppendLine(" Import-DSCResource -ModuleName xWebAdministration") + [void]$sb.AppendLine(" Node localhost") + [void]$sb.AppendLine(" {") + + $ResourcesPath = Join-Path -Path $PSScriptRoot ` + -ChildPath "..\DSCResources\" ` + -Resolve + $AllResources = Get-ChildItem $ResourcesPath -Recurse | Where-Object {$_.Name -like 'MSFT_*.psm1'} + + foreach ($ResourceModule in $AllResources) + { + Import-Module $ResourceModule.FullName | Out-Null + $exportString = Export-TargetResource + [void]$sb.Append($exportString) + } + + [void]$sb.AppendLine(" }") + [void]$sb.AppendLine("}") + + [void]$sb.AppendLine("`$cd = @{") + [void]$sb.AppendLine(" AllNodes = @(") + [void]$sb.AppendLine(" @{") + [void]$sb.AppendLine(" NodeName = 'localhost'") + [void]$sb.AppendLine(" PSDSCAllowPlaintextPassword = `$true") + [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(" )") + [void]$sb.AppendLine("}") + + [void]$sb.AppendLine("WebAdministrationConfiguration -ConfigurationData `$cd") + + #region Prompt the user for a location to save the extract and generate the files + if ($null -eq $Path -or "" -eq $Path) + { + $OutputDSCPath = Read-Host "Destination Path" + } + else + { + $OutputDSCPath = $Path + } + + while ((Test-Path -Path $OutputDSCPath -PathType Container -ErrorAction SilentlyContinue) -eq $false) + { + try + { + Write-Information "Directory `"$OutputDSCPath`" doesn't exist; creating..." + New-Item -Path $OutputDSCPath -ItemType Directory | Out-Null + if ($?) {break} + } + catch + { + Write-Warning "$($_.Exception.Message)" + Write-Warning "Could not create folder $OutputDSCPath!" + } + $OutputDSCPath = Read-Host "Please Provide Output Folder for DSC Configuration (Will be Created as Necessary)" + } + <## Ensures the path we specify ends with a Slash, in order to make sure the resulting file path is properly structured. #> + if (!$OutputDSCPath.EndsWith("\") -and !$OutputDSCPath.EndsWith("/")) + { + $OutputDSCPath += "\" + } + $outputDSCFile = $OutputDSCPath + "WebAdministrationConfiguration.ps1" + $sb.ToString() | Out-File $outputDSCFile + + Invoke-Item -Path $OutputDSCPath + #endregion +} diff --git a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 index 5d0890e0a..a8e7425ed 100644 --- a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 +++ b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 @@ -369,6 +369,18 @@ try } } } + + Describe 'MSFT_WebApplicationHandler/Export-TargetResource' { + + Context 'Export Configuration' { + + Mock Get-WebConfigurationProperty -MockWith {$mockCompliantHandler} + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } } diff --git a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 index c78334356..dea7f3ebf 100644 --- a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 @@ -30,6 +30,7 @@ try Metadata = @{ effectiveOverrideMode = 'Allow' } + SectionPath = "/System.webServer/" } $mockDenyOverrideMode = @{ @@ -168,6 +169,17 @@ try } } } + Describe 'MSFT_IISFeatureDelegation/Export-TargetResource' { + + Context 'Export Configuration' { + + Mock -CommandName Get-WebConfiguration -MockWith { return $mockAllowOverrideMode } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } #endregion } #endregion diff --git a/Tests/Unit/MSFT_xIISHandler.Tests.ps1 b/Tests/Unit/MSFT_xIISHandler.Tests.ps1 index 0e7afce42..239250612 100644 --- a/Tests/Unit/MSFT_xIISHandler.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISHandler.Tests.ps1 @@ -186,6 +186,18 @@ try Assert-MockCalled Get-WebConfigurationProperty } } + + Describe 'MSFT_xIISHandler/Export-TargetResource' { + + Context 'Export Configuration' { + Mock Assert-Module + Mock Get-Handler {'Present'} + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } #endregion } diff --git a/Tests/Unit/MSFT_xIISLogging.Tests.ps1 b/Tests/Unit/MSFT_xIISLogging.Tests.ps1 index 98f150213..087c8ff3d 100644 --- a/Tests/Unit/MSFT_xIISLogging.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISLogging.Tests.ps1 @@ -924,6 +924,22 @@ try } } } + Describe 'MSFT_xIISLogging/Export-TargetResource' { + + Context 'Export Configuration' { + Mock -CommandName Get-WebConfiguration ` + -MockWith { return $MockLogOutput } + + Mock -CommandName Assert-Module -MockWith {} + + Mock -CommandName ConvertTo-CimLogCustomFields ` + -MockWith { return $MockLogCustomFields } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } #endregion diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 new file mode 100644 index 000000000..0ba8b18e6 --- /dev/null +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -0,0 +1,133 @@ +$script:DSCModuleName = 'xWebAdministration' +$script:DSCResourceName = 'MSFT_xIisModule' + +# Unit Test Template Version: 1.1.0 +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\MockWebAdministrationWindowsFeature.psm1') + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion HEADER + +# Begin Testing +try +{ + #region Pester Tests + + InModuleScope $script:DSCResourceName { + + + Describe "$script:DSCResourceName\Assert-Module" { + + Context 'WebAdminstration module is not installed' { + Mock -ModuleName Helper -CommandName Get-Module -MockWith { + return $null + } + + It 'Should throw an error' { + { Assert-Module } | + Should Throw + + } + + } + + } + + Describe "$script:DSCResourceName\Get-TargetResource" { + + Context 'Resource does not exist. We need to add it' { + + $TestParams = @{ + Name = "Test Module" + SiteName = "Test Site" + Code = "Litware.Contoso.Tests" + } + Mock -CommandName Get-WebManagedModule -MockWith { + return $null + } + + Mock -CommandName New-WebManagedModule -MockWith { + return $null + } + + Mock -CommandName Assert-Module -MockWith {} + + It 'Should Absent from the Get Method' { + (Get-TargetResource @TestParams).Ensure | Should Be 'Absent' + } + + It 'Should create the module from the Set Method' { + Set-TargetResource @TestParams + } + + It 'Should return false from the Test method' { + Test-TargetResource @TestParams | Should be $false + } + } + + Context 'Resource exists.' { + + $TestParams = @{ + Name = "Test Module" + SiteName = "Test Site" + Code = "Litware.Contoso.Tests" + } + Mock -CommandName Get-WebManagedModule -MockWith { + return @{ + Name = "Test Module" + Type = "Litware.Contoso.Tests" + } + } + + Mock -CommandName New-WebManagedModule -MockWith { + return $null + } + + Mock -CommandName Assert-Module -MockWith {} + + It 'Should be Present from the Get Method' { + (Get-TargetResource @TestParams).Ensure | Should Be 'Present' + } + + It 'Should return true from the Test method' { + Test-TargetResource @TestParams | Should be $true + } + } + } + + Describe 'MSFT_xIISModule/Export-TargetResource' { + + Context 'Export Configuration' { + Mock -CommandName Get-WebManagedModule -MockWith { + return @{ + Name = "CustomModule" + Type = "Contoso.CustomModule" + } + } + + Mock -CommandName Assert-Module -MockWith {} + + It 'Should Export all instances' { + Export-TargetResource + } + } + } + } + #endregion +} + +finally +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} diff --git a/Tests/Unit/MSFT_xIisMimeTypeMapping.Tests.ps1 b/Tests/Unit/MSFT_xIisMimeTypeMapping.Tests.ps1 index 86783aa9c..ce2dcb10d 100644 --- a/Tests/Unit/MSFT_xIisMimeTypeMapping.Tests.ps1 +++ b/Tests/Unit/MSFT_xIisMimeTypeMapping.Tests.ps1 @@ -159,6 +159,17 @@ try } } #endregion + + Describe 'MSFT_xIISMimeTypeMapping/Export-TargetResource' { + + Context 'Export Configuration' { + Mock -CommandName Get-Mapping -MockWith { return $mockMapping } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xSSLSettings.Tests.ps1 b/Tests/Unit/MSFT_xSSLSettings.Tests.ps1 index 93671f582..d11827446 100644 --- a/Tests/Unit/MSFT_xSSLSettings.Tests.ps1 +++ b/Tests/Unit/MSFT_xSSLSettings.Tests.ps1 @@ -174,6 +174,17 @@ try } } } + Describe 'MSFT_xSSLSettings/Export-TargetResource' { + + Context 'Export Configuration' { + Mock Assert-Module -Verifiable {} + Mock Get-WebConfigurationProperty -Verifiable { return 'Ssl' } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xWebAppPool.Tests.ps1 b/Tests/Unit/MSFT_xWebAppPool.Tests.ps1 index bc4088c61..47063e541 100644 --- a/Tests/Unit/MSFT_xWebAppPool.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebAppPool.Tests.ps1 @@ -3306,6 +3306,87 @@ try } } + Describe 'MSFT_xWebAppPool/Export-TargetResource' { + Mock Assert-Module + Context 'Export Configuration' { + $mockAppPool = @{ + name = 'MockAppPool' + state = 'Started' + autoStart = $true + CLRConfigFile = '' + enable32BitAppOnWin64 = $false + enableConfigurationOverride = $true + managedPipelineMode = 'Integrated' + managedRuntimeLoader = 'webengine4.dll' + managedRuntimeVersion = 'v4.0' + passAnonymousToken = $true + startMode = 'OnDemand' + queueLength = 1000 + cpu = @{ + action = 'NoAction' + limit = 0 + resetInterval = '00:05:00' + smpAffinitized = $false + smpProcessorAffinityMask = 4294967295 + smpProcessorAffinityMask2 = 4294967295 + } + processModel = @{ + identityType = 'SpecificUser' + idleTimeout = '00:20:00' + idleTimeoutAction = 'Terminate' + loadUserProfile = $true + logEventOnProcessModel = 'IdleTimeout' + logonType = 'LogonBatch' + manualGroupMembership = $false + maxProcesses = 1 + password = 'P@$$w0rd' + pingingEnabled = $true + pingInterval = '00:00:30' + pingResponseTime = '00:01:30' + setProfileEnvironment = $false + shutdownTimeLimit = '00:01:30' + startupTimeLimit = '00:01:30' + userName = 'CONTOSO\JDoe' + } + failure = @{ + orphanActionExe = '' + orphanActionParams = '' + orphanWorkerProcess = $false + loadBalancerCapabilities = 'HttpLevel' + rapidFailProtection = $true + rapidFailProtectionInterval = '00:05:00' + rapidFailProtectionMaxCrashes = 5 + autoShutdownExe = '' + autoShutdownParams = '' + } + recycling = @{ + disallowOverlappingRotation = $false + disallowRotationOnConfigChange = $false + logEventOnRecycle = 'Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory' + periodicRestart = @{ + memory = 0 + privateMemory = 0 + requests = 0 + time = '1.05:00:00' + schedule = @{ + Collection = @( + @{value = '04:00:00'} + @{value = '08:00:00'} + ) + } + } + } + } + + Mock Get-WebConfiguration -MockWith {$mockAppPool} + Mock Assert-Module -Verifiable {} + Mock Get-WebConfigurationProperty -Verifiable { return 'Ssl' } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } diff --git a/Tests/Unit/MSFT_xWebAppPoolDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebAppPoolDefaults.Tests.ps1 index c6161a95f..8e7c0cc6f 100644 --- a/Tests/Unit/MSFT_xWebAppPoolDefaults.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebAppPoolDefaults.Tests.ps1 @@ -186,6 +186,31 @@ try } } } + Describe 'MSFT_xWebAppPoolDefaults/Export-TargetResource' { + $mockAppPoolDefaults = @{ + managedRuntimeVersion = 'v4.0' + processModel = @{ + identityType = 'SpecificUser' + } + } + + Mock Get-WebConfigurationProperty -MockWith { + $path = $Filter.Replace('system.applicationHost/applicationPools/applicationPoolDefaults', '') + + if ([System.String]::IsNullOrEmpty($path)) { + return $mockAppPoolDefaults[$Name] + } else { + $path = $path.Replace('/', '') + return $mockAppPoolDefaults[$path][$Name] + } + } + Context 'Export Configuration' { + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 index 35e182645..a89d4ce72 100644 --- a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 @@ -1543,6 +1543,58 @@ try } } + Describe 'MSFT_xWebApplicaton/Export-TargetResource' { + $MockParameters = @{ + Website = 'MockSite' + Name = 'MockApp' + WebAppPool = 'MockPool' + PhysicalPath = 'C:\MockSite\MockApp' + } + + Mock Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Anonymous') } + + Mock Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Windows') } + + Mock -CommandName Assert-Module -MockWith {} + Context 'Export Configuration' { + Mock -CommandName Get-WebApplication -MockWith { + return @{ + Website = 'MockSite' + Name = 'MockApp' + applicationPool = 'MockPool' + Path = 'C:\MockSite\MockApp' + SslFlags = 'Ssl' + PreloadEnabled = $true + ServiceAutoStartProvider = 'MockServiceAutoStartProvider' + ServiceAutoStartEnabled = $true + ApplicationType = 'MockApplicationType' + AuthenticationInfo = $MockAuthenticationInfo + EnabledProtocols = 'http' + Count = '1' + } + } + + Mock -CommandName Get-WebConfiguration -MockWith { + return $GetWebConfigurationOutput + } + + Mock -CommandName Get-WebConfigurationProperty -MockWith { + return $GetAuthenticationInfo + } + + Mock Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Anonymous') } + + Mock Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Windows') } + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } diff --git a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 index a10abc84d..cb938fb69 100644 --- a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 @@ -490,6 +490,26 @@ try } } #endregion Non-Exported Function Unit Tests + + Describe 'MSFT_xWebConfigKeyValue/Export-TargetResource' { + Mock -CommandName Get-ItemValue -ModuleName $script:DSCResourceName ` + -ParameterFilter { $isAttribute -eq $false } ` + -MockWith { return 'Value' } + + Mock -CommandName Get-WebConfiguration -MockWith { + return @{ + Key = "Key1" + Value = "Value1" + } + } + + Context 'Export Configuration' { + + It 'Should Export all instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xWebConfigProperty.tests.ps1 b/Tests/Unit/MSFT_xWebConfigProperty.tests.ps1 index 324968285..2d4d105c6 100644 --- a/Tests/Unit/MSFT_xWebConfigProperty.tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigProperty.tests.ps1 @@ -260,6 +260,15 @@ try } #endregion Non-Exported Function Unit Tests + + Describe 'MSFT_xWebConfigProperty/Export-TargetResource' { + Context 'Export Configuration' { + + It 'Should Not export any resource instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xWebConfigPropertyCollection.tests.ps1 b/Tests/Unit/MSFT_xWebConfigPropertyCollection.tests.ps1 index a2610c310..efc6b04fa 100644 --- a/Tests/Unit/MSFT_xWebConfigPropertyCollection.tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigPropertyCollection.tests.ps1 @@ -413,6 +413,15 @@ try } + Describe 'MSFT_xWebConfigPropertyCollection/Export-TargetResource' { + Context 'Export Configuration' { + + It 'Should Not export any resource instances' { + Export-TargetResource + } + } + } + #endregion Non-Exported Function Unit Tests } } diff --git a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 new file mode 100644 index 000000000..345fa358b --- /dev/null +++ b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 @@ -0,0 +1,82 @@ + +$script:DSCModuleName = 'xWebAdministration' +$script:DSCResourceName = 'MSFT_xWebSiteDefaults' + +#region HEADER +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\MockWebAdministrationWindowsFeature.psm1') + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion + +try +{ + InModuleScope $script:DSCResourceName { + + Describe "$script:DSCResourceName\Assert-Module" { + Context 'WebAdminstration module is not installed' { + Mock -ModuleName Helper -CommandName Get-Module -MockWith { + return $null + } + + It 'Should throw an error' { + { Assert-Module } | Should Throw + } + } + } + + Describe "$script:DSCResourceName\Test-TargetResource" { + $mockWebSiteDefaults = @{ + logFormat = "W3C" + directory = "c:\inetpub" + applicationPool = "Default App Pool" + allowSubDirConfig = $true + } + + Mock Get-WebConfigurationProperty -MockWith { + return $MockWebSiteDefaults[$Name] + } + + Context 'Returns Defaults' { + $params = @{ + ApplyTo = "Machine" + LogFormat = "W3C" + } + It 'Should return true from the Test function' { + $result = Test-TargetResource @params + + $result | Should Be $true + } + + It 'Should update the default values in the Set function' { + Set-TargetResource @params + } + + It 'Should return Present from the Get function' { + Set-TargetResource @params + } + + It 'Should extract the default values from the Export function' { + Export-TargetResource + } + } + } + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} diff --git a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 index 23c775a53..f1c2f2756 100644 --- a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 @@ -23,7 +23,7 @@ $TestEnvironment = Initialize-TestEnvironment ` try { InModuleScope $script:DSCResourceName { - + Describe "$script:DSCResourceName\Assert-Module" { Context 'WebAdminstration module is not installed' { Mock -ModuleName Helper -CommandName Get-Module -MockWith { @@ -35,7 +35,7 @@ try } } } - + Describe "$script:DSCResourceName\Test-TargetResource" { $MockSite = @{ Website = 'contoso.com' @@ -100,7 +100,7 @@ try -Name $MockSite.Name ` -PhysicalPath $MockSite.PhysicalPath ` -Ensure $MockSite.Ensure - + $result | Should Be $false } } @@ -165,7 +165,7 @@ try } Describe "$script:DSCResourceName\Set-TargetResource" { - + Mock -CommandName Assert-Module -MockWith {} Context 'Ensure = Present and virtual directory does not exist' { @@ -234,6 +234,21 @@ try } } } + Describe 'MSFT_xWebVirtualDirectory/Export-TargetResource' { + + Context 'Export Configuration' { + Mock -CommandName Get-WebVirtualDirectory -MockWith { + return @{ + Name = 'shared_directory' + PhysicalPath = 'C:\inetpub\wwwroot\shared' + Count = 1 + } + } + It 'Should Export all resource instances' { + Export-TargetResource + } + } + } } } finally diff --git a/Tests/Unit/MSFT_xWebsite.Tests.ps1 b/Tests/Unit/MSFT_xWebsite.Tests.ps1 index d4d56e4b7..3e0c566a4 100644 --- a/Tests/Unit/MSFT_xWebsite.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebsite.Tests.ps1 @@ -3947,6 +3947,120 @@ try } } } + + Describe 'MSFT_xWebsite/Export-TargetResource' { + $MockWebBinding = @( + @{ + bindingInformation = '*:443:web01.contoso.com' + protocol = 'https' + certificateHash = '1D3324C6E2F7ABC794C9CB6CA426B8D0F81045CD' + certificateStoreName = 'WebHosting' + sslFlags = '1' + } + ) + + $MockPreloadAndAutostartProviders = @( + @{ + preloadEnabled = 'True' + ServiceAutoStartProvider = 'MockServiceAutoStartProvider' + ServiceAutoStartEnabled = 'True' + } + ) + + $MockWebConfiguration = @( + @{ + SectionPath = 'MockSectionPath' + PSPath = 'MockPSPath' + Collection = @( + [PSCustomObject] @{ + Name = 'MockServiceAutoStartProvider'; + Type = 'MockApplicationType' + } + ) + } + ) + + $MockAuthenticationInfo = @( + New-CimInstance -ClassName MSFT_xWebAuthenticationInformation ` + -Namespace root/microsoft/Windows/DesiredStateConfiguration ` + -Property @{ + Anonymous = 'true' + Basic = 'false' + Digest = 'false' + Windows = 'false' + } ` + -ClientOnly + ) + + $mockLogCustomFields = @( + @{ + LogFieldName = 'LogField1' + SourceName = 'Accept-Encoding' + SourceType = 'RequestHeader' + } + @{ + LogFieldName = 'LogField2' + SourceName = 'Warning' + SourceType = 'ResponseHeader' + } + ) + + $MockLogOutput = @{ + directory = '%SystemDrive%\inetpub\logs\LogFiles' + logExtFileFlags = 'Date','Time','ClientIP','UserName','ServerIP','Method','UriStem','UriQuery','HttpStatus','Win32Status','TimeTaken','ServerPort','UserAgent','Referer','HttpSubStatus' + logFormat = $MockParameters.LogFormat + period = 'Daily' + logTargetW3C = 'File,ETW' + truncateSize = '1048576' + localTimeRollover = 'False' + customFields = @{Collection = $mockLogCustomFields} + } + + $MockWebsite = @{ + Name = 'MockName' + Id = 1234 + PhysicalPath = 'C:\NonExistent' + State = 'Started' + ServerAutoStart = $true + ApplicationPool = 'MockPool' + Bindings = @{Collection = @($MockWebBinding)} + EnabledProtocols = 'http' + ApplicationDefaults = $MockPreloadAndAutostartProviders + LogFile = $MockLogOutput + Count = 1 + } + + Mock -CommandName Assert-Module -MockWith {} + Context 'Export Configuration' { + Mock -CommandName Get-Website -MockWith {return $MockWebsite} + + Mock -CommandName Get-WebConfiguration ` + -ParameterFilter {$filter -eq '/system.webServer/defaultDocument/files/*'} ` + -MockWith { return @{value = 'index.html'} } + + Mock -CommandName Get-WebConfiguration ` + -ParameterFilter {$filter -eq '/system.applicationHost/serviceAutoStartProviders'} ` + -MockWith { return $MockWebConfiguration} + + Mock -CommandName Get-WebConfigurationProperty ` + -MockWith {return $MockAuthenticationInfo} + + Mock -CommandName Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Anonymous') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Basic') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Digest') } + + Mock -CommandName Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Windows') } + It 'Should Not export any resource instances' { + Export-TargetResource + } + } + } } #endregion } diff --git a/appveyor.yml b/appveyor.yml index c85fa1ea6..f010f9e8d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,7 @@ environment: install: - git clone https://github.com/PowerShell/DscResource.Tests - ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose + - ps: Install-Module ReverseDSC -RequiredVersion 1.9.4.5 -Force - ps: Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - ps: Invoke-AppveyorInstallTask - ps: Install-WindowsFeature -IncludeAllSubFeature -IncludeManagementTools -Name 'Web-Server' diff --git a/xWebAdministration.psd1 b/xWebAdministration.psd1 index 3ef0cfa8c..af3dc812c 100644 --- a/xWebAdministration.psd1 +++ b/xWebAdministration.psd1 @@ -20,6 +20,9 @@ Description = 'Module with DSC Resources for Web Administration' # Minimum version of the Windows PowerShell engine required by this module PowerShellVersion = '4.0' +# Adds dependency to ReverseDSC +RequiredModules = @(@{ModuleName = "ReverseDSC"; RequiredVersion = "1.9.4.7"; }) + # Minimum version of the common language runtime (CLR) required by this module CLRVersion = '4.0' @@ -60,11 +63,14 @@ PrivateData = @{ } # End of PrivateData hashtable +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +NestedModules = @('Modules\ReverseDSCCollector.psm1') + # Functions to export from this module FunctionsToExport = '*' # Cmdlets to export from this module -CmdletsToExport = '*' +CmdletsToExport = 'Export-WebAdministrationConfiguraton' }