Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function Get-SPDSCWebApplicationGeneralConfig
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param(
        [Parameter(Mandatory = $true)]
        $WebApplication
    )

    if ($WebApplication.DefaultTimeZone -eq -1)
    {
        $timezone = $null
    }
    else
    {
        $timezone = $WebApplication.DefaultTimeZone
    }

    return @{
        TimeZone = $timezone
        Alerts = $WebApplication.AlertsEnabled
        AlertsLimit = $WebApplication.AlertsMaximum
        RSS = $WebApplication.SyndicationEnabled
        BlogAPI = $WebApplication.MetaWeblogEnabled
        BlogAPIAuthenticated = $WebApplication.MetaWeblogAuthenticationEnabled
        BrowserFileHandling = $WebApplication.BrowserFileHandling
        SecurityValidation = $WebApplication.FormDigestSettings.Enabled
        SecurityValidationExpires = $WebApplication.FormDigestSettings.Expires
        SecurityValidationTimeoutMinutes = $WebApplication.FormDigestSettings.Timeout.TotalMinutes
        RecycleBinEnabled = $WebApplication.RecycleBinEnabled
        RecycleBinCleanupEnabled = $WebApplication.RecycleBinCleanupEnabled
        RecycleBinRetentionPeriod = $WebApplication.RecycleBinRetentionPeriod
        SecondStageRecycleBinQuota = $WebApplication.SecondStageRecycleBinQuota
        MaximumUploadSize = $WebApplication.MaximumFileSize
        CustomerExperienceProgram = $WebApplication.BrowserCEIPEnabled
        PresenceEnabled = $WebApplication.PresenceEnabled
        AllowOnlineWebPartCatalog = $WebApplication.AllowAccessToWebPartCatalog
        SelfServiceSiteCreationEnabled = $WebApplication.SelfServiceSiteCreationEnabled
        DefaultQuotaTemplate = $WebApplication.DefaultQuotaTemplate
    }
}

function Set-SPDSCWebApplicationGeneralConfig
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        $WebApplication,

        [Parameter(Mandatory = $true)]
        $Settings
    )

    if ($Settings.SecurityValidationTimeoutMinutes)
    {
        Write-Verbose -Message "timeout minutes: $($Settings.SecurityValidationTimeOutMinutes)"
        $mins = New-TimeSpan -Minutes $Settings.SecurityValidationTimeoutMinutes
        $Settings.SecurityValidationTimeoutMinutes = $mins
    }

    # Format here is SPWebApplication property = Custom settings property
    $mapping = @{
        DefaultTimeZone = "TimeZone"
        AlertsEnabled = "Alerts"
        AlertsMaximum = "AlertsLimit"
        SyndicationEnabled = "RSS"
        MetaWeblogEnabled = "BlogAPI"
        MetaWeblogAuthenticationEnabled = "BlogAPIAuthenticated"
        BrowserFileHandling = "BrowserFileHandling"
        MaximumFileSize = "MaximumUploadSize"
        RecycleBinEnabled = "RecycleBinEnabled"
        RecycleBinCleanupEnabled = "RecycleBinCleanupEnabled"
        RecycleBinRetentionPeriod = "RecycleBinRetentionPeriod"
        SecondStageRecycleBinQuota = "SecondStageRecycleBinQuota"
        BrowserCEIPEnabled = "CustomerExperienceProgram"
        PresenceEnabled = "Presence"
        AllowAccessToWebPartCatalog = "AllowOnlineWebPartCatalog"
        SelfServiceSiteCreationEnabled = "SelfServiceSiteCreationEnabled"
        DefaultQuotaTemplate = "DefaultQuotaTemplate"
    }
    $mapping.Keys | ForEach-Object -Process {
        Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $WebApplication `
                                                   -PropertyToSet $_ `
                                                   -ParamsValue $settings `
                                                   -ParamKey $mapping[$_]
    }

    # Set form digest settings child properties
    Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $WebApplication.FormDigestSettings `
                                          -PropertyToSet "Enabled" `
                                          -ParamsValue $settings `
                                          -ParamKey "SecurityValidation"

   Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $WebApplication.FormDigestSettings `
                                         -PropertyToSet "Expires" `
                                         -ParamsValue $settings `
                                         -ParamKey "SecurityValidationExpires"

    Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $WebApplication.FormDigestSettings `
                                          -PropertyToSet "Timeout" `
                                          -ParamsValue $settings `
                                          -ParamKey "SecurityValidationTimeOutMinutes"
}

function Test-SPDSCWebApplicationGeneralConfig
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param(
        [Parameter(Mandatory = $true)]
        $CurrentSettings,

        [Parameter(Mandatory = $true)]
        $DesiredSettings
    )

    $relPath = "..\..\Modules\SharePointDsc.Util\SharePointDsc.Util.psm1"
    Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath $relPath -Resolve)
    $valuesToCheck = @("TimeZone",
                       "Alerts",
                       "AlertsLimit",
                       "RSS",
                       "BlogAPI",
                       "BlogAPIAuthenticated",
                       "BrowserFileHandling",
                       "SecurityValidation",
                       "SecurityValidationExpires",
                       "SecurityValidationTimeoutMinutes",
                       "RecycleBinEnabled",
                       "RecycleBinCleanupEnabled",
                       "RecycleBinRetentionPeriod",
                       "SecondStageRecycleBinQuota",
                       "MaximumUploadSize",
                       "CustomerExperienceProgram",
                       "PresenceEnabled",
                       "AllowOnlineWebPartCatalog",
                       "SelfServiceSiteCreationEnabled",
                       "DefaultQuotaTemplate"
                      )
    $testReturn = Test-SPDscParameterState -CurrentValues $CurrentSettings `
                                           -DesiredValues $DesiredSettings `
                                           -ValuesToCheck $valuesToCheck
    return $testReturn
}