From 18e20b0378a62afb0d72f1ebe5cb0c4fdd661cf1 Mon Sep 17 00:00:00 2001 From: fbarriere Date: Thu, 8 Sep 2016 13:39:12 +0200 Subject: [PATCH] Support null value for ServiceAutoStartProvider property of xWebApplication. --- .../MSFT_xWebApplication.psm1 | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 index cb0522887..50a6ab6fc 100644 --- a/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 +++ b/DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1 @@ -17,7 +17,8 @@ data LocalizedData VerboseSetTargetPreload = Updating Preload for Web application "{0}". VerboseSetTargetAutostart = Updating AutoStart for Web application "{0}". VerboseSetTargetIISAutoStartProviders = Updating AutoStartProviders for IIS. - VerboseSetTargetWebApplicationAutoStartProviders = Updating AutoStartProviders for Web application "{0}". + VerboseSetTargetWebApplicationAutoStartProviders = Updating AutoStartProviders for Web application "{0}". + VerboseSetTargetWebApplicationClearAutoStartProviders = Removing AutoStartProviders for Web application "{0}". VerboseTestTargetFalseAbsent = Web application "{0}" is absent and should not absent. VerboseTestTargetFalsePresent = Web application $Name should be absent and is not absent. VerboseTestTargetFalsePhysicalPath = Physical path for web application "{0}" does not match desired state. @@ -229,22 +230,34 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('ServiceAutoStartProvider') -and ` $webApplication.serviceAutoStartProvider -ne $ServiceAutoStartProvider) { - if (-not (Confirm-UniqueServiceAutoStartProviders ` - -ServiceAutoStartProvider $ServiceAutoStartProvider ` - -ApplicationType $ApplicationType)) + if ($ServiceAutoStartProvider -eq $null) { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetIISAutoStartProviders) - Add-WebConfiguration ` - -filter /system.applicationHost/serviceAutoStartProviders ` - -Value @{name=$ServiceAutoStartProvider; type=$ApplicationType} ` - -ErrorAction Stop + Write-Verbose -Message ` + ($LocalizedData.VerboseSetTargetWebApplicationClearAutoStartProviders ` + -f $Name) + Clear-ItemProperty -Path "IIS:\Sites\$Website\$Name" ` + -Name serviceAutoStartProvider ` + -ErrorAction Stop + } + else + { + if (-not (Confirm-UniqueServiceAutoStartProviders ` + -ServiceAutoStartProvider $ServiceAutoStartProvider ` + -ApplicationType $ApplicationType)) + { + Write-Verbose -Message ($LocalizedData.VerboseSetTargetIISAutoStartProviders) + Add-WebConfiguration ` + -filter /system.applicationHost/serviceAutoStartProviders ` + -Value @{name=$ServiceAutoStartProvider; type=$ApplicationType} ` + -ErrorAction Stop + } + Write-Verbose -Message ` + ($LocalizedData.VerboseSetTargetWebApplicationAutoStartProviders -f $Name) + Set-ItemProperty -Path "IIS:\Sites\$Website\$Name" ` + -Name serviceAutoStartProvider ` + -Value $ServiceAutoStartProvider ` + -ErrorAction Stop } - Write-Verbose -Message ` - ($LocalizedData.VerboseSetTargetWebApplicationAutoStartProviders -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Website\$Name" ` - -Name serviceAutoStartProvider ` - -Value $ServiceAutoStartProvider ` - -ErrorAction Stop } }