From 066a149e3712ec78bc4a1e034203c346832b850f Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 6 Sep 2019 09:59:14 -0400 Subject: [PATCH 01/36] Update MSFT_xIisModule.psm1 --- DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 4a172a073..e7dfc62da 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -280,8 +280,6 @@ function Get-IisHandler ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - - [Parameter()] [String] $Name, [Parameter()] From acc22365e834d01caf062b1155cbecc253c8c6d3 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 9 Sep 2019 14:47:58 -0400 Subject: [PATCH 02/36] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6c14058b8..895984c03 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,8 @@ This resource manages the IIS configuration section locking (overrideMode) to co ### Unreleased +* Changes to xIisModule + * Fixed the parameters specification for the internal Get-IISHandler function * Fix multiple HTTPS bindings on one xWebsite receiving the first binding's certificate [#332](https://github.com/PowerShell/xWebAdministration/issues/332) * Added unit regression test From eb3b17b2207c8919ac270909a7d871204d6f4cb1 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 9 Sep 2019 15:08:58 -0400 Subject: [PATCH 03/36] Fixed Remove-IISHandler --- DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 | 2 -- README.md | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index e7dfc62da..37b7e8e43 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -303,8 +303,6 @@ function Remove-IisHandler ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - - [Parameter()] [String] $Name, [Parameter(Mandatory = $true)] diff --git a/README.md b/README.md index 895984c03..9a3a119f1 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ This resource manages the IIS configuration section locking (overrideMode) to co ### Unreleased * Changes to xIisModule - * Fixed the parameters specification for the internal Get-IISHandler function + * Fixed the parameters specification for the internal Get-IISHandler and Remove-IISHandlet function * Fix multiple HTTPS bindings on one xWebsite receiving the first binding's certificate [#332](https://github.com/PowerShell/xWebAdministration/issues/332) * Added unit regression test From a2e342b322c05750d2eab4b38c6fe5ef4c6fa316 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 11 Sep 2019 11:14:55 -0400 Subject: [PATCH 04/36] Cleaned, fixed, and reviewed --- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 101 ++++++------------ .../MSFT_xIisModule.schema.mof | 3 +- 2 files changed, 35 insertions(+), 69 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 37b7e8e43..3cdfe848b 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -46,47 +46,41 @@ function Get-TargetResource [String[]] $Verb, [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', + [ValidateSet("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] + [String] $ModuleType, [Parameter()] - [String] $SiteName - ) + [String] $SiteName, - Assert-Module + [Parameter(Mandatory = $true)] + [ValidateSet('Present', 'Absent')] + [String] + $Ensure + ) - $currentVerbs = @() - $Ensure = 'Absent' + Assert-Module - $modulePresent = $false; + $currentVerbs = @() - $handler = Get-IisHandler -Name $Name -SiteName $SiteName + $handler = Get-IisHandler -Name $Name -SiteName $SiteName - if($handler ) - { - $Ensure = 'Present' - $modulePresent = $true; + if($null -eq $handler) + { + $returnValue = @{ + Path = $Path + Name = $Name + RequestPath = $RequestPath + Verb = $Verb + Ensure = "Absent" } - + } + else + { foreach($thisVerb in $handler.Verb) { $currentVerbs += $thisVerb } - $fastCgiSetup = $false - - 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 - } - } - Write-Verbose -Message $LocalizedData.VerboseGetTargetResource $returnValue = @{ @@ -95,13 +89,12 @@ function Get-TargetResource RequestPath = $handler.Path Verb = $currentVerbs SiteName = $SiteName - Ensure = $Ensure + Ensure = "Present" ModuleType = $handler.Modules - EndPointSetup = $fastCgiSetup } + } - $returnValue - + $returnValue } function Set-TargetResource @@ -131,15 +124,14 @@ function Set-TargetResource [String[]] $Verb, [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', + [ValidateSet("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] + [String] $ModuleType, [Parameter()] [String] $SiteName ) - $getParameters = Get-PSBoundParameters -FunctionParameters $PSBoundParameters - $resourceStatus = Get-TargetResource @GetParameters + $resourceStatus = Get-TargetResource @PSBoundParameters $resourceTests = Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus if($resourceTests.Result) { @@ -151,7 +143,7 @@ function Set-TargetResource if($resourceTests.ModulePresent -and -not $resourceTests.ModuleConfigured) { Write-Verbose -Message $LocalizedData.VerboseSetTargetRemoveHandler - Remove-IisHandler + Remove-IisHandler -Name $Name -SiteName $SiteName } if(-not $resourceTests.ModulePresent -or -not $resourceTests.ModuleConfigured) @@ -177,7 +169,7 @@ function Set-TargetResource else { Write-Verbose -Message $LocalizedData.VerboseSetTargetRemoveHandler - Remove-IisHandler + Remove-IisHandler -Name $Name -SiteName $SiteName } } @@ -210,15 +202,14 @@ function Test-TargetResource [String[]] $Verb, [Parameter()] - [ValidateSet('FastCgiModule')] - [String] $ModuleType = 'FastCgiModule', + + [ValidateSet("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] + [String] $ModuleType, [Parameter()] [String] $SiteName ) - - $getParameters = Get-PSBoundParameters -FunctionParameters $PSBoundParameters - $resourceStatus = Get-TargetResource @GetParameters + $resourceStatus = Get-TargetResource @PSBoundParameters Write-Verbose -Message $LocalizedData.VerboseTestTargetResource @@ -227,28 +218,6 @@ function Test-TargetResource #region Helper Functions -function Get-PSBoundParameters -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [Hashtable] $FunctionParameters - ) - - [Hashtable] $getParameters = @{} - foreach($key in $FunctionParameters.Keys) - { - if($key -ine 'Ensure') - { - $getParameters.Add($key, $FunctionParameters.$key) | Out-Null - } - } - - return $getParameters -} - function Get-IisSitePath { [OutputType([System.String])] @@ -307,8 +276,6 @@ function Remove-IisHandler [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - - [Parameter()] [String] $SiteName ) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof index 135e12d76..d126b524c 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof @@ -8,8 +8,7 @@ class MSFT_xIisModule : OMI_BaseResource [Required, Description("The supported verbs for the module.")] String Verb[]; [Write, Description("The IIS Site to register the module.")] String SiteName; [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; + [Write, Description("The type of the module."), ValueMap{"DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule"}, Values{"DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule"}] String ModuleType; }; From 49706fc846b5edcd00ad287d7361c91af38010ac Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 11 Sep 2019 11:34:56 -0400 Subject: [PATCH 05/36] Update MSFT_xIisModule.psm1 --- DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 3cdfe848b..8ca485d21 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -90,7 +90,7 @@ function Get-TargetResource Verb = $currentVerbs SiteName = $SiteName Ensure = "Present" - ModuleType = $handler.Modules + ModuleType = $handler.Modules.SPlit(',') } } From 542121e62efd98e85f03751a8dd72b862e722cea Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 12 Sep 2019 17:40:47 +0000 Subject: [PATCH 06/36] Introduced Native ReverseDSC Support --- .../MSFT_WebApplicationHandler.psm1 | 29 ++ .../MSFT_xIIsHandler/MSFT_xIisHandler.psm1 | 11 + .../MSFT_xIisFeatureDelegation.psm1 | 45 ++++ .../MSFT_xIisLogging/MSFT_xIisLogging.psm1 | 23 ++ .../MSFT_xIisMimeTypeMapping.psm1 | 28 ++ .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 248 ++++++------------ .../MSFT_xIisModule.schema.mof | 9 +- .../MSFT_xIisModule/xIisModuleDesigner.ps1 | 50 ---- .../MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 | 11 + .../MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 | 46 ++++ .../MSFT_xWebAppPoolDefaults.psm1 | 10 + .../MSFT_xWebApplication.psm1 | 74 ++++++ .../MSFT_xWebConfigKeyValue.psm1 | 10 + .../MSFT_xWebConfigProperty.psm1 | 11 + .../MSFT_xWebConfigPropertyCollection.psm1 | 10 + .../MSFT_xWebSiteDefaults.psm1 | 11 + .../MSFT_xWebVirtualDirectory.psm1 | 49 ++++ DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 106 ++++++++ Modules/ReverseDSCCollector.psm1 | 61 +++++ xWebAdministration.psd1 | 8 +- 20 files changed, 627 insertions(+), 223 deletions(-) delete mode 100644 DSCResources/MSFT_xIisModule/xIisModuleDesigner.ps1 create mode 100644 Modules/ReverseDSCCollector.psm1 diff --git a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 index 989ec2d71..e5a17a94f 100644 --- a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 +++ b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 @@ -380,4 +380,33 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting WebApplicationHandler..." + $handlers = Get-WebConfigurationProperty -Filter "system.webServer/handlers/Add" -Name '.' + + $DSCConfigContent = "" + $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 + $Script:DSCConfigContent += " WebApplicationHandler " + (New-Guid).ToString() + "`r`n {`r`n" + $Script:DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $Script:DSCConfigContent += " }`r`n" + $i++ + } + return $DSCConfigContent +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 index a4cc72ec4..b1ac50384 100644 --- a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 +++ b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 @@ -915,6 +915,17 @@ function Test-TargetResource } } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xIISHandler..." + + return "" +} + #region Helper Functions function Get-Handler diff --git a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 index fb2780fac..9249c0a95 100644 --- a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 +++ b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 @@ -153,6 +153,51 @@ function Test-TargetResource return $false } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xIISFeatureDelegation..." + + $DSCContent = Get-IISFeatureDelegation -Path "system.webServer/*" + + return $DSCContent +} + +function Get-IISFeatureDelegation($Path) +{ + $ConfigSections = Get-WebConfiguration -Filter $Path -Metadata -Recurse + $DSCConfigContent = "" + foreach ($section in $ConfigSections) + { + $params = @{ + Filter = $section.SectionPath.Remove(0,1) + Path = "MACHINE/WEBROOT/APPHOST" + OverrideMode = $false + } + + try + { + $results = Get-TargetResource @params + $DSCConfigContent += " xIISFeatureDelegation " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $module -UseGetTargetResource + $DSCConfigContent += " }`r`n" + + + $ChildPath = $section.SectionPath.Remove(0,1) + "/*" + $ConfigSections = Get-WebConfiguration -Filter $ChildPath -Metadata -Recurse + if ($null -ne $ConfigSections) + { + $DSCConfigContent += Get-IISFeatureDelegation -Path $ChildPath + } + } + catch{} + } + return $DSCConfigContent +} + #region Helper functions <# .SYNOPSIS diff --git a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 index 9ce053274..438fd8d6c 100644 --- a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 +++ b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 @@ -398,6 +398,29 @@ function Test-TargetResource } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xIISLogging..." + + $LogSettings = Get-WebConfiguration -Filter '/system.applicationHost/sites/siteDefaults/Logfile' + + $params = @{ + LogPath = $LogSettings.directory + } + $results = Get-TargetResource @params + $results.LogFlags = $results.LogFlags.Split(',') + $DSCConfigContent += " xIISLogging " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $DSCConfigContent += " }`r`n" + + return $DSCConfigContent + +} + #region Helper functions <# diff --git a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 index ec3380ce2..8ad26c44f 100644 --- a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 +++ b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 @@ -228,6 +228,34 @@ function Test-TargetResource return $desiredConfigurationMatch } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xIISMimeTypeMapping..." + + $MimeMap = Get-WebConfiguration -Filter "system.webServer/staticContent/mimeMap" + + $i = 1 + 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 + $Script:DSCConfigContent += " xIISMimeTypeMapping " + (New-Guid).ToString() + "`r`n {`r`n" + $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $module + $Script:DSCConfigContent += " }`r`n" + $i++ + } +} + #region Helper Functions <# diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 8ca485d21..4787f0299 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,63 +13,47 @@ function Get-TargetResource param ( [Parameter(Mandatory = $true)] - [String] $Path, + [System.String] + $Name, [Parameter(Mandatory = $true)] - [String] $Name, - - [Parameter(Mandatory = $true)] - [String] $RequestPath, + [System.String] + $SiteName = "*", [Parameter(Mandatory = $true)] - [String[]] $Verb, - - [Parameter()] - [ValidateSet("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] - [String] $ModuleType, - - [Parameter()] - [String] $SiteName, + [System.String] + $Code, [Parameter(Mandatory = $true)] [ValidateSet('Present', 'Absent')] - [String] + [System.String] $Ensure ) Assert-Module + # We are looking at the root, therefore remove the asterik + if ('*' -eq $SiteName) + { + $SiteName = "" + } + $module = Get-WebManagedModule -Name $Name -Location $SiteName - $currentVerbs = @() - - $handler = Get-IisHandler -Name $Name -SiteName $SiteName - - if($null -eq $handler) + if($null -eq $module) { $returnValue = @{ - Path = $Path - Name = $Name - RequestPath = $RequestPath - Verb = $Verb - Ensure = "Absent" + Name = $Name + SiteName = $SiteName + Code = $Code + Ensure = "Absent" } } else { - foreach($thisVerb in $handler.Verb) - { - $currentVerbs += $thisVerb - } - - Write-Verbose -Message $LocalizedData.VerboseGetTargetResource - $returnValue = @{ - Path = $handler.ScriptProcessor - Name = $handler.Name - RequestPath = $handler.Path - Verb = $currentVerbs - SiteName = $SiteName - Ensure = "Present" - ModuleType = $handler.Modules.SPlit(',') + Name = $module.Name + SiteName = $SiteName + Code = $module.Type + Ensure = "Present" } } @@ -107,36 +70,21 @@ 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("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] - [String] $ModuleType, + [String] $Code, - [Parameter()] - [String] $SiteName + [Parameter(Mandatory = $true)] + [ValidateSet('Present', 'Absent')] + [String] $Ensure ) $resourceStatus = Get-TargetResource @PSBoundParameters - $resourceTests = Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus - if($resourceTests.Result) - { - return - } if($Ensure -eq 'Present') { @@ -157,14 +105,6 @@ function Set-TargetResource ScriptProcessor = $Path } } - - if(-not $resourceTests.EndPointSetup) - { - Write-Verbose -Message $LocalizedData.VerboseSetTargetAddfastCgi - Add-WebConfiguration /system.webServer/fastCgi iis:\ -Value @{ - FullPath = $Path - } - } } else { @@ -185,109 +125,85 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure, - [Parameter(Mandatory = $true)] - [String] $Path, + [System.String] + $Name, [Parameter(Mandatory = $true)] - [String] $Name, + [System.String] + $SiteName, [Parameter(Mandatory = $true)] - [String] $RequestPath, + [System.String] + $Code, [Parameter(Mandatory = $true)] - [String[]] $Verb, - - [Parameter()] - - [ValidateSet("DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule")] - [String] $ModuleType, - - [Parameter()] - [String] $SiteName + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure ) $resourceStatus = Get-TargetResource @PSBoundParameters - Write-Verbose -Message $LocalizedData.VerboseTestTargetResource - return (Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus).Result } -#region Helper Functions - -function Get-IisSitePath +function Export-TargetResource { - [OutputType([System.String])] [CmdletBinding()] - param - ( - [Parameter()] - [String] $SiteName - ) + [OutputType([System.String])] - if (-not $SiteName) - { - return 'IIS:\' - } - else + $InformationPreference = "Continue" + Write-Information "Extracting xIISModule..." + + $Modules = Get-WebManagedModule + + Write-Information " Modules Defined at Root Level:" + $i = 1 + foreach ($Module in $Modules) { - return Join-Path 'IIS:\sites\' $SiteName + Write-Information " [$i/$($Modules.Count)] $($Module.Name)" + $params = @{ + Name = $Module.Name + SiteName = "*" + Code = $Module.Type + Ensure = "Present" + } + $results = Get-TargetResource @params + $DSCConfigContent += " xIISModule " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $dscmodule + $DSCConfigContent += " }`r`n" + $i++ } -} -function Get-IisHandler -{ - <# - .NOTES - Get a list on IIS handlers - #> - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] $Name, + $sites = Get-Website - [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} + foreach ($site in $sites) + { + Write-Information " Modules Defined at Site Level {$($site.Name)}" + $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 + $DSCConfigContent += " xIISModule " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $dscmodule + $DSCConfigContent += " }`r`n" + $i++ + } + } + return $DSCConfigContent } -function Remove-IisHandler -{ - <# - .NOTES - Remove an IIS Handler - #> - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] $Name, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] $SiteName - ) +#region Helper Functions - $handler = Get-IisHandler @PSBoundParameters - if($handler) - { - Clear-WebConfiguration -PSPath $handler.PSPath ` - -Filter $handler.ItemXPath ` - -Location $handler.Location - } -} function Test-TargetResourceImpl { diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof index d126b524c..6be33586b 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof @@ -2,13 +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; + [Write, 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{"DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule"}, Values{"DefaultDocumentModule","DirectoryListingModule","FastCgiModule","ProtocolSupportModule","StaticFileModule"}] String ModuleType; }; 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..f9621e5c3 100644 --- a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 +++ b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 @@ -174,4 +174,15 @@ function Test-TargetResource return $false; } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xSSLSettings..." + + return "" +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 index a5368df53..fe6a4951b 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -977,6 +977,52 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebAppPool..." + + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + $appPools = Get-WebConfiguration -Filter '/system.applicationHost/applicationPools/add' + $DSCConfigContent = "" + $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") + { + $securePassword = ConvertTo-SecureString $appPool.ProcessModel.password -AsPlainText + $creds = New-Object System.Automation.PSCredential($appPool.ProcessModel.username, $securePassword) + $results.Credential = "`$Creds" + $appPool.ProcessModel.username + } + else + { + $results.Remove("Credential") + } + + Write-Verbose "All Parameters with values" + $results | ConvertTo-Json | Write-Verbose + + $DSCConfigContent += "`r`n" + $DSCConfigContent += " xWebAppPool " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $DSCConfigContent += " }`r`n" + } + return $DSCConfigContent +} + #region Helper Functions function Get-Property diff --git a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 index 1919de41b..df7802ff0 100644 --- a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 +++ b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 @@ -121,6 +121,16 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebAppPoolDefaults..." + return "" +} + #region Helper Functions function Confirm-Value diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index 9e7cae8fc..459acafb8 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -504,6 +504,80 @@ function Confirm-UniqueEnabledProtocols return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebApplication..." + + $webSites = Get-WebSite + + $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) + { + 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 + + $AuthenticationInfo = "MSFT_xWebApplicationAuthenticationInformation`r`n {`r`n" + + $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)" + $AuthenticationInfo += " $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value + ";`r`n" + } + + $results.AuthenticationInfo = $AuthenticationInfo + $results.SslFlags = $results.SslFlags.Split(",") + $results.EnabledProtocols = $results.EnabledProtocols.Split(",") + + Write-Verbose "All Parameters with values" + $results | ConvertTo-Json | Write-Verbose + + $Script:dscConfigContent += " xWebApplication " + (New-GUID).ToString() + "`r`n {`r`n" + $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $Script:dscConfigContent += " }`r`n" + $j++ + } + } + $i++ + } +} + #region Helper Functions <# diff --git a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 index 60efcf45d..2944c808d 100644 --- a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 +++ b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 @@ -242,6 +242,16 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebConfigKeyValue..." + return "" +} + # region Helper Functions function Add-Item diff --git a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 index 5ec082c9a..9565169f7 100644 --- a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 +++ b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 @@ -252,6 +252,17 @@ function Test-TargetResource return $true } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebConfigProperty..." + + return "" +} + # region Helper Functions <# diff --git a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 index efb4a9c7e..dd8ea6ffa 100644 --- a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 +++ b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 @@ -426,6 +426,16 @@ function Test-TargetResource } } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebConfigPropertyCollection..." + return "" +} + # region Helper Functions <# diff --git a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 index 2953601f3..0f7b5da59 100644 --- a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 +++ b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 @@ -169,6 +169,17 @@ function Test-TargetResource } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebSiteDefaults..." + + return "" +} + #region Helper Functions function Confirm-Value diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index 86db784c3..24cbd63f8 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -210,4 +210,53 @@ function Test-TargetResource return $false } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebVirtualDirectory..." + $webSites = Get-WebSite + + $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.path)" + Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.path)" + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + <# Setting Primary Keys #> + $params.Name = $webvirtualdirectory.Path + $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 + + $Script:dscConfigContent += " xWebVirtualDirectory " + (New-Guid).ToString() + "`r`n {`r`n" + $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $Script:dscConfigContent += " }`r`n" + $j++ + } + } + } + $i++ +} + Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 154c9509c..6470e42c2 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1119,6 +1119,112 @@ function Test-TargetResource return $inDesiredState } +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + Write-Information "Extracting xWebSite..." + + $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot + + $webSites = Get-WebSite + + $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) + { + $currentBinding = "MSFT_xWebBindingInformation`r`n {`r`n" + $currentBinding += " Protocol = `"$($binding.Protocol)`"" + "`r`n" + $currentBinding += " SslFlags = $($binding.sslFlags)" + "`r`n" + + if ($binding.protocol -match "^http") + { + $bindingInfo = $binding.bindingInformation.split(":") + $ipAddress = $bindingInfo[0] + $port = $bindingInfo[1] + $hostName = $bindingInfo[2] + $currentBinding += " IPAddress = `"$ipAddress`"" + ";`r`n" + $currentBinding += " Port = $port" + ";`r`n" + $currentBinding += " Hostname = `"$hostName`"" + ";`r`n" + if ($binding.CertificateStoreName -eq "My" -or $binding.CertificateStoreName -eq "WebHosting") + { + if ($null -ne $binding.CertificateHash -and "" -ne $binding.CertificateHash) + { + $currentBinding += " CertificateThumbprint = `"$($binding.CertificateHash)`"`r`n" + } + $currentBinding += " CertificateStoreName = `"$($binding.CertificateStoreName)`"`r`n" + } + } + else + { + $currentBinding += " BindingInformation = `"$($binding.bindingInformation)`"" + ";`r`n" + } + + $currentBinding += " }" + + $results.BindingInfo += $currentBinding + } + + $results.LogCustomFields = @(); + + [string]$LogCustomFields = $null + foreach ($customfield in $webSite.logfile.customFields.Collection) + { + $LogCustomFields += "MSFT_LogCustomFieldInformation`r`n{`r`n" + $LogCustomFields += " logFieldName = `"$($customfield.logFieldName)`"`r`n" + $LogCustomFields += " sourceName = `"$($customfield.sourceName)`"`r`n" + $LogCustomFields += "` sourceType = `"$($customfield.sourceType)`"`r`n" + $LogCustomFields += "}" + } + + $results.LogCustomFields = $LogCustomFields + + $AuthenticationInfo = "MSFT_xWebAuthenticationInformation`r`n {`r`n" + + $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)" + $AuthenticationInfo += " $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value + "`r`n" + } + + $results.AuthenticationInfo = $AuthenticationInfo + $results.LogFlags = $results.LogFlags.Split(",") + + Write-Verbose "All Parameters with values" + $results | ConvertTo-Json | Write-Verbose + + $DSCConfigContent += " xWebSite " + (New-Guid).ToString() + "`r`n {`r`n" + $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + $DSCConfigContent += " }`r`n" + } + + return $DSCConfigContent +} + #region Helper Functions <# diff --git a/Modules/ReverseDSCCollector.psm1 b/Modules/ReverseDSCCollector.psm1 new file mode 100644 index 000000000..4720327c0 --- /dev/null +++ b/Modules/ReverseDSCCollector.psm1 @@ -0,0 +1,61 @@ +function Export-WebAdministrationConfiguration +{ + [CmdletBinding()] + [OutputType([System.String])] + + $InformationPreference = "Continue" + + $DSCContent = "Configuration WebAdministrationConfiguration`r`n{`r`n" + $DSCContent += " Import-DSCResource -ModuleName xWebAdministration`r`n`r`n" + $DSCContent += " Node localhost`r`n" + $DSCContent += " {`r`n" + + $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 + $DSCContent += Export-TargetResource + } + + $DSCContent += " }`r`n}`r`n" + + #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 + "HyperVConfiguration.ps1" + $DSCContent | Out-File $outputDSCFile + + Invoke-Item -Path $OutputDSCPath + #endregion +} diff --git a/xWebAdministration.psd1 b/xWebAdministration.psd1 index 3ef0cfa8c..5afda7854 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.5"; }) + # 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' } From 553b8d1e4321c55a1a47adea0f8ff3f43d20bb18 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 12 Sep 2019 17:45:50 +0000 Subject: [PATCH 07/36] Update appveyor.yml --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) 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' From 5594221d00d71ed09e39b33ecbd59fa951761d4d Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 12 Sep 2019 18:03:44 +0000 Subject: [PATCH 08/36] Fixed tests --- .../MSFT_xIisFeatureDelegation.psm1 | 14 ++++++++++++-- DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 | 4 +++- .../MSFT_xIisModule/MSFT_xIisModule.schema.mof | 2 +- .../MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 | 2 -- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 index 9249c0a95..76de11a30 100644 --- a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 +++ b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 @@ -166,8 +166,15 @@ function Export-TargetResource return $DSCContent } -function Get-IISFeatureDelegation($Path) +function Get-IISFeatureDelegation { + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [String] + $Path + ) $ConfigSections = Get-WebConfiguration -Filter $Path -Metadata -Recurse $DSCConfigContent = "" foreach ($section in $ConfigSections) @@ -193,7 +200,10 @@ function Get-IISFeatureDelegation($Path) $DSCConfigContent += Get-IISFeatureDelegation -Path $ChildPath } } - catch{} + catch + { + Write-Error $_ + } } return $DSCConfigContent } diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 4787f0299..4c2c5bbbe 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -18,7 +18,7 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SiteName = "*", + $SiteName, [Parameter(Mandatory = $true)] [System.String] @@ -31,6 +31,7 @@ function Get-TargetResource ) Assert-Module + Write-Verbose "Calling Get-TargetResource for $Name" # We are looking at the root, therefore remove the asterik if ('*' -eq $SiteName) { @@ -144,6 +145,7 @@ function Test-TargetResource ) $resourceStatus = Get-TargetResource @PSBoundParameters + Write-Verbose "Testing $Name" return (Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus).Result } diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof index 6be33586b..41f8fcb66 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.schema.mof @@ -4,7 +4,7 @@ class MSFT_xIisModule : OMI_BaseResource { [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; - [Write, Description("The code associated with the module to register")] String Code; + [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; }; diff --git a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 index fe6a4951b..bf0d600a2 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -1003,8 +1003,6 @@ function Export-TargetResource if($appPool.ProcessModel -eq "SpecificUser") { - $securePassword = ConvertTo-SecureString $appPool.ProcessModel.password -AsPlainText - $creds = New-Object System.Automation.PSCredential($appPool.ProcessModel.username, $securePassword) $results.Credential = "`$Creds" + $appPool.ProcessModel.username } else From f886dcb8a2f6ea31db1c002fa5f30866b8c25d1b Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 12 Sep 2019 19:25:06 +0000 Subject: [PATCH 09/36] Fixed tests --- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 13 +-- Tests/Unit/MSFT_xIISModule.Tests.ps1 | 81 +++++++++++++++++++ 2 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 Tests/Unit/MSFT_xIISModule.Tests.ps1 diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 4c2c5bbbe..afbc0f846 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -24,10 +24,10 @@ function Get-TargetResource [System.String] $Code, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateSet('Present', 'Absent')] [System.String] - $Ensure + $Ensure= "Present" ) Assert-Module @@ -80,9 +80,10 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [String] $Code, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateSet('Present', 'Absent')] - [String] $Ensure + [System.String] + $Ensure= "Present" ) $resourceStatus = Get-TargetResource @PSBoundParameters @@ -138,10 +139,10 @@ function Test-TargetResource [System.String] $Code, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateSet('Present', 'Absent')] [System.String] - $Ensure + $Ensure = "Present" ) $resourceStatus = Get-TargetResource @PSBoundParameters diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 new file mode 100644 index 000000000..f8ade36ec --- /dev/null +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -0,0 +1,81 @@ +$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 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 + } + } + } + #endregion +} + +finally +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} From 9b4e59881db4353055aca1ee7a31e955cd597109 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 13 Sep 2019 00:00:27 +0000 Subject: [PATCH 10/36] Update MSFT_xIISModule.Tests.ps1 --- Tests/Unit/MSFT_xIISModule.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 index f8ade36ec..c6a04980e 100644 --- a/Tests/Unit/MSFT_xIISModule.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -72,6 +72,7 @@ try } } } + } #endregion } From d14ea6fd4a0323f5750a309f0b5d2a5307b0267f Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 13 Sep 2019 00:40:50 +0000 Subject: [PATCH 11/36] Fixed tests --- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 110 ++---------------- 1 file changed, 7 insertions(+), 103 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index afbc0f846..e9d9238ce 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -90,15 +90,14 @@ function Set-TargetResource if($Ensure -eq 'Present') { + Write-Verbose "Setting Configuration" if($resourceTests.ModulePresent -and -not $resourceTests.ModuleConfigured) { - Write-Verbose -Message $LocalizedData.VerboseSetTargetRemoveHandler Remove-IisHandler -Name $Name -SiteName $SiteName } if(-not $resourceTests.ModulePresent -or -not $resourceTests.ModuleConfigured) { - Write-Verbose -Message $LocalizedData.VerboseSetTargetAddHandler Add-webconfiguration /system.webServer/handlers iis:\ -Value @{ Name = $Name Path = $RequestPath @@ -146,8 +145,13 @@ function Test-TargetResource ) $resourceStatus = Get-TargetResource @PSBoundParameters + $result = $true + if ($resourceStatus.Ensure -ne $Ensure -or $resourceStatus.SiteName -ne $SiteName -or $resourceStatus.Code -ne $Code) + { + return $false + } Write-Verbose "Testing $Name" - return (Test-TargetResourceImpl @PSBoundParameters -ResourceStatus $resourceStatus).Result + return $result } function Export-TargetResource @@ -207,106 +211,6 @@ function Export-TargetResource #region Helper Functions - -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, - - [Parameter(Mandatory = $true)] - [HashTable] $resourceStatus - ) - - $matchedVerbs = @() - $mismatchVerbs =@() - foreach($thisVerb in $resourceStatus.Verb) - { - if($Verb -icontains $thisVerb) - { - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplVerb ` - -f $Verb) - $matchedVerbs += $thisVerb - } - else - { - Write-Verbose -Message ($LocalizedData.VerboseTestTargetResourceImplExtraVerb ` - -f $Verb) - $mismatchVerbs += $thisVerb - } - } - - $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 - } - } -} - - #endregion Export-ModuleMember -Function *-TargetResource From 38be70960e4064ba3d5bcb618eacf86ea68f3111 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 13 Sep 2019 01:00:58 +0000 Subject: [PATCH 12/36] Update MSFT_xIisModule.psm1 --- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index e9d9238ce..144b48fcb 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -88,29 +88,22 @@ function Set-TargetResource $resourceStatus = Get-TargetResource @PSBoundParameters - if($Ensure -eq 'Present') + if ($Ensure -eq 'Present' -and $resourceStatus.Ensure -eq 'Absent') { Write-Verbose "Setting Configuration" - if($resourceTests.ModulePresent -and -not $resourceTests.ModuleConfigured) - { - Remove-IisHandler -Name $Name -SiteName $SiteName - } if(-not $resourceTests.ModulePresent -or -not $resourceTests.ModuleConfigured) { - Add-webconfiguration /system.webServer/handlers iis:\ -Value @{ - Name = $Name - Path = $RequestPath - Verb = $Verb -join ',' - Module = $ModuleType - ScriptProcessor = $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 -Name $Name -SiteName $SiteName + Remove-WebManagedModule -Location $SiteName -Name $NAme } } From e2126231772be3b297fc2fd23450b450f15f4c7c Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 13 Sep 2019 01:17:08 +0000 Subject: [PATCH 13/36] Fixes mocks --- DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 | 5 +---- Tests/Unit/MSFT_xIISModule.Tests.ps1 | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index 144b48fcb..bb895debf 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -92,10 +92,7 @@ function Set-TargetResource { Write-Verbose "Setting Configuration" - if(-not $resourceTests.ModulePresent -or -not $resourceTests.ModuleConfigured) - { - New-WebManagedModule -Name $Name -Location $SiteName -Type $Code - } + New-WebManagedModule -Name $Name -Location $SiteName -Type $Code } elseif ($Ensure -eq 'Present' -and $resourceStatus.Ensure -eq 'Present') { diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 index c6a04980e..a61b2b202 100644 --- a/Tests/Unit/MSFT_xIISModule.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -57,6 +57,10 @@ try return $null } + Mock -CommandName New-WebManagedModule -MockWith { + return $null + } + Mock -CommandName Assert-Module -MockWith {} It 'Should Absent from the Get Method' { From b07efda6813b87137d1dca21dfeaf3374d63cebe Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 13 Sep 2019 14:45:42 -0400 Subject: [PATCH 14/36] Updated Resources --- .../MSFT_WebApplicationHandler.psm1 | 13 ++-- .../MSFT_xIIsHandler/MSFT_xIisHandler.psm1 | 25 ++++++- .../MSFT_xIisFeatureDelegation.psm1 | 66 ++++++++----------- .../MSFT_xIisLogging/MSFT_xIisLogging.psm1 | 12 ++-- .../MSFT_xIisMimeTypeMapping.psm1 | 11 +++- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 50 +++++++++----- .../MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 | 23 ++++++- .../MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 | 15 +++-- .../MSFT_xWebAppPoolDefaults.psm1 | 14 +++- .../MSFT_xWebApplication.psm1 | 22 +++++-- .../MSFT_xWebConfigKeyValue.psm1 | 33 +++++++++- .../MSFT_xWebConfigProperty.psm1 | 3 +- .../MSFT_xWebConfigPropertyCollection.psm1 | 3 +- .../MSFT_xWebSiteDefaults.psm1 | 22 +++++-- .../MSFT_xWebVirtualDirectory.psm1 | 13 ++-- DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 61 +++++++++-------- Modules/ReverseDSCCollector.psm1 | 22 ++++--- 17 files changed, 274 insertions(+), 134 deletions(-) diff --git a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 index e5a17a94f..fcd7671ba 100644 --- a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 +++ b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 @@ -384,12 +384,13 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting WebApplicationHandler..." $handlers = Get-WebConfigurationProperty -Filter "system.webServer/handlers/Add" -Name '.' - $DSCConfigContent = "" + $sb = [System.Text.StringBuilder]::new() $i = 1 foreach ($handler in $handlers) { @@ -401,12 +402,14 @@ function Export-TargetResource } $results = Get-TargetResource @params - $Script:DSCConfigContent += " WebApplicationHandler " + (New-Guid).ToString() + "`r`n {`r`n" - $Script:DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $Script:DSCConfigContent += " }`r`n" + [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 $DSCConfigContent + return $sb.ToString() } Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 index b1ac50384..417b03069 100644 --- a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 +++ b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 @@ -919,11 +919,34 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xIISHandler..." - return "" + $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 diff --git a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 index 76de11a30..047dcc9a9 100644 --- a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 +++ b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 @@ -157,55 +157,43 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() - $InformationPreference = "Continue" + $InformationPreference = 'Continue' Write-Information "Extracting xIISFeatureDelegation..." - $DSCContent = Get-IISFeatureDelegation -Path "system.webServer/*" - - return $DSCContent -} - -function Get-IISFeatureDelegation -{ - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [String] - $Path - ) - $ConfigSections = Get-WebConfiguration -Filter $Path -Metadata -Recurse - $DSCConfigContent = "" - foreach ($section in $ConfigSections) + $configSections = Get-WebConfiguration -Filter "system.webServer/*" -Metadata -Recurse + $sb = [System.Text.StringBuilder]::new() + $i = 1 + foreach ($section in $configSections) { - $params = @{ - Filter = $section.SectionPath.Remove(0,1) - Path = "MACHINE/WEBROOT/APPHOST" - OverrideMode = $false - } - - try + if ($null -ne $section.SectionPath) { - $results = Get-TargetResource @params - $DSCConfigContent += " xIISFeatureDelegation " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $module -UseGetTargetResource - $DSCConfigContent += " }`r`n" - + Write-Information " [$i/$($configSections.Count)] $($section.SectionPath.Remove(0,1))" + $params = @{ + Filter = $section.SectionPath.Remove(0,1) + Path = "MACHINE/WEBROOT/APPHOST" + OverrideMode = "Deny" + } - $ChildPath = $section.SectionPath.Remove(0,1) + "/*" - $ConfigSections = Get-WebConfiguration -Filter $ChildPath -Metadata -Recurse - if ($null -ne $ConfigSections) + try { - $DSCConfigContent += Get-IISFeatureDelegation -Path $ChildPath + $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 $_ } } - catch - { - Write-Error $_ - } + $i++ } - return $DSCConfigContent + + return $sb.ToString() } #region Helper functions diff --git a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 index 438fd8d6c..bd57c1605 100644 --- a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 +++ b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 @@ -402,6 +402,7 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xIISLogging..." @@ -411,13 +412,16 @@ function Export-TargetResource $params = @{ LogPath = $LogSettings.directory } + $sb = [System.Text.StringBuilder]::new() $results = Get-TargetResource @params $results.LogFlags = $results.LogFlags.Split(',') - $DSCConfigContent += " xIISLogging " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $DSCConfigContent += " }`r`n" + [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 $DSCConfigContent + return $sb.ToString() } diff --git a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 index 8ad26c44f..146fc06f8 100644 --- a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 +++ b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 @@ -232,6 +232,7 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xIISMimeTypeMapping..." @@ -239,6 +240,7 @@ function Export-TargetResource $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)" @@ -249,11 +251,14 @@ function Export-TargetResource Ensure = "Present" } $results = Get-TargetResource @params - $Script:DSCConfigContent += " xIISMimeTypeMapping " + (New-Guid).ToString() + "`r`n {`r`n" - $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $module - $Script:DSCConfigContent += " }`r`n" + [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 bb895debf..fe05c4d70 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -148,6 +148,7 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xIISModule..." @@ -155,6 +156,7 @@ function Export-TargetResource $Modules = Get-WebManagedModule Write-Information " Modules Defined at Root Level:" + $sb = [System.Text.StringBuilder]::new() $i = 1 foreach ($Module in $Modules) { @@ -166,9 +168,11 @@ function Export-TargetResource Ensure = "Present" } $results = Get-TargetResource @params - $DSCConfigContent += " xIISModule " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $dscmodule - $DSCConfigContent += " }`r`n" + [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++ } @@ -177,25 +181,35 @@ function Export-TargetResource foreach ($site in $sites) { Write-Information " Modules Defined at Site Level {$($site.Name)}" - $Modules = Get-WebManagedModule -Location $site.Name - $i = 1 - foreach ($Module in $Modules) + + try { - Write-Information " [$i/$($Modules.Count)] $($Module.Name)" - $params =@{ - Name = $Module.Name - SiteName = $site.Name - Code = $Module.Type - Ensure = "Present" + $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++ } - $results = Get-TargetResource @params - $DSCConfigContent += " xIISModule " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $dscmodule - $DSCConfigContent += " }`r`n" - $i++ + } + catch + { + Write-Verbose "Modules in site $site.Name are being override at a parent level." } } - return $DSCConfigContent + return $sb.ToString() } #region Helper Functions diff --git a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 index f9621e5c3..44a178e74 100644 --- a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 +++ b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 @@ -178,11 +178,32 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xSSLSettings..." - return "" + $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 bf0d600a2..fa488e026 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -981,6 +981,7 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xWebAppPool..." @@ -988,7 +989,7 @@ function Export-TargetResource $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot $appPools = Get-WebConfiguration -Filter '/system.applicationHost/applicationPools/add' - $DSCConfigContent = "" + $sb = [System.Text.StringBuilder]::new() $i = 1 foreach($appPool in $appPools) { @@ -1000,7 +1001,6 @@ function Export-TargetResource $results = Get-TargetResource @params - if($appPool.ProcessModel -eq "SpecificUser") { $results.Credential = "`$Creds" + $appPool.ProcessModel.username @@ -1013,12 +1013,13 @@ function Export-TargetResource Write-Verbose "All Parameters with values" $results | ConvertTo-Json | Write-Verbose - $DSCConfigContent += "`r`n" - $DSCConfigContent += " xWebAppPool " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $DSCConfigContent += " }`r`n" + [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 $DSCConfigContent + return $sb.ToString() } #region Helper Functions diff --git a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 index df7802ff0..1d8434c73 100644 --- a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 +++ b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 @@ -125,10 +125,22 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xWebAppPoolDefaults..." - return "" + $sb = [System.Text.StringBuilder]::new() + $params = @{ + ApplyTo = "Machine" + } + $results = Get-TargetResource @params + + [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 diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index 459acafb8..90a10963f 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -508,12 +508,13 @@ 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) { @@ -525,6 +526,7 @@ function Export-TargetResource $j = 1 foreach($webapplication in $webApplications) { + $authSb = [System.Text.StringBuilder]::new() Write-Information "[$j/$($webApplications.Count)] $($webApplication.Path)" <# Setting Primary Keys #> @@ -544,7 +546,8 @@ function Export-TargetResource Write-Verbose "All Parameters as follows" $results | ConvertTo-Json | Write-Verbose - $AuthenticationInfo = "MSFT_xWebApplicationAuthenticationInformation`r`n {`r`n" + [void]$authSb.AppendLine( "MSFT_xWebApplicationAuthenticationInformation") + [void]$authSb.AppendLine(" {") $AuthenticationTypes = @("BasicAuthentication","AnonymousAuthentication","DigestAuthentication","WindowsAuthentication") @@ -558,24 +561,29 @@ function Export-TargetResource -Name enabled ` -PSPath "IIS:\Sites\$location" Write-Verbose "$authenticationtype : $($prop.Value)" - $AuthenticationInfo += " $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value + ";`r`n" + [void]$authSb.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } + [void]$authSb.AppendLine(" }") - $results.AuthenticationInfo = $AuthenticationInfo + $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 - $Script:dscConfigContent += " xWebApplication " + (New-GUID).ToString() + "`r`n {`r`n" - $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $Script:dscConfigContent += " }`r`n" + [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 diff --git a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 index 2944c808d..fe73759c1 100644 --- a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 +++ b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 @@ -246,10 +246,41 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xWebConfigKeyValue..." - return "" + + $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 + + [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 diff --git a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 index 9565169f7..a51f230f5 100644 --- a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 +++ b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 @@ -256,9 +256,10 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" - Write-Information "Extracting xWebConfigProperty..." + Write-Information "Extracting xWebConfigProperty is not supported by ReverseDSC." return "" } diff --git a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 index dd8ea6ffa..6f33e4214 100644 --- a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 +++ b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 @@ -430,9 +430,10 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" - Write-Information "Extracting xWebConfigPropertyCollection..." + Write-Information "Extracting xWebConfigPropertyCollection is not supported by ReverseDSC" return "" } diff --git a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 index 0f7b5da59..e574913af 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 } } @@ -173,11 +173,23 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xWebSiteDefaults..." + $sb = [System.Text.StringBuilder]::new() - return "" + $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 diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index 24cbd63f8..8daa35eb5 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -214,11 +214,13 @@ 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) { @@ -249,14 +251,17 @@ function Export-TargetResource Write-Verbose "All Parameters with values" $results | ConvertTo-Json | Write-Verbose - $Script:dscConfigContent += " xWebVirtualDirectory " + (New-Guid).ToString() + "`r`n {`r`n" - $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $Script:dscConfigContent += " }`r`n" + [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++ } - $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 6470e42c2..7ad5b6237 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1123,6 +1123,7 @@ function Export-TargetResource { [CmdletBinding()] [OutputType([System.String])] + param() $InformationPreference = "Continue" Write-Information "Extracting xWebSite..." @@ -1130,7 +1131,7 @@ function Export-TargetResource $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot $webSites = Get-WebSite - + $sb = [System.Text.StringBuilder]::new() $i = 1 foreach($website in $webSites) { @@ -1148,9 +1149,11 @@ function Export-TargetResource foreach($binding in $website.Bindings.Collection) { - $currentBinding = "MSFT_xWebBindingInformation`r`n {`r`n" - $currentBinding += " Protocol = `"$($binding.Protocol)`"" + "`r`n" - $currentBinding += " SslFlags = $($binding.sslFlags)" + "`r`n" + $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") { @@ -1158,43 +1161,46 @@ function Export-TargetResource $ipAddress = $bindingInfo[0] $port = $bindingInfo[1] $hostName = $bindingInfo[2] - $currentBinding += " IPAddress = `"$ipAddress`"" + ";`r`n" - $currentBinding += " Port = $port" + ";`r`n" - $currentBinding += " Hostname = `"$hostName`"" + ";`r`n" + [void]$bindingContent.AppendLine(" IPAddress = `"$ipAddress`"") + [void]$bindingContent.AppendLine(" Port = $port") + [void]$bindingContent.AppendLine(" Hostname = `"$hostName`"") if ($binding.CertificateStoreName -eq "My" -or $binding.CertificateStoreName -eq "WebHosting") { if ($null -ne $binding.CertificateHash -and "" -ne $binding.CertificateHash) { - $currentBinding += " CertificateThumbprint = `"$($binding.CertificateHash)`"`r`n" + [void]$bindingContent.AppendLine(" CertificateThumbprint = `"$($binding.CertificateHash)`"") } - $currentBinding += " CertificateStoreName = `"$($binding.CertificateStoreName)`"`r`n" + [void]$bindingContent.AppendLine(" CertificateStoreName = `"$($binding.CertificateStoreName)`"") } } else { - $currentBinding += " BindingInformation = `"$($binding.bindingInformation)`"" + ";`r`n" + [void]$bindingContent.AppendLine(" BindingInformation = `"$($binding.bindingInformation)`"") } - $currentBinding += " }" + [void]$bindingContent.AppendLine(" }") - $results.BindingInfo += $currentBinding + $results.BindingInfo += $bindingContent.ToString() } $results.LogCustomFields = @(); [string]$LogCustomFields = $null + $logSB = [System.Text.StringBuilder]::new() foreach ($customfield in $webSite.logfile.customFields.Collection) { - $LogCustomFields += "MSFT_LogCustomFieldInformation`r`n{`r`n" - $LogCustomFields += " logFieldName = `"$($customfield.logFieldName)`"`r`n" - $LogCustomFields += " sourceName = `"$($customfield.sourceName)`"`r`n" - $LogCustomFields += "` sourceType = `"$($customfield.sourceType)`"`r`n" - $LogCustomFields += "}" + [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 = $LogCustomFields - - $AuthenticationInfo = "MSFT_xWebAuthenticationInformation`r`n {`r`n" + $results.LogCustomFields = $logSB.ToString() + $authSB = [System.Text.StringBuilder]::new() + [void]$authSB.AppendLine(" MSFT_xWebAuthenticationInformation") + [void]$authSB.AppendLine(" {") $AuthenticationTypes = @("BasicAuthentication","AnonymousAuthentication","DigestAuthentication","WindowsAuthentication") @@ -1208,21 +1214,24 @@ function Export-TargetResource -Name enabled ` -Location $location Write-Verbose "$authenticationtype : $($prop.Value)" - $AuthenticationInfo += " $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value + "`r`n" + [void]$authSB.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } + [void]$authSB.Append(" }") - $results.AuthenticationInfo = $AuthenticationInfo + $results.AuthenticationInfo = $authSB.ToString() $results.LogFlags = $results.LogFlags.Split(",") Write-Verbose "All Parameters with values" $results | ConvertTo-Json | Write-Verbose - $DSCConfigContent += " xWebSite " + (New-Guid).ToString() + "`r`n {`r`n" - $DSCConfigContent += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $DSCConfigContent += " }`r`n" + [void]$sb.AppendLine(" xWebSite " + (New-Guid).ToString()) + [void]$sb.AppendLine(" {") + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot + [void]$sb.Append($dscBlock) + [void]$sb.AppendLine(" }") } - return $DSCConfigContent + return $sb.ToString() } #region Helper Functions diff --git a/Modules/ReverseDSCCollector.psm1 b/Modules/ReverseDSCCollector.psm1 index 4720327c0..9dd957955 100644 --- a/Modules/ReverseDSCCollector.psm1 +++ b/Modules/ReverseDSCCollector.psm1 @@ -3,12 +3,12 @@ function Export-WebAdministrationConfiguration [CmdletBinding()] [OutputType([System.String])] - $InformationPreference = "Continue" - - $DSCContent = "Configuration WebAdministrationConfiguration`r`n{`r`n" - $DSCContent += " Import-DSCResource -ModuleName xWebAdministration`r`n`r`n" - $DSCContent += " Node localhost`r`n" - $DSCContent += " {`r`n" + $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\" ` @@ -18,10 +18,12 @@ function Export-WebAdministrationConfiguration foreach ($ResourceModule in $AllResources) { Import-Module $ResourceModule.FullName | Out-Null - $DSCContent += Export-TargetResource + $exportString = Export-TargetResource + [void]$sb.Append($exportString) } - $DSCContent += " }`r`n}`r`n" + [void]$sb.AppendLine(" }") + [void]$sb.AppendLine("}") #region Prompt the user for a location to save the extract and generate the files if ($null -eq $Path -or "" -eq $Path) @@ -53,8 +55,8 @@ function Export-WebAdministrationConfiguration { $OutputDSCPath += "\" } - $outputDSCFile = $OutputDSCPath + "HyperVConfiguration.ps1" - $DSCContent | Out-File $outputDSCFile + $outputDSCFile = $OutputDSCPath + "WebAdministrationConfiguration.ps1" + $sb.ToString() | Out-File $outputDSCFile Invoke-Item -Path $OutputDSCPath #endregion From 3e7781de2b2b6a3b869d53dbcbf79a48c0e17f23 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Sat, 14 Sep 2019 11:51:26 -0400 Subject: [PATCH 15/36] Trying out unit tests --- Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 index 5d0890e0a..de613ebbb 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 + + It 'Should Export all instances' { + Export-TargetResource @GetTargetRequiredParameters + } + } + } } } From a41b691109aa5b5607d740da738c5b29be39656c Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Sat, 14 Sep 2019 12:01:46 -0400 Subject: [PATCH 16/36] Update MSFT_WebApplicationHandler.tests.ps1 --- Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 index de613ebbb..700b65434 100644 --- a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 +++ b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 @@ -377,7 +377,7 @@ try Mock Get-WebConfigurationProperty It 'Should Export all instances' { - Export-TargetResource @GetTargetRequiredParameters + Export-TargetResource } } } From 7d7aed028afed18811e451889f3735a082ac2000 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Sun, 15 Sep 2019 16:28:17 -0400 Subject: [PATCH 17/36] added tests --- .../Unit/MSFT_xIISFeatureDelegation.Tests.ps1 | 13 +++++++++++++ Tests/Unit/MSFT_xIISHandler.Tests.ps1 | 12 ++++++++++++ Tests/Unit/MSFT_xIISLogging.Tests.ps1 | 16 ++++++++++++++++ Tests/Unit/MSFT_xIISModule.Tests.ps1 | 18 ++++++++++++++++++ Tests/Unit/MSFT_xIisMimeTypeMapping.Tests.ps1 | 11 +++++++++++ 5 files changed, 70 insertions(+) diff --git a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 index c78334356..8ebfdf709 100644 --- a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 @@ -168,6 +168,19 @@ try } } } + Describe 'MSFT_IISFeatureDelegation/Export-TargetResource' { + + Context 'Export Configuration' { + + Mock -CommandName Get-WebConfiguration -MockWith { return $mockDenyOverrideMode } + + $overrideMode = Get-OverrideMode @getOverrideModeParameters + + 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 index a61b2b202..b5efaabfc 100644 --- a/Tests/Unit/MSFT_xIISModule.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -76,6 +76,24 @@ try } } } + + 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 } 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 From 7b04e2f0ad0ce5c8f8ca97c67c3ebe0280c93537 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 09:28:33 -0400 Subject: [PATCH 18/36] Added remaining Tests --- .../Unit/MSFT_xIISFeatureDelegation.Tests.ps1 | 2 - Tests/Unit/MSFT_xSSLSettings.Tests.ps1 | 11 ++ Tests/Unit/MSFT_xWebAppPool.Tests.ps1 | 81 +++++++++++++ Tests/Unit/MSFT_xWebAppPoolDefaults.Tests.ps1 | 25 ++++ Tests/Unit/MSFT_xWebApplication.Tests.ps1 | 43 +++++++ Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 | 18 +++ Tests/Unit/MSFT_xWebConfigProperty.tests.ps1 | 9 ++ ...SFT_xWebConfigPropertyCollection.tests.ps1 | 9 ++ .../Unit/MSFT_xWebVirtualDirectory.Tests.ps1 | 28 ++++- Tests/Unit/MSFT_xWebsite.Tests.ps1 | 114 ++++++++++++++++++ 10 files changed, 334 insertions(+), 6 deletions(-) diff --git a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 index 8ebfdf709..4920073de 100644 --- a/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISFeatureDelegation.Tests.ps1 @@ -174,8 +174,6 @@ try Mock -CommandName Get-WebConfiguration -MockWith { return $mockDenyOverrideMode } - $overrideMode = Get-OverrideMode @getOverrideModeParameters - It 'Should Export all instances' { Export-TargetResource } 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..0cb1e5851 100644 --- a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 @@ -1543,6 +1543,49 @@ try } } + Describe 'MSFT_xWebApplicaton/Export-TargetResource' { + $MockParameters = @{ + Website = 'MockSite' + Name = 'MockApp' + WebAppPool = 'MockPool' + PhysicalPath = 'C:\MockSite\MockApp' + } + + Mock -CommandName Get-WebConfiguration -MockWith { + return $GetWebConfigurationOutput + } + + 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 $MockWebApplicationOutput + } + + 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..47922c7a4 100644 --- a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 @@ -490,6 +490,24 @@ try } } #endregion Non-Exported Function Unit Tests + + Describe 'MSFT_xWebConfigKeyValue/Export-TargetResource' { + Mock -CommandName Get-ItemValue -ModuleName $script:DSCResourceName -MockWith { + return $null + } + + $parameters = @{ + WebsitePath = 'C:\SomePath\web.config' + ConfigSection = 'AppSettings' + Key = 'Key' + } + 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_xWebVirtualDirectory.Tests.ps1 b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 index 23c775a53..8a9b8ca5c 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,26 @@ try } } } + Describe 'MSFT_xWebVirtualDirectory/Export-TargetResource' { + $MockSite = @{ + Website = 'contoso.com' + WebApplication = 'contosoapp' + Name = 'shared_directory' + PhysicalPath = 'C:\inetpub\wwwroot\shared' + Ensure = 'Present' + } + $virtualDir = @{ + Name = 'shared_directory' + PhysicalPath = 'C:\inetpub\wwwroot\shared' + Count = 1 + } + Context 'Export Configuration' { + Mock -CommandName Get-WebVirtualDirectory -MockWith { return $virtualDir } + It 'Should Not export any 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 } From df002206ab2126d6d8e60cb3bfaef6e7d1c59d85 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 09:48:27 -0400 Subject: [PATCH 19/36] Fixed Tests and re-triggered bad integration test run --- Tests/Unit/MSFT_xWebApplication.Tests.ps1 | 15 ++++++++++++++- Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 | 13 +++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 index 0cb1e5851..7f2c9063a 100644 --- a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 @@ -1552,7 +1552,20 @@ try } Mock -CommandName Get-WebConfiguration -MockWith { - return $GetWebConfigurationOutput + 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 Test-AuthenticationEnabled { return $true } ` diff --git a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 index 8a9b8ca5c..0c80b0b44 100644 --- a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 @@ -235,21 +235,14 @@ try } } Describe 'MSFT_xWebVirtualDirectory/Export-TargetResource' { - $MockSite = @{ - Website = 'contoso.com' - WebApplication = 'contosoapp' - Name = 'shared_directory' - PhysicalPath = 'C:\inetpub\wwwroot\shared' - Ensure = 'Present' - } $virtualDir = @{ - Name = 'shared_directory' - PhysicalPath = 'C:\inetpub\wwwroot\shared' + Name = 'shared_directory' + Path = 'C:\inetpub\wwwroot\shared' Count = 1 } Context 'Export Configuration' { Mock -CommandName Get-WebVirtualDirectory -MockWith { return $virtualDir } - It 'Should Not export any resource instances' { + It 'Should Export all resource instances' { Export-TargetResource } } From 00b4f8bf6176218215fc0a4536883740a0362812 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 10:08:17 -0400 Subject: [PATCH 20/36] Nik --- Tests/Unit/MSFT_xWebApplication.Tests.ps1 | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 index 7f2c9063a..a89d4ce72 100644 --- a/Tests/Unit/MSFT_xWebApplication.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebApplication.Tests.ps1 @@ -1551,7 +1551,15 @@ try PhysicalPath = 'C:\MockSite\MockApp' } - Mock -CommandName Get-WebConfiguration -MockWith { + 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' @@ -1566,18 +1574,6 @@ try EnabledProtocols = 'http' Count = '1' } - } - - 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 $MockWebApplicationOutput } Mock -CommandName Get-WebConfiguration -MockWith { From f944f081b1aa0f9b7179810c5edf1efc5975b69b Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 10:25:49 -0400 Subject: [PATCH 21/36] Fixed broken VirtualDirectory test --- .../MSFT_xWebVirtualDirectory.psm1 | 6 +++--- Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index 8daa35eb5..a488e4cdf 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -233,12 +233,12 @@ function Export-TargetResource $j =1 foreach($webvirtualdirectory in $webVirtualDirectories) { - Write-Information " [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.path)" - Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.path)" + Write-Information " [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)" + Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)" $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot <# Setting Primary Keys #> - $params.Name = $webvirtualdirectory.Path + $params.Name = $webvirtualdirectory.PhysicalPath $params.WebApplication = "" $params.Website = $website.Name <# Setting Required Keys #> diff --git a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 index 0c80b0b44..6d8ecc840 100644 --- a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 @@ -236,9 +236,9 @@ try } Describe 'MSFT_xWebVirtualDirectory/Export-TargetResource' { $virtualDir = @{ - Name = 'shared_directory' - Path = 'C:\inetpub\wwwroot\shared' - Count = 1 + Name = 'shared_directory' + PhysicalPath = 'C:\inetpub\wwwroot\shared' + Count = 1 } Context 'Export Configuration' { Mock -CommandName Get-WebVirtualDirectory -MockWith { return $virtualDir } From e04986e33a4eb3f785a1f3e9fce787b5520f43b5 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 10:46:31 -0400 Subject: [PATCH 22/36] Fixes to empty Physical Path in tests --- .../MSFT_xWebVirtualDirectory.psm1 | 3 ++- Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index a488e4cdf..0c516ee49 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -238,7 +238,8 @@ function Export-TargetResource $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot <# Setting Primary Keys #> - $params.Name = $webvirtualdirectory.PhysicalPath + $params.Name = $webvirtualdirectory.Name + $params.PhysicalPath = $webvirtualdirectory.PhysicalPath $params.WebApplication = "" $params.Website = $website.Name <# Setting Required Keys #> diff --git a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 index 6d8ecc840..f1c2f2756 100644 --- a/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebVirtualDirectory.Tests.ps1 @@ -235,13 +235,15 @@ try } } Describe 'MSFT_xWebVirtualDirectory/Export-TargetResource' { - $virtualDir = @{ - Name = 'shared_directory' - PhysicalPath = 'C:\inetpub\wwwroot\shared' - Count = 1 - } + Context 'Export Configuration' { - Mock -CommandName Get-WebVirtualDirectory -MockWith { return $virtualDir } + Mock -CommandName Get-WebVirtualDirectory -MockWith { + return @{ + Name = 'shared_directory' + PhysicalPath = 'C:\inetpub\wwwroot\shared' + Count = 1 + } + } It 'Should Export all resource instances' { Export-TargetResource } From 5e3434c4a864f2981eab2ad33785f4b891830f71 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 11:37:47 -0400 Subject: [PATCH 23/36] Fixed Review and added coverage --- .../MSFT_WebApplicationHandler.psm1 | 14 +++--- .../MSFT_xIIsHandler/MSFT_xIisHandler.psm1 | 12 ++--- .../MSFT_xIisFeatureDelegation.psm1 | 14 +++--- .../MSFT_xIisLogging/MSFT_xIisLogging.psm1 | 10 ++-- .../MSFT_xIisMimeTypeMapping.psm1 | 14 +++--- .../MSFT_xIisModule/MSFT_xIisModule.psm1 | 24 ++++----- .../MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 | 10 ++-- .../MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 | 18 +++---- .../MSFT_xWebAppPoolDefaults.psm1 | 12 ++--- .../MSFT_xWebApplication.psm1 | 42 ++++++++-------- .../MSFT_xWebConfigKeyValue.psm1 | 14 +++--- .../MSFT_xWebConfigProperty.psm1 | 6 +-- .../MSFT_xWebConfigPropertyCollection.psm1 | 6 +-- .../MSFT_xWebSiteDefaults.psm1 | 12 ++--- .../MSFT_xWebVirtualDirectory.psm1 | 24 ++++----- DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 50 +++++++++---------- .../Unit/MSFT_WebApplicationHandler.tests.ps1 | 2 +- .../Unit/MSFT_xIISFeatureDelegation.Tests.ps1 | 3 +- Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 | 11 ++-- 19 files changed, 147 insertions(+), 151 deletions(-) diff --git a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 index fcd7671ba..84a378a7a 100644 --- a/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 +++ b/DSCResources/MSFT_WebApplicationHandler/MSFT_WebApplicationHandler.psm1 @@ -386,9 +386,9 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting WebApplicationHandler..." - $handlers = Get-WebConfigurationProperty -Filter "system.webServer/handlers/Add" -Name '.' + $InformationPreference = 'Continue' + Write-Information 'Extracting WebApplicationHandler...' + $handlers = Get-WebConfigurationProperty -Filter 'system.webServer/handlers/Add' -Name '.' $sb = [System.Text.StringBuilder]::new() $i = 1 @@ -397,16 +397,16 @@ function Export-TargetResource Write-Information " [$i/$($handlers.Count)] $($handler.name)" $params = @{ Name = $handler.name - Path = "IIS://" + Path = 'IIS://' Location = $handler.location } $results = Get-TargetResource @params - [void]$sb.AppendLine(" WebApplicationHandler " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' WebApplicationHandler ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } return $sb.ToString() diff --git a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 index 417b03069..faaec3d4c 100644 --- a/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 +++ b/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1 @@ -921,8 +921,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xIISHandler..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISHandler...' $handlers = Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' ` -Filter 'system.webServer/handlers/*' ` @@ -934,16 +934,16 @@ function Export-TargetResource { $params = @{ Name = $handler.name - Ensure = "Present" + Ensure = 'Present' } $results = Get-TargetResource @params Write-Information " [$i/$($handlers.Count)] $($handler.name)" - [void]$sb.AppendLine(" xIISHandler " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISHandler ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } return $sb.ToString() diff --git a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 index 047dcc9a9..e54e2a1fc 100644 --- a/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 +++ b/DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1 @@ -160,9 +160,9 @@ function Export-TargetResource param() $InformationPreference = 'Continue' - Write-Information "Extracting xIISFeatureDelegation..." + Write-Information 'Extracting xIISFeatureDelegation...' - $configSections = Get-WebConfiguration -Filter "system.webServer/*" -Metadata -Recurse + $configSections = Get-WebConfiguration -Filter 'system.webServer/*' -Metadata -Recurse $sb = [System.Text.StringBuilder]::new() $i = 1 foreach ($section in $configSections) @@ -172,18 +172,18 @@ function Export-TargetResource Write-Information " [$i/$($configSections.Count)] $($section.SectionPath.Remove(0,1))" $params = @{ Filter = $section.SectionPath.Remove(0,1) - Path = "MACHINE/WEBROOT/APPHOST" - OverrideMode = "Deny" + Path = 'MACHINE/WEBROOT/APPHOST' + OverrideMode = 'Deny' } try { $results = Get-TargetResource @params - [void]$sb.AppendLine(" xIISFeatureDelegation " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISFeatureDelegation ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') } catch { diff --git a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 index bd57c1605..7342d2f0d 100644 --- a/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 +++ b/DSCResources/MSFT_xIisLogging/MSFT_xIisLogging.psm1 @@ -404,8 +404,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xIISLogging..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISLogging...' $LogSettings = Get-WebConfiguration -Filter '/system.applicationHost/sites/siteDefaults/Logfile' @@ -415,11 +415,11 @@ function Export-TargetResource $sb = [System.Text.StringBuilder]::new() $results = Get-TargetResource @params $results.LogFlags = $results.LogFlags.Split(',') - [void]$sb.AppendLine(" xIISLogging " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISLogging ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') return $sb.ToString() diff --git a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 index 146fc06f8..d3dba3f1c 100644 --- a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 +++ b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 @@ -234,10 +234,10 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xIISMimeTypeMapping..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISMimeTypeMapping...' - $MimeMap = Get-WebConfiguration -Filter "system.webServer/staticContent/mimeMap" + $MimeMap = Get-WebConfiguration -Filter 'system.webServer/staticContent/mimeMap' $i = 1 $sb = [System.Text.StringBuilder]::new() @@ -248,14 +248,14 @@ function Export-TargetResource ConfigurationPath = $mimeType.PSPath Extension = $mimeType.fileExtension MimeType = $mimeType.mimeType - Ensure = "Present" + Ensure = 'Present' } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xIISMimeTypeMapping " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISMimeTypeMapping ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $module [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } return $sb.ToString() diff --git a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 index fe05c4d70..3e45b5000 100644 --- a/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 +++ b/DSCResources/MSFT_xIisModule/MSFT_xIisModule.psm1 @@ -150,12 +150,12 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xIISModule..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xIISModule...' $Modules = Get-WebManagedModule - Write-Information " Modules Defined at Root Level:" + Write-Information ' Modules Defined at Root Level:' $sb = [System.Text.StringBuilder]::new() $i = 1 foreach ($Module in $Modules) @@ -163,16 +163,16 @@ function Export-TargetResource Write-Information " [$i/$($Modules.Count)] $($Module.Name)" $params = @{ Name = $Module.Name - SiteName = "*" + SiteName = '*' Code = $Module.Type - Ensure = "Present" + Ensure = 'Present' } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xIISModule " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISModule ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $dscmodule [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } @@ -193,14 +193,14 @@ function Export-TargetResource Name = $Module.Name SiteName = $site.Name Code = $Module.Type - Ensure = "Present" + Ensure = 'Present' } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xIISModule " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xIISModule ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $dscmodule [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } } diff --git a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 index 44a178e74..51ad5f384 100644 --- a/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 +++ b/DSCResources/MSFT_xSSLSettings/MSFT_xSSLSettings.psm1 @@ -180,8 +180,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xSSLSettings..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xSSLSettings...' $sb = [System.Text.StringBuilder]::new() @@ -195,11 +195,11 @@ function Export-TargetResource } $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(" {") + [void]$sb.AppendLine(' xSSLSettings ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $i++ } diff --git a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 index fa488e026..30d97a2f7 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -983,8 +983,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebAppPool..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebAppPool...' $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot @@ -996,28 +996,28 @@ function Export-TargetResource Write-Information " [$i/$($appPools.Length)] $($appPool.Name)" <# Setting Primary Keys #> $params.Name = $appPool.Name - Write-Verbose "Key parameters as follows" + Write-Verbose 'Key parameters as follows' $params | ConvertTo-Json | Write-Verbose $results = Get-TargetResource @params - if($appPool.ProcessModel -eq "SpecificUser") + if($appPool.ProcessModel -eq 'SpecificUser') { $results.Credential = "`$Creds" + $appPool.ProcessModel.username } else { - $results.Remove("Credential") + $results.Remove('Credential') } - Write-Verbose "All Parameters with values" + Write-Verbose 'All Parameters with values' $results | ConvertTo-Json | Write-Verbose - [void]$sb.AppendLine(" xWebAppPool " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebAppPool ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') } return $sb.ToString() } diff --git a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 index 1d8434c73..9e75a10a9 100644 --- a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 +++ b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 @@ -127,19 +127,19 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebAppPoolDefaults..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebAppPoolDefaults...' $sb = [System.Text.StringBuilder]::new() $params = @{ - ApplyTo = "Machine" + ApplyTo = 'Machine' } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xWebAppPoolDefaults " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebAppPoolDefaults ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') return $sb.ToString() } diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index 90a10963f..64746d0cd 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -510,13 +510,13 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebApplication..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebApplication...' $webSites = Get-WebSite $sb = [System.Text.StringBuilder]::new() $i = 1 - foreach($website in $webSites) + foreach ($website in $webSites) { Write-Information " [$i/$($webSites.Count)] Site {$($webSite.Name)}" $webApplications = Get-WebApplication -Site $website.name @@ -524,7 +524,7 @@ function Export-TargetResource if($webApplications) { $j = 1 - foreach($webapplication in $webApplications) + foreach ($webapplication in $webApplications) { $authSb = [System.Text.StringBuilder]::new() Write-Information "[$j/$($webApplications.Count)] $($webApplication.Path)" @@ -534,50 +534,50 @@ function Export-TargetResource Name = $webapplication.Path Website = $website.Name WebAppPool = $webapplication.ApplicationPool - PhysicalPath = "*" + PhysicalPath = '*' } <# Setting Required Keys #> #$params.WebAppPool = $webapplication.applicationpool #$params.PhysicalPath = $webapplication.PhysicalPath - Write-Verbose "Key parameters as follows" + Write-Verbose 'Key parameters as follows' $params | ConvertTo-Json | Write-Verbose $results = Get-TargetResource @params - Write-Verbose "All Parameters as follows" + Write-Verbose 'All Parameters as follows' $results | ConvertTo-Json | Write-Verbose - [void]$authSb.AppendLine( "MSFT_xWebApplicationAuthenticationInformation") - [void]$authSb.AppendLine(" {") + [void]$authSb.AppendLine( 'MSFT_xWebApplicationAuthenticationInformation') + [void]$authSb.AppendLine(' {') - $AuthenticationTypes = @("BasicAuthentication","AnonymousAuthentication","DigestAuthentication","WindowsAuthentication") + $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)" + $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)" + -PSPath 'IIS:\Sites\$location' + Write-Verbose '$authenticationtype : $($prop.Value)' [void]$authSb.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } - [void]$authSb.AppendLine(" }") + [void]$authSb.AppendLine(' }') $results.AuthenticationInfo = $authSb.ToString() - $results.SslFlags = $results.SslFlags.Split(",") - $results.EnabledProtocols = $results.EnabledProtocols.Split(",") + $results.SslFlags = $results.SslFlags.Split(',') + $results.EnabledProtocols = $results.EnabledProtocols.Split(',') - Write-Verbose "All Parameters with values" + Write-Verbose 'All Parameters with values' $results | ConvertTo-Json | Write-Verbose - [void]$sb.AppendLine(" xWebApplication " + (New-GUID).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebApplication ' + (New-GUID).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot - $dscBlock = Convert-DSCStringParamToVariable -DSCBlock $dscBlock -ParameterName "AuthenticationInfo" + $dscBlock = Convert-DSCStringParamToVariable -DSCBlock $dscBlock -ParameterName 'AuthenticationInfo' [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $j++ } } diff --git a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 index fe73759c1..5f78f7881 100644 --- a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 +++ b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 @@ -248,8 +248,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebConfigKeyValue..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebConfigKeyValue...' $webSites = Get-Website @@ -258,7 +258,7 @@ function Export-TargetResource 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)" + $keys = Get-WebConfiguration -Filter '/appSettings/*' -PSPath "IIS:/Sites/$($site.Name)" $j = 1 foreach ($key in $keys) @@ -266,16 +266,16 @@ function Export-TargetResource Write-Information " [$j/$($keys.Count)] $($key.Key)" $params = @{ WebsitePath = "IIS:/Sites/$($site.Name)" - ConfigSection = "AppSettings" + ConfigSection = 'AppSettings' Key = $key.Key } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xWebConfigKeyValue " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebConfigKeyValue ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $j++ } $i++ diff --git a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 index a51f230f5..5f9ba8542 100644 --- a/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 +++ b/DSCResources/MSFT_xWebConfigProperty/MSFT_xWebConfigProperty.psm1 @@ -258,10 +258,10 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebConfigProperty is not supported by ReverseDSC." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebConfigProperty is not supported by ReverseDSC.' - return "" + return '' } # region Helper Functions diff --git a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 index 6f33e4214..b438e1d00 100644 --- a/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 +++ b/DSCResources/MSFT_xWebConfigPropertyCollection/MSFT_xWebConfigPropertyCollection.psm1 @@ -432,9 +432,9 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebConfigPropertyCollection is not supported by ReverseDSC" - return "" + $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 e574913af..e39938421 100644 --- a/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 +++ b/DSCResources/MSFT_xWebSiteDefaults/MSFT_xWebSiteDefaults.psm1 @@ -175,20 +175,20 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebSiteDefaults..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebSiteDefaults...' $sb = [System.Text.StringBuilder]::new() $params = @{ - ApplyTo = "Machine" + ApplyTo = 'Machine' } $results = Get-TargetResource @params - [void]$sb.AppendLine(" xWebSiteDefaults " + (New-GUID).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebSiteDefaults ' + (New-GUID).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') return $sb.ToString() } diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index 0c516ee49..c4514cfff 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -216,16 +216,16 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebVirtualDirectory..." + $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)" + 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) @@ -233,30 +233,30 @@ function Export-TargetResource $j =1 foreach($webvirtualdirectory in $webVirtualDirectories) { - Write-Information " [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)" - Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)" + Write-Information ' [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)' + Write-Verbose 'WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)' $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot <# Setting Primary Keys #> $params.Name = $webvirtualdirectory.Name $params.PhysicalPath = $webvirtualdirectory.PhysicalPath - $params.WebApplication = "" + $params.WebApplication = '' $params.Website = $website.Name <# Setting Required Keys #> #$params.PhysicalPath = $webapplication.PhysicalPath - Write-Verbose "Key parameters as follows" + Write-Verbose 'Key parameters as follows' $params | ConvertTo-Json | Write-Verbose $results = Get-TargetResource @params - Write-Verbose "All Parameters with values" + Write-Verbose 'All Parameters with values' $results | ConvertTo-Json | Write-Verbose - [void]$sb.AppendLine(" xWebVirtualDirectory " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebVirtualDirectory ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock += Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') $j++ } } diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 7ad5b6237..ec21d86ca 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1125,8 +1125,8 @@ function Export-TargetResource [OutputType([System.String])] param() - $InformationPreference = "Continue" - Write-Information "Extracting xWebSite..." + $InformationPreference = 'Continue' + Write-Information 'Extracting xWebSite...' $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot @@ -1138,11 +1138,11 @@ function Export-TargetResource Write-Information " [$i/$($webSites.Count)] $($website.Name)" <# Setting Primary Keys #> $params.Name = $website.Name - Write-Verbose "Key parameters as follows" + Write-Verbose 'Key parameters as follows' $params | ConvertTo-Json | Write-Verbose $results = Get-TargetResource @params - Write-Verbose "All Parameters as follows" + Write-Verbose 'All Parameters as follows' $results | ConvertTo-Json | Write-Verbose $results.BindingInfo = @(); @@ -1150,23 +1150,23 @@ function Export-TargetResource foreach($binding in $website.Bindings.Collection) { $bindingContent = [System.Text.StringBuilder]::new() - [void]$bindingContent.AppendLine("MSFT_xWebBindingInformation") - [void]$bindingContent.AppendLine(" {") + [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") + if ($binding.protocol -match '^http') { - $bindingInfo = $binding.bindingInformation.split(":") + $bindingInfo = $binding.bindingInformation.split(':') $ipAddress = $bindingInfo[0] $port = $bindingInfo[1] $hostName = $bindingInfo[2] [void]$bindingContent.AppendLine(" IPAddress = `"$ipAddress`"") [void]$bindingContent.AppendLine(" Port = $port") [void]$bindingContent.AppendLine(" Hostname = `"$hostName`"") - if ($binding.CertificateStoreName -eq "My" -or $binding.CertificateStoreName -eq "WebHosting") + if ($binding.CertificateStoreName -eq 'My' -or $binding.CertificateStoreName -eq 'WebHosting') { - if ($null -ne $binding.CertificateHash -and "" -ne $binding.CertificateHash) + if ($null -ne $binding.CertificateHash -and '' -ne $binding.CertificateHash) { [void]$bindingContent.AppendLine(" CertificateThumbprint = `"$($binding.CertificateHash)`"") } @@ -1178,7 +1178,7 @@ function Export-TargetResource [void]$bindingContent.AppendLine(" BindingInformation = `"$($binding.bindingInformation)`"") } - [void]$bindingContent.AppendLine(" }") + [void]$bindingContent.AppendLine(' }') $results.BindingInfo += $bindingContent.ToString() } @@ -1189,20 +1189,20 @@ function Export-TargetResource $logSB = [System.Text.StringBuilder]::new() foreach ($customfield in $webSite.logfile.customFields.Collection) { - [void]$logSB.AppendLine("MSFT_LogCustomFieldInformation") - [void]$logSB.AppendLine("{") + [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("}") + [void]$logSB.AppendLine('}') } $results.LogCustomFields = $logSB.ToString() $authSB = [System.Text.StringBuilder]::new() - [void]$authSB.AppendLine(" MSFT_xWebAuthenticationInformation") - [void]$authSB.AppendLine(" {") + [void]$authSB.AppendLine(' MSFT_xWebAuthenticationInformation') + [void]$authSB.AppendLine(' {') - $AuthenticationTypes = @("BasicAuthentication","AnonymousAuthentication","DigestAuthentication","WindowsAuthentication") + $AuthenticationTypes = @('BasicAuthentication','AnonymousAuthentication','DigestAuthentication','WindowsAuthentication') foreach ($authenticationtype in $AuthenticationTypes) { @@ -1213,22 +1213,22 @@ function Export-TargetResource -Filter /system.WebServer/security/authentication/$authenticationtype ` -Name enabled ` -Location $location - Write-Verbose "$authenticationtype : $($prop.Value)" + Write-Verbose '$authenticationtype : $($prop.Value)' [void]$authSB.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } - [void]$authSB.Append(" }") + [void]$authSB.Append(' }') $results.AuthenticationInfo = $authSB.ToString() - $results.LogFlags = $results.LogFlags.Split(",") + $results.LogFlags = $results.LogFlags.Split(',') - Write-Verbose "All Parameters with values" + Write-Verbose 'All Parameters with values' $results | ConvertTo-Json | Write-Verbose - [void]$sb.AppendLine(" xWebSite " + (New-Guid).ToString()) - [void]$sb.AppendLine(" {") + [void]$sb.AppendLine(' xWebSite ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(" }") + [void]$sb.AppendLine(' }') } return $sb.ToString() @@ -1631,7 +1631,7 @@ function ConvertTo-WebBinding { if ($binding.CertificateSubject.substring(0,3) -ne 'CN=') { - $binding.CertificateSubject = "CN=$($Binding.CertificateSubject)" + $binding.CertificateSubject = 'CN=$($Binding.CertificateSubject)' } $FindCertificateSplat = @{ Subject = $Binding.CertificateSubject diff --git a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 index 700b65434..a8e7425ed 100644 --- a/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 +++ b/Tests/Unit/MSFT_WebApplicationHandler.tests.ps1 @@ -374,7 +374,7 @@ try Context 'Export Configuration' { - Mock Get-WebConfigurationProperty + 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 4920073de..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 = @{ @@ -172,7 +173,7 @@ try Context 'Export Configuration' { - Mock -CommandName Get-WebConfiguration -MockWith { return $mockDenyOverrideMode } + Mock -CommandName Get-WebConfiguration -MockWith { return $mockAllowOverrideMode } It 'Should Export all instances' { Export-TargetResource diff --git a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 index 47922c7a4..37bba4e3c 100644 --- a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 @@ -492,15 +492,10 @@ try #endregion Non-Exported Function Unit Tests Describe 'MSFT_xWebConfigKeyValue/Export-TargetResource' { - Mock -CommandName Get-ItemValue -ModuleName $script:DSCResourceName -MockWith { - return $null - } + Mock -CommandName Get-ItemValue -ModuleName $script:DSCResourceName ` + -ParameterFilter { $isAttribute -eq $false } ` + -MockWith { return 'Value' } - $parameters = @{ - WebsitePath = 'C:\SomePath\web.config' - ConfigSection = 'AppSettings' - Key = 'Key' - } Context 'Export Configuration' { It 'Should Export all instances' { From dad96e296057aca3d6eb9697dad70859069bf96e Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 12:05:55 -0400 Subject: [PATCH 24/36] Update MSFT_xWebsite.psm1 --- DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index ec21d86ca..62189a1e8 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1631,7 +1631,7 @@ function ConvertTo-WebBinding { if ($binding.CertificateSubject.substring(0,3) -ne 'CN=') { - $binding.CertificateSubject = 'CN=$($Binding.CertificateSubject)' + $binding.CertificateSubject = "CN=$($Binding.CertificateSubject)" } $FindCertificateSplat = @{ Subject = $Binding.CertificateSubject From 5ad9e5637bd71d2061c1a98b73b144ca4eec31c2 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 14:45:14 -0400 Subject: [PATCH 25/36] Added missing tests for xWebSiteDefaults --- Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 diff --git a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 new file mode 100644 index 000000000..78333dd01 --- /dev/null +++ b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 @@ -0,0 +1,90 @@ + +$script:DSCModuleName = 'xWebSiteDefaults' +$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 { + $path = $Filter.Replace('system.applicationHost/sites/siteDefaults/', '') + + if ([System.String]::IsNullOrEmpty($path)) { + return $MockWebSiteDefaults[$Name] + } else { + $path = $path.Replace('/', '') + return $MockWebSiteDefaults[$path][$Name] + } + } + + Context 'Returns Defaults' { + $params = @{ + ApplyTo = "Machine" + LogFormat = "W3C" + Ensure = "Present" + } + 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 +} From 76781d420b9680ee2c0bfbc103804fe72f36ed10 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 15:00:20 -0400 Subject: [PATCH 26/36] Update MSFT_xWebSiteDefaults.Tests.ps1 --- Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 index 78333dd01..7be8773af 100644 --- a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 @@ -79,7 +79,7 @@ try Export-TargetResource } } - + } } } finally From bc49d07a9e756ae7b65ff93c8c2ed8b08e3b49f4 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 15:14:37 -0400 Subject: [PATCH 27/36] Update MSFT_xWebSiteDefaults.Tests.ps1 --- Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 index 7be8773af..3b9e4f6e6 100644 --- a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xWebSiteDefaults' +$script:DSCModuleName = 'xWebAdministration' $script:DSCResourceName = 'MSFT_xWebSiteDefaults' #region HEADER From 19c559c93830505e2308df65dff5afe02e542c56 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 15:33:12 -0400 Subject: [PATCH 28/36] Update MSFT_xWebSiteDefaults.Tests.ps1 --- Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 index 3b9e4f6e6..345fa358b 100644 --- a/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebSiteDefaults.Tests.ps1 @@ -45,21 +45,13 @@ try } Mock Get-WebConfigurationProperty -MockWith { - $path = $Filter.Replace('system.applicationHost/sites/siteDefaults/', '') - - if ([System.String]::IsNullOrEmpty($path)) { - return $MockWebSiteDefaults[$Name] - } else { - $path = $path.Replace('/', '') - return $MockWebSiteDefaults[$path][$Name] - } + return $MockWebSiteDefaults[$Name] } Context 'Returns Defaults' { $params = @{ ApplyTo = "Machine" LogFormat = "W3C" - Ensure = "Present" } It 'Should return true from the Test function' { $result = Test-TargetResource @params From eea8ce08f73bb6d96405bb159cf1faea758e4c66 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 15:50:21 -0400 Subject: [PATCH 29/36] Update MSFT_xIISModule.Tests.ps1 --- Tests/Unit/MSFT_xIISModule.Tests.ps1 | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 index b5efaabfc..d2ed874e3 100644 --- a/Tests/Unit/MSFT_xIISModule.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -75,6 +75,39 @@ try Test-TargetResource @TestParams | Should be $false } } + + Context 'Resource exists. We need to add it' { + + $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 update the instance from the Set Method' { + Set-TargetResource @TestParams + } + + It 'Should return true from the Test method' { + Test-TargetResource @TestParams | Should be $true + } + } } Describe 'MSFT_xIISModule/Export-TargetResource' { From 9979b7841f54b5404426f7213e56c6a3e8989855 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 16:11:03 -0400 Subject: [PATCH 30/36] Update MSFT_xIISModule.Tests.ps1 --- Tests/Unit/MSFT_xIISModule.Tests.ps1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Tests/Unit/MSFT_xIISModule.Tests.ps1 b/Tests/Unit/MSFT_xIISModule.Tests.ps1 index d2ed874e3..0ba8b18e6 100644 --- a/Tests/Unit/MSFT_xIISModule.Tests.ps1 +++ b/Tests/Unit/MSFT_xIISModule.Tests.ps1 @@ -76,7 +76,7 @@ try } } - Context 'Resource exists. We need to add it' { + Context 'Resource exists.' { $TestParams = @{ Name = "Test Module" @@ -100,10 +100,6 @@ try (Get-TargetResource @TestParams).Ensure | Should Be 'Present' } - It 'Should update the instance from the Set Method' { - Set-TargetResource @TestParams - } - It 'Should return true from the Test method' { Test-TargetResource @TestParams | Should be $true } From 86ea1cd413c30c4b39d4d7aa100cfba2b2a47371 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 17:12:26 -0400 Subject: [PATCH 31/36] Update MSFT_xWebConfigKeyValue.Tests.ps1 --- Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 index 37bba4e3c..5e1510ad6 100644 --- a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 @@ -496,6 +496,13 @@ try -ParameterFilter { $isAttribute -eq $false } ` -MockWith { return 'Value' } + Mock -CommandName Get-WebConfiguration -MockWith { + return @{ + Name = "Key1" + Value = "Value1" + } + } + Context 'Export Configuration' { It 'Should Export all instances' { From a4610b47ed48d5b25a409ee29b23d59203b48ff2 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 17:21:35 -0400 Subject: [PATCH 32/36] Fixed quotes --- DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index 64746d0cd..a3e23706a 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -559,7 +559,7 @@ function Export-TargetResource $prop = Get-WebConfigurationProperty ` -Filter /system.WebServer/security/authentication/$authenticationtype ` -Name enabled ` - -PSPath 'IIS:\Sites\$location' + -PSPath "IIS:\Sites\$location" Write-Verbose '$authenticationtype : $($prop.Value)' [void]$authSb.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } @@ -717,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 } From bb21d69c69cf5fae6a7a70ce3c50e9b1e643373a Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 16 Sep 2019 17:37:24 -0400 Subject: [PATCH 33/36] Update MSFT_xWebConfigKeyValue.Tests.ps1 --- Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 index 5e1510ad6..cb938fb69 100644 --- a/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebConfigKeyValue.Tests.ps1 @@ -498,7 +498,7 @@ try Mock -CommandName Get-WebConfiguration -MockWith { return @{ - Name = "Key1" + Key = "Key1" Value = "Value1" } } From 5dc1010071845abd4ab3a49d281db8894f2e34d2 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 21 Oct 2019 14:27:25 -0400 Subject: [PATCH 34/36] Fixes --- .../MSFT_xWebApplication/MSFT_xWebApplication.psm1 | 8 ++++---- xWebAdministration.psd1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index a3e23706a..34724f674 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -555,12 +555,12 @@ function Export-TargetResource { Remove-Variable -Name location -ErrorAction SilentlyContinue Remove-Variable -Name prop -ErrorAction SilentlyContinue - $location = "$($website.Name)' + '$($webapplication.Path)" + $location = $website.Name + $webapplication.Path $prop = Get-WebConfigurationProperty ` - -Filter /system.WebServer/security/authentication/$authenticationtype ` - -Name enabled ` + -Filter "/system.WebServer/security/authentication/$authenticationtype" ` + -Name 'enabled' ` -PSPath "IIS:\Sites\$location" - Write-Verbose '$authenticationtype : $($prop.Value)' + Write-Verbose "$authenticationtype : $($prop.Value)" [void]$authSb.AppendLine(" $($authenticationtype.Replace('Authentication','')) = `$" + $prop.Value) } [void]$authSb.AppendLine(' }') diff --git a/xWebAdministration.psd1 b/xWebAdministration.psd1 index 5afda7854..75546a69a 100644 --- a/xWebAdministration.psd1 +++ b/xWebAdministration.psd1 @@ -21,7 +21,7 @@ Description = 'Module with DSC Resources for Web Administration' PowerShellVersion = '4.0' # Adds dependency to ReverseDSC -RequiredModules = @(@{ModuleName = "ReverseDSC"; RequiredVersion = "1.9.4.5"; }) +RequiredModules = @(@{ModuleName = "ReverseDSC"; RequiredVersion = "1.9.4.6"; }) # Minimum version of the common language runtime (CLR) required by this module CLRVersion = '4.0' From 5a7494e40b5e4bd93237692931c5aaed7f730bbc Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 21 Oct 2019 19:10:54 -0400 Subject: [PATCH 35/36] Fixes --- .../MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 | 1 - .../MSFT_xWebAppPoolDefaults.psm1 | 1 + .../MSFT_xWebConfigKeyValue.psm1 | 2 ++ .../MSFT_xWebVirtualDirectory.psm1 | 25 +++++++++++------- DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 26 ++++++++++++++----- Modules/ReverseDSCCollector.psm1 | 11 ++++++++ 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 index 30d97a2f7..ad5b4bf64 100644 --- a/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 +++ b/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1 @@ -1012,7 +1012,6 @@ function Export-TargetResource 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 diff --git a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 index 9e75a10a9..34abdd7c9 100644 --- a/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 +++ b/DSCResources/MSFT_xWebAppPoolDefaults/MSFT_xWebAppPoolDefaults.psm1 @@ -134,6 +134,7 @@ function Export-TargetResource ApplyTo = 'Machine' } $results = Get-TargetResource @params + $results.Add('ApplyTo', 'Machine') [void]$sb.AppendLine(' xWebAppPoolDefaults ' + (New-Guid).ToString()) [void]$sb.AppendLine(' {') diff --git a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 index 5f78f7881..975b40e7b 100644 --- a/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 +++ b/DSCResources/MSFT_xWebConfigKeyValue/MSFT_xWebConfigKeyValue.psm1 @@ -270,6 +270,8 @@ function Export-TargetResource 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(' {') diff --git a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 index c4514cfff..40abb6bd2 100644 --- a/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 +++ b/DSCResources/MSFT_xWebVirtualDirectory/MSFT_xWebVirtualDirectory.psm1 @@ -224,8 +224,8 @@ function Export-TargetResource $i = 1 foreach($website in $webSites) { - Write-Information ' [$i/$($webSites.Count)] Getting Virtual Directories from WebSite {$($website.Name)}' - Write-Verbose 'WebSite: $($website.name)' + 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) @@ -233,12 +233,19 @@ function Export-TargetResource $j =1 foreach($webvirtualdirectory in $webVirtualDirectories) { - Write-Information ' [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)' - Write-Verbose 'WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)' + Write-Information " [$j/$($webVirtualDirectories.Count)] $($webvirtualdirectory.PhysicalPath)" + Write-Verbose "WebSite/VirtualDirectory: $($website.name)$($webvirtualdirectory.PhysicalPath)" $params = Get-DSCFakeParameters -ModulePath $PSScriptRoot <# Setting Primary Keys #> - $params.Name = $webvirtualdirectory.Name + if ($null -ne $webvirtualdirectory.Name) + { + $params.Name = $webvirtualdirectory.Name + } + else + { + $params.Name = $webvirtualdirectory.Path + } $params.PhysicalPath = $webvirtualdirectory.PhysicalPath $params.WebApplication = '' $params.Website = $website.Name @@ -252,11 +259,11 @@ function Export-TargetResource 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.AppendLine(' xWebVirtualDirectory ' + (New-Guid).ToString()) + [void]$sb.AppendLine(' {') + $dscBlock = Get-DSCBlock -Params $results -ModulePath $PSScriptRoot [void]$sb.Append($dscBlock) - [void]$sb.AppendLine(' }') + [void]$sb.AppendLine(' }') $j++ } } diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 62189a1e8..8bfdae8ef 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -1152,7 +1152,7 @@ function Export-TargetResource $bindingContent = [System.Text.StringBuilder]::new() [void]$bindingContent.AppendLine('MSFT_xWebBindingInformation') [void]$bindingContent.AppendLine(' {') - [void]$bindingContent.AppendLine(" Protocol = `"$($binding.Protocol)`"") + [void]$bindingContent.AppendLine(" Protocol = '$($binding.Protocol)'") [void]$bindingContent.AppendLine(" SslFlags = $($binding.sslFlags)") if ($binding.protocol -match '^http') @@ -1161,21 +1161,24 @@ function Export-TargetResource $ipAddress = $bindingInfo[0] $port = $bindingInfo[1] $hostName = $bindingInfo[2] - [void]$bindingContent.AppendLine(" IPAddress = `"$ipAddress`"") + [void]$bindingContent.AppendLine(" IPAddress = '$ipAddress'") [void]$bindingContent.AppendLine(" Port = $port") - [void]$bindingContent.AppendLine(" Hostname = `"$hostName`"") + 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(" CertificateThumbprint = '$($binding.CertificateHash)'") } - [void]$bindingContent.AppendLine(" CertificateStoreName = `"$($binding.CertificateStoreName)`"") + [void]$bindingContent.AppendLine(" CertificateStoreName = '$($binding.CertificateStoreName)'") } } else { - [void]$bindingContent.AppendLine(" BindingInformation = `"$($binding.bindingInformation)`"") + [void]$bindingContent.AppendLine(" BindingInformation = '$($binding.bindingInformation)'") } [void]$bindingContent.AppendLine(' }') @@ -1221,12 +1224,23 @@ function Export-TargetResource $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(' }') } diff --git a/Modules/ReverseDSCCollector.psm1 b/Modules/ReverseDSCCollector.psm1 index 9dd957955..6d3315a4b 100644 --- a/Modules/ReverseDSCCollector.psm1 +++ b/Modules/ReverseDSCCollector.psm1 @@ -25,6 +25,17 @@ function Export-WebAdministrationConfiguration [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) { From 698aeadda3957ade839fe9423bd7d83418da5a71 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 21 Oct 2019 21:41:48 -0400 Subject: [PATCH 36/36] Fixes --- Modules/ReverseDSCCollector.psm1 | 7 ++++++- xWebAdministration.psd1 | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Modules/ReverseDSCCollector.psm1 b/Modules/ReverseDSCCollector.psm1 index 6d3315a4b..1c1d9a51b 100644 --- a/Modules/ReverseDSCCollector.psm1 +++ b/Modules/ReverseDSCCollector.psm1 @@ -2,6 +2,11 @@ function Export-WebAdministrationConfiguration { [CmdletBinding()] [OutputType([System.String])] + param( + [Parameter()] + [System.String] + $Path + ) $sb = [System.Text.StringBuilder]::new() [void]$sb.AppendLine("Configuration WebAdministrationConfiguration") @@ -33,7 +38,7 @@ function Export-WebAdministrationConfiguration [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 diff --git a/xWebAdministration.psd1 b/xWebAdministration.psd1 index 75546a69a..af3dc812c 100644 --- a/xWebAdministration.psd1 +++ b/xWebAdministration.psd1 @@ -21,7 +21,7 @@ Description = 'Module with DSC Resources for Web Administration' PowerShellVersion = '4.0' # Adds dependency to ReverseDSC -RequiredModules = @(@{ModuleName = "ReverseDSC"; RequiredVersion = "1.9.4.6"; }) +RequiredModules = @(@{ModuleName = "ReverseDSC"; RequiredVersion = "1.9.4.7"; }) # Minimum version of the common language runtime (CLR) required by this module CLRVersion = '4.0'