Skip to content

Commit

Permalink
Merge pull request #1182 from ykuijs/master
Browse files Browse the repository at this point in the history
Improved verbose logging and added logging to custom event log
  • Loading branch information
ykuijs authored Mar 19, 2020
2 parents 9d26732 + 9fff701 commit 8639d83
Show file tree
Hide file tree
Showing 132 changed files with 2,069 additions and 520 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- SharePointDsc
- Added verbose logging of the test results in the Test method
- Added function to create SharePointDsc event log and add log entries
- Added the logging of all test results to the new SharePointDsc event log

### Fixed

- SPFarmSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,25 @@ function Test-TargetResource

if ($CurrentValues.DatabaseServer -ne $DatabaseServer)
{
Write-Verbose -Message ("Specified database server does not match the actual " + `
"database server. This resource cannot move the database " + `
"to a different SQL instance.")
return $false
$message = "Specified database server does not match the actual database " + `
"server. This resource cannot move the database to a different " + `
"SQL instance. Actual: $($CurrentValues.DatabaseServer), " + `
"Desired: $DatabaseServer"
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source
$result = $false
}
else
{
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")
}

return Test-SPDscParameterState -CurrentValues $CurrentValues `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")
Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,14 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Name", "ApplicationPool", "Ensure")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ function Test-TargetResource

if ($Ensure -eq "Present")
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("WebAppName", `
"Zone", `
Expand All @@ -293,8 +294,13 @@ function Test-TargetResource
}
else
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")
}

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,13 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("SiteUrl")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("AppDomain", "Prefix")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,23 @@ function Test-TargetResource

if ($CurrentValues.ProxyName -eq "")
{
return $false
$message = "The specified ProxyName is empty"
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source
$result = $false
}
else
{
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("ApplicationPool", `
"Ensure")
}

return Test-SPDscParameterState -CurrentValues $CurrentValues `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("ApplicationPool", `
"Ensure")
Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,25 @@ function Test-TargetResource

if ($null -eq $currentValues.WebAppUrl)
{
Write-Verbose -Message "Specified web application does not exist."
$message = "Specified web application does not exist."
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source

Write-Verbose -Message "Test-TargetResource returned false"
return $false
}

if ($PSBoundParameters.ContainsKey("AllowAppPurchases"))
{
if ($AllowAppPurchases -ne $CurrentValues.AllowAppPurchases)
{
$message = ("The parameter AllowAppPurchases for web application $WebAppUrl "+ `
"is not in the desired state. Actual: " + `
"$($CurrentValues.AllowAppPurchases), Desired: $AllowAppPurchases")
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source

Write-Verbose -Message "Test-TargetResource returned false"
return $false
}
}
Expand All @@ -166,10 +177,18 @@ function Test-TargetResource
{
if ($AllowAppsForOffice -ne $CurrentValues.AllowAppsForOffice)
{
$message = ("The parameter AllowAppsForOffice for web application $WebAppUrl "+ `
"is not in the desired state. Actual: " + `
"$($CurrentValues.AllowAppsForOffice), Desired: $AllowAppsForOffice")
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source

Write-Verbose -Message "Test-TargetResource returned false"
return $false
}
}

Write-Verbose -Message "Test-TargetResource returned true"
return $true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ function Test-TargetResource()
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("AuthenticationRealm")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,22 @@ function Test-TargetResource

if ($Ensure -eq "Present")
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("MetadataServiceEndpointUri", "Ensure")
}
else
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")
}

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,14 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("ApplicationPool", "Ensure")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,27 @@ function Test-TargetResource
{
if (-not (Test-Path -Path $Location))
{
Write-Verbose "Blob Cache Folder $Location does not exist"
$message = "Blob Cache Folder $Location does not exist"
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source

Write-Verbose -Message "Test-TargetResource returned false"
return $false
}
}

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("EnableCache",
"Location",
"MaxSizeInGB",
"FileType",
"MaxAgeInSeconds")
"Location",
"MaxSizeInGB",
"FileType",
"MaxAgeInSeconds")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,25 @@ function Test-TargetResource

if ($SetWebAppPolicy -eq $true)
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("SuperUserAlias", `
"SuperReaderAlias", `
"SetWebAppPolicy")
}
else
{
return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("SuperUserAlias", `
"SuperReaderAlias")
}

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,23 @@ function Test-TargetResource

if ($PSBoundParameters.ContainsKey('DatabaseServer') -and $PSBoundParameters.DatabaseServer -ne $null -and $CurrentValues.DatabaseServer -ne $PSBoundParameters.DatabaseServer)
{
Write-Verbose -Message ("Specified database server does not match the actual " + `
"database server. This resource cannot move the database " + `
"to a different SQL instance.")
$message = ("Specified database server $DatabaseServer does not match the actual " + `
"database server $($CurrentValues.DatabaseServer). This resource cannot move " + `
"the database to a different SQL instance.")
Write-Verbose -Message $message
Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $MyInvocation.MyCommand.Source

Write-Verbose -Message "Test-TargetResource returned false"
return $false
}

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,13 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-SPDscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-SPDscHashtableToString -Hashtable $PSBoundParameters)"

return Test-SPDscParameterState -CurrentValues $CurrentValues `
$result = Test-SPDscParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Ensure", "DatabaseName")

Write-Verbose -Message "Test-TargetResource returned $result"

return $result
}

Loading

0 comments on commit 8639d83

Please sign in to comment.