Skip to content

Commit

Permalink
Merge pull request #1350 from ykuijs/master
Browse files Browse the repository at this point in the history
Bugfix PR: #1346, #1347, #1348 and #1349
  • Loading branch information
ykuijs authored Oct 2, 2021
2 parents fbd52e9 + 92f8a9b commit f4d64fa
Show file tree
Hide file tree
Showing 16 changed files with 718 additions and 242 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- SPLogLevel
- Added ReverseDsc export support to this resource
- SPWebApplication
- Added logic to check if specified content database exists in the web
application
- Added possibility to update application pool

### Fixed

- ReverseDsc
- Fixed issue where the export would contain duplicate configuration
- Fixed issue where the example export cmdlets was in the incorrect format
- SPDocIcon
- Fixed issue where the resource was using hardcoded SP2016 and later paths
and therefore didn't work in SP2013
- SPSearchServiceApp
- Fix SQL authentication support with updating DB ownership functions
- SPServiceAppPool
- Fixed issue in Export method where the PsDscRunAsCredential was stored as
a string instead of a PsCredential object
- SPSite
- Fixed issue where the code continues when the creation of the site failed,
throwing even more errors

## [4.8.0] - 2021-08-31

### Added
Expand Down
10 changes: 8 additions & 2 deletions SharePointDsc/DSCResources/MSFT_SPDocIcon/MSFT_SPDocIcon.psm1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$script:SPDscUtilModulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\SharePointDsc.Util'
Import-Module -Name $script:SPDscUtilModulePath

$dociconPath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'microsoft shared\Web Server Extensions\16\TEMPLATE\XML'
$iconPath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'microsoft shared\Web Server Extensions\16\TEMPLATE\IMAGES'
$dociconPath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'microsoft shared\Web Server Extensions\{0}\TEMPLATE\XML'
$iconPath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'microsoft shared\Web Server Extensions\{0}\TEMPLATE\IMAGES'
$dociconFileName = 'DOCICON.XML'
$backupFileName = 'DOCICON_Backup_{0}.XML'

Expand Down Expand Up @@ -55,6 +55,7 @@ function Get-TargetResource
return $nullReturn
}

$dociconPath = $dociconPath -f (Get-SPDscInstalledProductVersion).FileMajorPart
$docIconFilePath = Join-Path -Path $dociconPath -ChildPath $dociconFileName

if ((Test-Path -Path $docIconFilePath) -eq $false)
Expand All @@ -76,6 +77,7 @@ function Get-TargetResource
{
Write-Verbose -Message "Specifed file type ($FileType) exists in docicon.xml"

$iconPath = $iconPath -f (Get-SPDscInstalledProductVersion).FileMajorPart
$iconFilePath = Join-Path -Path $iconPath -ChildPath $xmlNode.Value
if (Test-Path -Path $iconFilePath)
{
Expand Down Expand Up @@ -150,6 +152,7 @@ function Set-TargetResource
throw $message
}

$dociconPath = $dociconPath -f (Get-SPDscInstalledProductVersion).FileMajorPart
$docIconFilePath = Join-Path -Path $dociconPath -ChildPath $dociconFileName

if ((Test-Path -Path $docIconFilePath) -eq $false)
Expand All @@ -166,6 +169,8 @@ function Set-TargetResource
$xmlDoc.Load($docIconFilePath)
$xmlNode = $xmlDoc.SelectSingleNode("//Mapping[@Key='$($FileType.ToLower())']")

$iconPath = $iconPath -f (Get-SPDscInstalledProductVersion).FileMajorPart

$changed = $false
if ($Ensure -eq 'Present')
{
Expand Down Expand Up @@ -335,6 +340,7 @@ function Export-TargetResource
$Content = ''
$params = Get-DSCFakeParameters -ModulePath $module

$dociconPath = $dociconPath -f (Get-SPDscInstalledProductVersion).FileMajorPart
$docIconFilePath = Join-Path -Path $dociconPath -ChildPath $dociconFileName

if ((Test-Path -Path $docIconFilePath) -eq $false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*

**Example**

SPHealthAnalyzerRuleState DisableDiskSpaceRule
{
Name = "Drives are at risk of running out of free space."
Enabled = $true
RuleScope = "All Servers"
Schedule = "Daily"
FixAutomatically = $false
InstallAccount = $InstallAccount
}
*/

[ClassVersion("1.0.0.0"), FriendlyName("SPHealthAnalyzerRuleState")]
class MSFT_SPHealthAnalyzerRuleState : OMI_BaseResource
{
Expand All @@ -23,4 +8,3 @@ class MSFT_SPHealthAnalyzerRuleState : OMI_BaseResource
[Write, Description("Should the rule fix itself automatically")] Boolean FixAutomatically;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

162 changes: 108 additions & 54 deletions SharePointDsc/DSCResources/MSFT_SPLogLevel/MSFT_SPLogLevel.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -89,69 +89,54 @@ function Get-TargetResource
return $null
}

#TraceLevels
#if we desire defaults, we will check for default for each item and return as such
if ($DesiredSetting.TraceLevel -eq "Default")
foreach ($currentItem in $CurrentLogItemSettings)
{
$SettingAtDefault = $true #assume they are all at default until we find otherwise
foreach ($setting in $CurrentLogItemSettings) #default values can vary for each area/name, need to check each one.
#TraceLevels
#if we desire defaults, we will check for default for each item and return as such
if ($DesiredSetting.TraceLevel -eq "Default")
{
if ($setting.TraceSeverity -ne $setting.DefaultTraceSeverity)
if ($currentItem.TraceSeverity -eq $currentItem.DefaultTraceSeverity)
{
$SettingAtDefault = $false
$Tracelevel = 'Default'
}
else
{
#return a csv list of current unique trace level settings for the provided Area/Name
$Tracelevel = $currentItem.TraceSeverity
}
}

if ($SettingAtDefault)
{
$Tracelevel = 'Default'
}
#default was not specified, so we return the unique current trace severity across all provided settings.
else
{
#return a csv list of current unique trace level settings for the provided Area/Name
$Tracelevel = [System.String]::Join(",", (($CurrentLogItemSettings.traceseverity) | Select-Object -Unique))
$Tracelevel = $currentItem.TraceSeverity
}
}
#default was not specified, so we return the unique current trace severity across all provided settings.
else
{
$Tracelevel = [System.String]::Join(",", (($CurrentLogItemSettings.traceseverity) | Select-Object -Unique))
}

#EventLevels
#if we desire defaults, we will check for default and return as such
if ($DesiredSetting.EventLevel -eq "Default")
{
$SettingAtDefault = $true #assume they are all at default until we find otherwise
foreach ($setting in $CurrentLogItemSettings) #default values can vary for each area/name, need to check each one.
#EventLevels
#if we desire defaults, we will check for default and return as such
if ($DesiredSetting.EventLevel -eq "Default")
{
if ($setting.EventSeverity -ne $setting.DefaultEventSeverity)
if ($currentItem.EventSeverity -eq $currentItem.DefaultEventSeverity)
{
$SettingAtDefault = $false
$Eventlevel = 'Default'
}
else
{
#return a csv list of current unique Event level settings for the provided Area/Name
$Eventlevel = $currentItem.Eventseverity
}
}

if ($SettingAtDefault)
{
$Eventlevel = 'Default'
}
#default was not specified, so we return the unique current Event severity across all provided settings.
else
{
#return a csv list of current unique Event level settings for the provided Area/Name
$Eventlevel = [System.String]::Join(",", (($CurrentLogItemSettings.Eventseverity) | Select-Object -Unique))
$Eventlevel = $currentItem.Eventseverity
}
}
#default was not specified, so we return the unique current Event severity across all provided settings.
else
{
$Eventlevel = [System.String]::Join(",", (($CurrentLogItemSettings.Eventseverity) | Select-Object -Unique))
}

$CurrentLogLevelSettings += New-Object -TypeName PSObject -Property @{
Area = $DesiredSetting.Area
Name = $DesiredSetting.Name
TraceLevel = $TraceLevel
EventLevel = $EventLevel
$CurrentLogLevelSettings += New-Object -TypeName PSObject -Property @{
Area = $currentItem.Area
Name = $currentItem.Name
TraceLevel = $TraceLevel
EventLevel = $EventLevel
}
}
}

Expand Down Expand Up @@ -336,17 +321,41 @@ function Test-TargetResource
{
Write-Verbose -Message "Testing SP Log Level setting for $($DesiredSetting.Area):$($DesiredSetting.Name)"

$CurrentSetting = $CurrentValues.SPLogLevelSetting | Where-Object -FilterScript { $_.Area -eq $DesiredSetting.Area -and $_.Name -eq $DesiredSetting.Name }
if ($DesiredSetting.Area -eq "*")
{
if ($DesiredSetting.Name -eq "*")
{
$CurrentSettings = $CurrentValues.SPLogLevelSetting
}
else
{
$CurrentSettings = $CurrentValues.SPLogLevelSetting | Where-Object -FilterScript { $_.Name -eq $DesiredSetting.Name }
}
}
else
{
if ($DesiredSetting.Name -eq "*")
{
$CurrentSettings = $CurrentValues.SPLogLevelSetting | Where-Object -FilterScript { $_.Area -eq $DesiredSetting.Area }
}
else
{
$CurrentSettings = $CurrentValues.SPLogLevelSetting | Where-Object -FilterScript { $_.Area -eq $DesiredSetting.Area -and $_.Name -eq $DesiredSetting.Name }
}
}

if (($null -ne $DesiredSetting.TraceLevel -and $CurrentSetting.TraceLevel -ne $DesiredSetting.TraceLevel) -or ($null -ne $DesiredSetting.EventLevel -and $CurrentSetting.EventLevel -ne $DesiredSetting.EventLevel))
foreach ($currentSetting in $CurrentSettings)
{
$mismatchedSettings += @{
Name = $Name
DesiredSetting = $DesiredSetting
$CurrentSetting = $CurrentSetting
if (($null -ne $DesiredSetting.TraceLevel -and $currentSetting.TraceLevel -ne $DesiredSetting.TraceLevel) -or ($null -ne $DesiredSetting.EventLevel -and $currentSetting.EventLevel -ne $DesiredSetting.EventLevel))
{
$mismatchedSettings += @{
Name = $Name
DesiredSetting = $DesiredSetting
CurrentSetting = $currentSetting
}
Write-Verbose -Message "SP Log Level setting for $($currentSetting.Area):$($currentSetting.Name) is not in the desired state"
$mismatchedSettingFound = $true
}
Write-Verbose -Message "SP Log Level setting for $($DesiredSetting.Area):$($DesiredSetting.Name) is not in the desired state"
$mismatchedSettingFound = $true
}
}

Expand Down Expand Up @@ -384,3 +393,48 @@ function Test-TargetResource

return $result
}

function Export-TargetResource
{
$VerbosePreference = "SilentlyContinue"
$ParentModuleBase = Get-Module "SharePointDsc" -ListAvailable | Select-Object -ExpandProperty Modulebase
$module = Join-Path -Path $ParentModuleBase -ChildPath "\DSCResources\MSFT_SPLogLevel\MSFT_SPLogLevel.psm1" -Resolve

$Content = ''
$params = Get-DSCFakeParameters -ModulePath $module
$PartialContent = " SPLogLevel AllLogLevels`r`n"
$PartialContent += " {`r`n"

try
{
$params.SPLogLevelSetting = @()
$params.SPLogLevelSetting += New-CimInstance -ClassName MSFT_SPLogLevelItem -Property @{
Area = "*"
Name = "*"
TraceLevel = "Default"
EventLevel = "Default"
} -ClientOnly
$results = Get-TargetResource @params

$results = Repair-Credentials -results $results

$currentBlock = Get-DSCBlock -Params $results -ModulePath $module
$currentBlock = Convert-DSCStringParamToVariable -DSCBlock $currentBlock -ParameterName "PsDscRunAsCredential"

# Change hashtable format into CIM Instance format
$currentBlock = $currentBlock -replace "@{", "`r`n MSFT_SPLogLevelItem {" -replace "}", "}," -replace ",\);", "`r`n );" -replace "=", "=`"" -replace "; ", "`"; " -replace "}", "`"}"

$PartialContent += $currentBlock
$PartialContent += " }`r`n"
$Content += $PartialContent
}
catch
{
$Global:ErrorLog += "[Diagnostic Logging Level]`r`n"
$Global:ErrorLog += "$_`r`n`r`n"
}

return $Content
}

Export-ModuleMember -Function *-TargetResource
Loading

0 comments on commit f4d64fa

Please sign in to comment.