From 7c86b2038b1ded66ab61ed966440ef4ceec68457 Mon Sep 17 00:00:00 2001 From: Krzysztof Morcinek Date: Fri, 20 Jul 2018 20:15:08 +0200 Subject: [PATCH] Remove duplication in MSFT_xWebsite.psm1 --- DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 | 382 ++++++------------ README.md | 1 + 2 files changed, 123 insertions(+), 260 deletions(-) diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 5329630bc..5f857fee9 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -371,144 +371,6 @@ function Set-TargetResource Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdatedState ` -f $Name, $State) } - - # Set Authentication; if not defined then pass in DefaultAuthenticationInfo - if ($PSBoundParameters.ContainsKey('AuthenticationInfo') -and ` - (-not (Test-AuthenticationInfo -Site $Name ` - -AuthenticationInfo $AuthenticationInfo))) - { - Set-AuthenticationInfo -Site $Name ` - -AuthenticationInfo $AuthenticationInfo ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetAuthenticationInfoUpdated ` - -f $Name) - } - - # Update Preload if required - if ($PSBoundParameters.ContainsKey('preloadEnabled') -and ` - ($website.applicationDefaults.preloadEnabled -ne $PreloadEnabled)) - { - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.preloadEnabled ` - -Value $PreloadEnabled ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsitePreloadUpdated ` - -f $Name) - } - - # Update AutoStart if required - if ($PSBoundParameters.ContainsKey('ServiceAutoStartEnabled') -and ` - ($website.applicationDefaults.ServiceAutoStartEnabled -ne $ServiceAutoStartEnabled)) - { - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.serviceAutoStartEnabled ` - -Value $ServiceAutoStartEnabled ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsiteAutoStartUpdated ` - -f $Name) - } - - # Update AutoStartProviders if required - if ($PSBoundParameters.ContainsKey('ServiceAutoStartProvider') -and ` - ($website.applicationDefaults.ServiceAutoStartProvider -ne ` - $ServiceAutoStartProvider)) - { - if (-not (Confirm-UniqueServiceAutoStartProviders ` - -ServiceAutoStartProvider $ServiceAutoStartProvider ` - -ApplicationType $ApplicationType)) - { - Add-WebConfiguration -filter /system.applicationHost/serviceAutoStartProviders ` - -Value @{ - name=$ServiceAutoStartProvider - type=$ApplicationType} ` - -ErrorAction Stop - Write-Verbose -Message ` - ($LocalizedData.VerboseSetTargetIISAutoStartProviderUpdated) - } - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.serviceAutoStartProvider ` - -Value $ServiceAutoStartProvider -ErrorAction Stop - Write-Verbose -Message ` - ($LocalizedData.VerboseSetTargetWebsiteAutoStartProviderUpdated ` - -f $Name) - } - - # Update LogFormat if Needed - if ($PSBoundParameters.ContainsKey('LogFormat') -and ` - ($LogFormat -ne $website.logfile.LogFormat)) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFormat ` - -f $Name) - - # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.LogFormat property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.LogFormat = $LogFormat - $site | Set-Item - } - - # Update LogFlags if required - if ($PSBoundParameters.ContainsKey('LogFlags') -and ` - (-not (Compare-LogFlags -Name $Name -LogFlags $LogFlags))) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFlags ` - -f $Name) - - # Set-ItemProperty has no effect with the LogFile.LogExtFileFlags property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.LogFormat = 'W3C' - $site.LogFile.LogExtFileFlags = $LogFlags -join ',' - $site | Set-Item - } - - # Update LogPath if required - if ($PSBoundParameters.ContainsKey('LogPath') -and ` - ($LogPath -ne $website.logfile.directory)) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPath ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.directory -value $LogPath - } - - # Update LogPeriod if needed - if ($PSBoundParameters.ContainsKey('LogPeriod') -and ` - ($LogPeriod -ne $website.logfile.period)) - { - if ($PSBoundParameters.ContainsKey('LogTruncateSize')) - { - Write-Verbose -Message ($LocalizedData.WarningLogPeriod -f $Name) - } - - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPeriod) - - # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.Period property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.Period = $LogPeriod - $site | Set-Item - } - - # Update LogTruncateSize if needed - if ($PSBoundParameters.ContainsKey('LogTruncateSize') -and ` - ($LogTruncateSize -ne $website.logfile.LogTruncateSize)) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogTruncateSize ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.truncateSize -Value $LogTruncateSize - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.period -Value 'MaxSize' - } - - # Update LoglocalTimeRollover if needed - if ($PSBoundParameters.ContainsKey('LoglocalTimeRollover') -and ` - ($LoglocalTimeRollover -ne ` - ([System.Convert]::ToBoolean($website.logfile.LocalTimeRollover)))) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLoglocalTimeRollover ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.localTimeRollover -Value $LoglocalTimeRollover - } } # Create website if it does not exist else @@ -617,146 +479,146 @@ function Set-TargetResource -ErrorCategory 'InvalidOperation' } } + } - # Set Authentication; if not defined then pass in DefaultAuthenticationInfo - if ($PSBoundParameters.ContainsKey('AuthenticationInfo') -and ` - (-not (Test-AuthenticationInfo -Site $Name ` - -AuthenticationInfo $AuthenticationInfo))) - { - Set-AuthenticationInfo -Site $Name ` - -AuthenticationInfo $AuthenticationInfo ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetAuthenticationInfoUpdated ` - -f $Name) - } + # Set Authentication; if not defined then pass in DefaultAuthenticationInfo + if ($PSBoundParameters.ContainsKey('AuthenticationInfo') -and ` + (-not (Test-AuthenticationInfo -Site $Name ` + -AuthenticationInfo $AuthenticationInfo))) + { + Set-AuthenticationInfo -Site $Name ` + -AuthenticationInfo $AuthenticationInfo ` + -ErrorAction Stop + Write-Verbose -Message ($LocalizedData.VerboseSetTargetAuthenticationInfoUpdated ` + -f $Name) + } - # Update Preload if required - if ($PSBoundParameters.ContainsKey('preloadEnabled') -and ` - ($website.applicationDefaults.preloadEnabled -ne $PreloadEnabled)) - { - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.preloadEnabled ` - -Value $PreloadEnabled ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsitePreloadUpdated ` - -f $Name) - } + # Update Preload if required + if ($PSBoundParameters.ContainsKey('preloadEnabled') -and ` + ($website.applicationDefaults.preloadEnabled -ne $PreloadEnabled)) + { + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name applicationDefaults.preloadEnabled ` + -Value $PreloadEnabled ` + -ErrorAction Stop + Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsitePreloadUpdated ` + -f $Name) + } - # Update AutoStart if required - if ($PSBoundParameters.ContainsKey('ServiceAutoStartEnabled') -and ` - ($website.applicationDefaults.ServiceAutoStartEnabled -ne $ServiceAutoStartEnabled)) - { - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.serviceAutoStartEnabled ` - -Value $ServiceAutoStartEnabled ` - -ErrorAction Stop - Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsiteAutoStartUpdated ` - -f $Name) - } + # Update AutoStart if required + if ($PSBoundParameters.ContainsKey('ServiceAutoStartEnabled') -and ` + ($website.applicationDefaults.ServiceAutoStartEnabled -ne $ServiceAutoStartEnabled)) + { + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name applicationDefaults.serviceAutoStartEnabled ` + -Value $ServiceAutoStartEnabled ` + -ErrorAction Stop + Write-Verbose -Message ($LocalizedData.VerboseSetTargetWebsiteAutoStartUpdated ` + -f $Name) + } - # Update AutoStartProviders if required - if ($PSBoundParameters.ContainsKey('ServiceAutoStartProvider') -and ` - ($website.applicationDefaults.ServiceAutoStartProvider ` - -ne $ServiceAutoStartProvider)) + # Update AutoStartProviders if required + if ($PSBoundParameters.ContainsKey('ServiceAutoStartProvider') -and ` + ($website.applicationDefaults.ServiceAutoStartProvider ` + -ne $ServiceAutoStartProvider)) + { + if (-not (Confirm-UniqueServiceAutoStartProviders ` + -ServiceAutoStartProvider $ServiceAutoStartProvider ` + -ApplicationType $ApplicationType)) { - if (-not (Confirm-UniqueServiceAutoStartProviders ` - -ServiceAutoStartProvider $ServiceAutoStartProvider ` - -ApplicationType $ApplicationType)) - { - Add-WebConfiguration -filter /system.applicationHost/serviceAutoStartProviders ` - -Value @{ - name=$ServiceAutoStartProvider; - type=$ApplicationType - } ` - -ErrorAction Stop - Write-Verbose -Message ` - ($LocalizedData.VerboseSetTargetIISAutoStartProviderUpdated) - } - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name applicationDefaults.serviceAutoStartProvider ` - -Value $ServiceAutoStartProvider -ErrorAction Stop + Add-WebConfiguration -filter /system.applicationHost/serviceAutoStartProviders ` + -Value @{ + name=$ServiceAutoStartProvider; + type=$ApplicationType + } ` + -ErrorAction Stop Write-Verbose -Message ` - ($LocalizedData.VerboseSetTargetWebsiteAutoStartProviderUpdated ` - -f $Name) + ($LocalizedData.VerboseSetTargetIISAutoStartProviderUpdated) } + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name applicationDefaults.serviceAutoStartProvider ` + -Value $ServiceAutoStartProvider -ErrorAction Stop + Write-Verbose -Message ` + ($LocalizedData.VerboseSetTargetWebsiteAutoStartProviderUpdated ` + -f $Name) + } - # Update LogFormat if Needed - if ($PSBoundParameters.ContainsKey('LogFormat') -and ` - ($LogFormat -ne $website.logfile.LogFormat)) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFormat -f $Name) + # Update LogFormat if Needed + if ($PSBoundParameters.ContainsKey('LogFormat') -and ` + ($LogFormat -ne $website.logfile.LogFormat)) + { + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFormat -f $Name) - # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.LogFormat property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.LogFormat = $LogFormat - $site | Set-Item - } + # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.LogFormat property + $site = Get-Item "IIS:\Sites\$Name" + $site.LogFile.LogFormat = $LogFormat + $site | Set-Item + } - # Update LogFlags if required - if ($PSBoundParameters.ContainsKey('LogFlags') -and ` - (-not (Compare-LogFlags -Name $Name -LogFlags $LogFlags))) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFlags ` - -f $Name) + # Update LogFlags if required + if ($PSBoundParameters.ContainsKey('LogFlags') -and ` + (-not (Compare-LogFlags -Name $Name -LogFlags $LogFlags))) + { + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogFlags ` + -f $Name) - # Set-ItemProperty has no effect with the LogFile.LogExtFileFlags property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.LogFormat = 'W3C' - $site.LogFile.LogExtFileFlags = $LogFlags -join ',' - $site | Set-Item - } + # Set-ItemProperty has no effect with the LogFile.LogExtFileFlags property + $site = Get-Item "IIS:\Sites\$Name" + $site.LogFile.LogFormat = 'W3C' + $site.LogFile.LogExtFileFlags = $LogFlags -join ',' + $site | Set-Item + } - # Update LogPath if required - if ($PSBoundParameters.ContainsKey('LogPath') -and ` - ($LogPath -ne $website.logfile.directory)) - { + # Update LogPath if required + if ($PSBoundParameters.ContainsKey('LogPath') -and ` + ($LogPath -ne $website.logfile.directory)) + { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPath ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.directory -value $LogPath - } + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPath ` + -f $Name) + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name LogFile.directory -value $LogPath + } - # Update LogPeriod if needed - if ($PSBoundParameters.ContainsKey('LogPeriod') -and ` - ($LogPeriod -ne $website.logfile.period)) - { - if ($PSBoundParameters.ContainsKey('LogTruncateSize')) - { - Write-Verbose -Message ($LocalizedData.WarningLogPeriod ` - -f $Name) - } + # Update LogPeriod if needed + if ($PSBoundParameters.ContainsKey('LogPeriod') -and ` + ($LogPeriod -ne $website.logfile.period)) + { + if ($PSBoundParameters.ContainsKey('LogTruncateSize')) + { + Write-Verbose -Message ($LocalizedData.WarningLogPeriod ` + -f $Name) + } - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPeriod) + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPeriod) - # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.Period property - $site = Get-Item "IIS:\Sites\$Name" - $site.LogFile.Period = $LogPeriod - $site | Set-Item - } + # In Windows Server 2008 R2, Set-ItemProperty only accepts index values to the LogFile.Period property + $site = Get-Item "IIS:\Sites\$Name" + $site.LogFile.Period = $LogPeriod + $site | Set-Item + } - # Update LogTruncateSize if needed - if ($PSBoundParameters.ContainsKey('LogTruncateSize') -and ` - ($LogTruncateSize -ne $website.logfile.LogTruncateSize)) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogTruncateSize ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.truncateSize -Value $LogTruncateSize - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.period -Value 'MaxSize' - } + # Update LogTruncateSize if needed + if ($PSBoundParameters.ContainsKey('LogTruncateSize') -and ` + ($LogTruncateSize -ne $website.logfile.LogTruncateSize)) + { + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogTruncateSize ` + -f $Name) + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name LogFile.truncateSize -Value $LogTruncateSize + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name LogFile.period -Value 'MaxSize' + } - # Update LoglocalTimeRollover if needed - if ($PSBoundParameters.ContainsKey('LoglocalTimeRollover') -and ` - ($LoglocalTimeRollover -ne ` - ([System.Convert]::ToBoolean($website.logfile.LocalTimeRollover)))) - { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLoglocalTimeRollover ` - -f $Name) - Set-ItemProperty -Path "IIS:\Sites\$Name" ` - -Name LogFile.localTimeRollover -Value $LoglocalTimeRollover - } + # Update LoglocalTimeRollover if needed + if ($PSBoundParameters.ContainsKey('LoglocalTimeRollover') -and ` + ($LoglocalTimeRollover -ne ` + ([System.Convert]::ToBoolean($website.logfile.LocalTimeRollover)))) + { + Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLoglocalTimeRollover ` + -f $Name) + Set-ItemProperty -Path "IIS:\Sites\$Name" ` + -Name LogFile.localTimeRollover -Value $LoglocalTimeRollover } # Update LogCustomFields if needed diff --git a/README.md b/README.md index fba001522..c67e75a68 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,7 @@ This resource manages the IIS configuration section locking (overrideMode) to co * Update section header for WebApplicationHandler in README. * Fix tests for helper function `Get-LocalizedData` in Helper.Tests.ps1 that referenced the wrong path. +* Remove duplication in MSFT_xWebsite.psm1. [Krzysztof Morcinek (@kmorcinek)](https://github.com/kmorcinek) ### 2.1.0.0