From 4882394f17dbf26b33cc4850e75edb35ecda45fc Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 17 May 2017 15:46:05 +0200 Subject: [PATCH 01/18] Ready for testing changes --- CHANGELOG.md | 9 + .../MSFT_SPExcelServiceApp.psm1 | 30 ++-- .../DSCResources/MSFT_SPInstall/Readme.md | 3 + .../MSFT_SPInstallLanguagePack.psm1 | 82 ++++++--- .../MSFT_SPOutgoingEmailSettings.psm1 | 107 ++++++++++- .../MSFT_SPOutgoingEmailSettings.schema.mof | 2 + ...MSFT_SPSubscriptionSettingsServiceApp.psm1 | 15 +- .../MSFT_SPWebApplication.psm1 | 92 ++++++---- .../MSFT_SPWebApplication.schema.mof | 2 +- ...rePointDsc.SPInstallLanguagePack.Tests.ps1 | 170 ++++++++---------- ...PointDsc.SPOutgoingEmailSettings.Tests.ps1 | 161 ++++++++++++++++- ...ePointDsc.SPSubscriptionSettings.Tests.ps1 | 128 ++++++++++--- .../SharePointDsc.SPWebApplication.Tests.ps1 | 15 ++ 13 files changed, 612 insertions(+), 204 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b728b616d..3413615e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,15 @@ joined to a farm * Bugfix in SPContentDatabase for setting WarningSiteCount as 0. * Fixing verbose message that identifies SP2016 as 2013 in MSFT_SPFarm +* Fixed issue in SPSubscriptionSettingsServiceApp not returning database values +* Fixed issue in SPWebApplication where the Get method didn't return Classic + web applications properly +* Updated Readme of SPInstall to include SharePoint Foundation is not supported (580) +* Added TLS and SMTP port support for SharePoint 2016 (540) +* Fixed missing brackets in error message in SPExcelServiceApp (589) +* Removed the requirement for the ConfigWizard in SPInstallLanguagePack (594) +* Fixed LP detection issue in SPInstallLanguagePack (596) +* ISSUE 551 - ADImport rework ## 1.6 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 index 6e3cc8ba3..06e675b3f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 @@ -122,11 +122,11 @@ function Get-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] "Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` - "this service. See " + ` - "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` - "for more info." + throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "this service. See " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` + "for more info.") } $result = Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -313,11 +313,11 @@ function Set-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] "Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` - "this service. See " + ` - "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` - "for more info." + throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "this service. See " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` + "for more info.") } $result = Get-TargetResource @PSBoundParameters @@ -571,11 +571,11 @@ function Test-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] "Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` - "this service. See " + ` - "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` - "for more info." + throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "this service. See " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` + "for more info.") } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md index d9e8b2bba..a28caa18e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md @@ -6,6 +6,9 @@ itself). The ProductKey parameter is used to inject in to the configuration file and validate the license key during the installation process. This module depends on the prerequisites already being installed, which can be done +NOTE: This resource only supports SharePoint Server. SharePoint Foundation +is not supported. + ## Installing from network locations If you wish to install SharePoint from a network location this can diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 index 77d0a00a9..5dec4aa3e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 @@ -43,13 +43,10 @@ function Get-TargetResource throw "Unknown folder structure" } - $products = Invoke-SPDSCCommand -Credential $InstallAccount ` - -ScriptBlock { - return Get-SPDscRegProductsInfo - } + $products = Get-SPDscRegProductsInfo # Extract language from filename - if ($osrvFolder.Name -match "\w*.(\w{2}-\w{2})") + if ($osrvFolder.Name -match "\w*.(\w{2,3}-\w*-?\w*)") { $language = $matches[1] } @@ -75,9 +72,11 @@ function Get-TargetResource } # Extract English name of the language code - if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \(\w*\)") + $updateLanguage = "" + if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \([^)]*\)") { $languageEnglish = $matches[1] + $updateLanguage = $matches[0] if ($languageEnglish.contains(",")) { $languages = $languageEnglish.Split(",") @@ -86,7 +85,7 @@ function Get-TargetResource } # Extract Native name of the language code - if ($cultureInfo.NativeName -match "(\w*,*\s*\w*) \(\w*\)") + if ($cultureInfo.NativeName -match "(\w*,*\s*\w*) ?\([^)]*\)") { $languageNative = $matches[1] if ($languageNative.contains(",")) @@ -97,35 +96,77 @@ function Get-TargetResource } # Build language string used in Language Pack names - $languageString = "$languageEnglish/$languageNative" + $languageString = $("$languageEnglish/$languageNative").Trim() + $languageString2 = $("$languageEnglish $languageNative").Trim() + + switch ($updateLanguage) { + "Azerbaijani (Latin, Azerbaijan)" { + $languageString = "Azerbaijani/Azərbaycan­ılı" + $languageString2 = "NO MATCH" + } + "English (United States)" { + $languageString = "English" + $languageString2 = "NO MATCH" + } + "Portuguese (Brazil)" { + $languageString = "Portuguese/Português \(Brasil\)" + $languageString2 = "NO MATCH" + } + "Dari (Afghanistan)" { + $languageString = "درى Dari" + $languageString2 = "NO MATCH" + } + "Latvian (Latvia)" { + $languageString = "Latvian/latviski" + $languageString2 = "NO MATCH" + } + "Malay (Malaysia)" { + $languageString = "Malay/Bahasa Malaysia" + $languageString2 = "NO MATCH" + } + "Vietnamese (Vietnam)" { + $languageString = "Vietnamese/Tiếng Việt" + $languageString2 = "NO MATCH" + } + "Chinese (Simplified, China)" { + $languageString = 'Chinese \(PRC\)/中文\(简体\)' + $languageString2 = "NO MATCH" + } + "Chinese (Traditional, Taiwan)" { + $languageString = 'Chinese \(Taiwan\)/中文 \(繁體\)' + $languageString2 = "NO MATCH" + } + } Write-Verbose -Message "Update is for the $languageEnglish language" # Find the product name for the specific language pack - $productName = "" + $productFound = $false foreach ($product in $products) { - if ($product -match $languageString) + if ($product -match $languageString -or $product -match $languageString2) { - $productName = $product + $productFound = $true } } - if ($productName -eq "") + if ($productFound -eq $true) { + Write-Verbose -Message "Language Pack $languageEnglish is found" return @{ BinaryDir = $BinaryDir BinaryInstallDays = $BinaryInstallDays BinaryInstallTime = $BinaryInstallTime - Ensure = "Absent" + Ensure = "Present" } } else { + Write-Verbose -Message "Language Pack $languageEnglish is NOT found" return @{ BinaryDir = $BinaryDir BinaryInstallDays = $BinaryInstallDays BinaryInstallTime = $BinaryInstallTime - Ensure = "Present" + Ensure = "Absent" } } } @@ -257,19 +298,6 @@ function Set-TargetResource $wssRegKey ="hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0\WSS" } - # Read LanguagePackInstalled and SetupType registry keys - $languagePackInstalled = Get-SPDSCRegistryKey -Key $wssRegKey -Value "LanguagePackInstalled" - $setupType = Get-SPDSCRegistryKey -Key $wssRegKey -Value "SetupType" - - # Determine if LanguagePackInstalled=1 or SetupType=B2B_Upgrade. - # If so, the Config Wizard is required, so the installation will be skipped. - if (($languagePackInstalled -eq 1) -or ($setupType -eq "B2B_UPGRADE")) - { - Write-Verbose -Message ("An upgrade is pending. " + ` - "To prevent a possible loop, the install will be skipped") - return - } - Write-Verbose -Message "Writing install config file" $configPath = "$env:temp\SPInstallLanguagePackConfig.xml" diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 index 5cd4d011b..cc417fec0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 @@ -24,6 +24,14 @@ function Get-TargetResource [System.String] $CharacterSet, + [parameter(Mandatory = $false)] + [System.Boolean] + $UseTLS, + + [parameter(Mandatory = $false)] + [System.UInt32] + $SMTPPort, + [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount @@ -31,6 +39,19 @@ function Get-TargetResource Write-Verbose -Message "Getting outgoing email settings configuration for $WebAppUrl" + $installedVersion = Get-SPDSCInstalledProductVersion + if (($PSBoundParameters.ContainsKey("UseTLS") -eq $true) ` + -and $installedVersion.FileMajorPart -ne 16) + { + throw [Exception] "UseTLS is only supported in SharePoint 2016." + } + + if (($PSBoundParameters.ContainsKey("SMTPPort") -eq $true) ` + -and $installedVersion.FileMajorPart -ne 16) + { + throw [Exception] "SMTPPort is only supported in SharePoint 2016." + } + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { @@ -56,6 +77,8 @@ function Get-TargetResource FromAddress= $webApp.OutboundMailSenderAddress ReplyToAddress= $webApp.OutboundMailReplyToAddress CharacterSet = $webApp.OutboundMailCodePage + UseTLS = $webApp.OutboundMailEnableSsl + SMTPPort = $webApp.OutboundMailPort } } return $result @@ -86,6 +109,14 @@ function Set-TargetResource [System.String] $CharacterSet, + [parameter(Mandatory = $false)] + [System.Boolean] + $UseTLS, + + [parameter(Mandatory = $false)] + [System.UInt32] + $SMTPPort, + [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount @@ -93,9 +124,22 @@ function Set-TargetResource Write-Verbose -Message "Setting outgoing email settings configuration for $WebAppUrl" - Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + $installedVersion = Get-SPDSCInstalledProductVersion + if (($PSBoundParameters.ContainsKey("UseTLS") -eq $true) ` + -and $installedVersion.FileMajorPart -ne 16) + { + throw [Exception] "UseTLS is only supported in SharePoint 2016." + } + + if (($PSBoundParameters.ContainsKey("SMTPPort") -eq $true) ` + -and $installedVersion.FileMajorPart -ne 16) + { + throw [Exception] "SMTPPort is only supported in SharePoint 2016." + } + + $null = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { $params = $args[0] $webApp = $null @@ -106,10 +150,47 @@ function Set-TargetResource { throw "Web Application $webAppUrl not found" } - $webApp.UpdateMailSettings($params.SMTPServer, ` - $params.FromAddress, ` - $params.ReplyToAddress, ` - $params.CharacterSet) + + $installedVersion = Get-SPDSCInstalledProductVersion + switch ($installedVersion.FileMajorPart) + { + 15 { + $webApp.UpdateMailSettings($params.SMTPServer, ` + $params.FromAddress, ` + $params.ReplyToAddress, ` + $params.CharacterSet) + } + 16 { + if ($params.ContainsKey("UseTLS") -eq $false) + { + $UseTLS = $false + } + else + { + $UseTLS = $params.UseTLS + } + + if ($params.ContainsKey("SMTPPort") -eq $false) + { + $SMTPPort = 25 + } + else + { + $SMTPPort = $params.SMTPPort + } + + $webApp.UpdateMailSettings($params.SMTPServer, ` + $params.FromAddress, ` + $params.ReplyToAddress, ` + $params.CharacterSet, ` + $UseTLS, ` + $SMTPPort) + } + default { + throw ("Detected an unsupported major version of SharePoint. SharePointDsc only " + ` + "supports SharePoint 2013 or 2016.") + } + } } } @@ -139,6 +220,14 @@ function Test-TargetResource [System.String] $CharacterSet, + [parameter(Mandatory = $false)] + [System.Boolean] + $UseTLS, + + [parameter(Mandatory = $false)] + [System.UInt32] + $SMTPPort, + [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount @@ -158,7 +247,9 @@ function Test-TargetResource -ValuesToCheck @("SMTPServer", "FromAddress", "ReplyToAddress", - "CharacterSet") + "CharacterSet", + "UseTLS", + "SMTPPort") } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof index 3980350d8..6125de66a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof @@ -6,6 +6,8 @@ class MSFT_SPOutgoingEmailSettings : OMI_BaseResource [Required, Description("The from address to put on messages")] string FromAddress; [Required, Description("The email address that replies should be directed to")] string ReplyToAddress; [Required, Description("The character set to use on messages")] string CharacterSet; + [Write, Description("Use TLS when connecting to the SMTP server")] boolean UseTLS; + [Write, Description("The port which is used to connect to the SMTP server")] uint32 SMTPPort; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/MSFT_SPSubscriptionSettingsServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/MSFT_SPSubscriptionSettingsServiceApp.psm1 index 3646b916b..fe3443fb2 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/MSFT_SPSubscriptionSettingsServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/MSFT_SPSubscriptionSettingsServiceApp.psm1 @@ -59,11 +59,22 @@ function Get-TargetResource } else { + $propertyFlags = [System.Reflection.BindingFlags]::Instance ` + -bor [System.Reflection.BindingFlags]::NonPublic + + $propData = $serviceApp.GetType().GetProperties($propertyFlags) + + $dbProp = $propData | Where-Object -FilterScript { + $_.Name -eq "Database" + } + + $db = $dbProp.GetValue($serviceApp) + return @{ Name = $serviceApp.DisplayName ApplicationPool = $serviceApp.ApplicationPool.Name - DatabaseName = $serviceApp.Database.Name - DatabaseServer = $serviceApp.Database.Server.Name + DatabaseName = $db.Name + DatabaseServer = $db.Server.Name InstallAccount = $params.InstallAccount Ensure = "Present" } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 index 942ba122b..33c15ca1a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 @@ -49,7 +49,7 @@ function Get-TargetResource $UseSSL, [parameter(Mandatory = $false)] - [ValidateSet("NTLM","Kerberos","Claims")] + [ValidateSet("NTLM","Kerberos","Claims","Classic")] [System.String] $AuthenticationMethod, @@ -70,10 +70,9 @@ function Get-TargetResource Write-Verbose -Message "Getting web application '$Name' config" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] $wa = Get-SPWebApplication -Identity $params.Name -ErrorAction SilentlyContinue if ($null -eq $wa) @@ -86,24 +85,33 @@ function Get-TargetResource Ensure = "Absent" } } + ### COMMENT: Are we making an assumption here, about Default Zone $authProvider = Get-SPAuthenticationProvider -WebApplication $wa.Url -Zone "Default" - if($authProvider.DisplayName -eq "Windows Authentication") + if ($null -eq $authProvider) { - if ($authProvider.DisableKerberos -eq $true) - { - $localAuthMode = "NTLM" - } - else - { - $localAuthMode = "Kerberos" - } - $authenticationProvider = "Windows Authentication" + $authenticationProvider = "" + $localAuthMode = "Classic" } - else + else { - $localAuthMode = "Claims" - $authenticationProvider = $authProvider.DisplayName + if ($authProvider.DisplayName -eq "Windows Authentication") + { + if ($authProvider.DisableKerberos -eq $true) + { + $localAuthMode = "NTLM" + } + else + { + $localAuthMode = "Kerberos" + } + $authenticationProvider = "Windows Authentication" + } + else + { + $localAuthMode = "Claims" + $authenticationProvider = $authProvider.DisplayName + } } return @{ @@ -178,7 +186,7 @@ function Set-TargetResource $UseSSL, [parameter(Mandatory = $false)] - [ValidateSet("NTLM","Kerberos","Claims")] + [ValidateSet("NTLM","Kerberos","Claims","Classic")] [System.String] $AuthenticationMethod, @@ -198,19 +206,24 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$Name' config" - if ($Ensure -eq "Present") + if ($Ensure -eq "Present") { + if ($PSBoundParameters.ContainsKey("AuthenticationMethod") -eq $false) + { + throw [Exception] ("When Ensure is Present, the AuthenticationMethod " + ` + "parameter is required.") + } if ($AuthenticationMethod -eq "Claims" -and [string]::IsNullOrEmpty($AuthenticationProvider)) { - throw [Exception] "When configuring SPWebApplication to use Claims the AuthenticationProvider value must be specified." + throw [Exception] ("When configuring SPWebApplication to use Claims the " + ` + "AuthenticationProvider value must be specified.") } Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] $wa = Get-SPWebApplication -Identity $params.Name -ErrorAction SilentlyContinue if ($null -eq $wa) @@ -233,7 +246,7 @@ function Set-TargetResource # ApplicationPoolAccount parameter to create the application pool try { - Get-SPManagedAccount $params.ApplicationPoolAccount -ErrorAction Stop + $null = Get-SPManagedAccount $params.ApplicationPoolAccount -ErrorAction Stop $newWebAppParams.Add("ApplicationPoolAccount", $params.ApplicationPoolAccount) } catch @@ -255,18 +268,21 @@ function Set-TargetResource if ($params.ContainsKey("AuthenticationMethod") -eq $true) { - if($params.AuthenticationMethod -eq "Claims") - { - $ap = Get-SPTrustedIdentityTokenIssuer -Identity $params.AuthenticationProvider - } - else + if ($params.AuthenticationMethod -ne "Classic") { - $disableKerberos = ($params.AuthenticationMethod -eq "NTLM") - $ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication ` - -DisableKerberos:$disableKerberos + if ($params.AuthenticationMethod -eq "Claims") + { + $ap = Get-SPTrustedIdentityTokenIssuer -Identity $params.AuthenticationProvider + } + else + { + $disableKerberos = ($params.AuthenticationMethod -eq "NTLM") + $ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication ` + -DisableKerberos:$disableKerberos + } + + $newWebAppParams.Add("AuthenticationProvider", $ap) } - - $newWebAppParams.Add("AuthenticationProvider", $ap) } if ($params.ContainsKey("AllowAnonymous") -eq $true) @@ -306,10 +322,9 @@ function Set-TargetResource if ($Ensure -eq "Absent") { Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] $wa = Get-SPWebApplication -Identity $params.Name -ErrorAction SilentlyContinue if ($null -ne $wa) @@ -371,7 +386,7 @@ function Test-TargetResource $UseSSL, [parameter(Mandatory = $false)] - [ValidateSet("NTLM","Kerberos","Claims")] + [ValidateSet("NTLM","Kerberos","Claims","Classic")] [System.String] $AuthenticationMethod, @@ -393,6 +408,13 @@ function Test-TargetResource $PSBoundParameters.Ensure = $Ensure + if ($Ensure -eq "Present" -and + $PSBoundParameters.ContainsKey("AuthenticationMethod") -eq $false) + { + throw [Exception] ("When Ensure is Present, the AuthenticationMethod " + ` + "parameter is required.") + } + $CurrentValues = Get-TargetResource @PSBoundParameters $testReturn = Test-SPDscParameterState -CurrentValues $CurrentValues ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.schema.mof index cbe3ae6bd..0741d7c25 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.schema.mof @@ -6,7 +6,7 @@ class MSFT_SPWebApplication : OMI_BaseResource [Required, Description("The name of the managed account to run the app pool with")] string ApplicationPoolAccount; [Required, Description("The URL of the web application")] string Url; [Write, Description("Should anonymous access be enabled for this web app")] boolean AllowAnonymous; - [Write, Description("What authentication mode should be used for the web app"), ValueMap{"NTLM","Kerberos","Claims"}, Values{"NTLM","Kerberos","Claims"}] string AuthenticationMethod; + [Write, Description("What authentication mode should be used for the web app"), ValueMap{"NTLM","Kerberos","Claims","Classic"}, Values{"NTLM","Kerberos","Claims","Classic"}] string AuthenticationMethod; [Write, Description("What authentication provider should be used for the web app. This value is required when AuthenticationMethod is set to Claims")] string AuthenticationProvider; [Write, Description("The name of the first content database to be created with this web app")] string DatabaseName; [Write, Description("The name of the database server to host the default content DB")] string DatabaseServer; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 index 0cbadba53..48809b2bb 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 @@ -31,18 +31,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } - Mock -CommandName Start-Process -MockWith { return @{ ExitCode = 0 @@ -89,26 +77,96 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) { - return "CLEAN_INSTALL" + 15 { + return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") + } + 16 { + return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.zh-tw" } + } - if ($Value -eq "LanguagePackInstalled") + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) { - return 0 + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Chinese (Taiwan)/中文 (繁體)') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Chinese (Taiwan)/中文 (繁體)') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } } } - + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.pt-br" + } + } + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) { 15 { - return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Portuguese/Português (Brasil)') } 16 { - return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Portuguese/Português (Brasil)') } Default { throw [Exception] "A supported version of SharePoint was not used in testing" @@ -146,18 +204,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } } - - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } Mock -CommandName Get-SPDscRegProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) @@ -211,18 +257,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } } - - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } Mock -CommandName Get-SPDscRegProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) @@ -277,18 +311,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } - Mock -CommandName Get-SPDscRegProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -348,18 +370,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } - Mock -CommandName Get-SPDscRegProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -403,18 +413,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 0 - } - } - Mock -CommandName Get-SPDscRegProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -436,18 +434,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BinaryDir = "C:\SPInstall" Ensure = "Present" } - - Mock -CommandName Get-SPDSCRegistryKey -MockWith { - if ($Value -eq "SetupType") - { - return "CLEAN_INSTALL" - } - - if ($Value -eq "LanguagePackInstalled") - { - return 1 - } - } It "Should return null from the set method" { Set-TargetResource @testParams | Should BeNullOrEmpty diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 index c60b1b2cf..02f5a9482 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 @@ -77,7 +77,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "The web application exists and the properties don't match" -Fixture { $testParams = @{ WebAppUrl = "http://sharepoint.contoso.com" @@ -119,6 +118,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $result } + It "Should return false from the get method" { + Get-TargetResource @testParams | Should Not BeNullOrEmpty + } + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } @@ -129,6 +132,162 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPDscUpdateMailSettingsCalled | Should Be $true } } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Context -Name "UseTLS is using in SharePoint 2013" -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + SMTPServer = "smtp.contoso.com" + FromAddress = "from@email.com" + ReplyToAddress = "reply@email.com" + UseTLS = $true + CharacterSet= "65001" + } + + It "Should throw an exception in the get method" { + { Get-TargetResource @testParams } | Should Throw "UseTLS is only supported in SharePoint 2016." + } + + It "Should throw an exception in the test method" { + { Test-TargetResource @testParams } | Should Throw "UseTLS is only supported in SharePoint 2016." + } + + It "Should throw an exception in the set method" { + { Set-TargetResource @testParams } | Should Throw "UseTLS is only supported in SharePoint 2016." + } + } + + Context -Name "SMTPPort is using in SharePoint 2013" -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + SMTPServer = "smtp.contoso.com" + FromAddress = "from@email.com" + ReplyToAddress = "reply@email.com" + SMTPPort = 25 + CharacterSet= "65001" + } + + It "Should throw an exception in the get method" { + { Get-TargetResource @testParams } | Should Throw "SMTPPort is only supported in SharePoint 2016." + } + + It "Should throw an exception in the test method" { + { Test-TargetResource @testParams } | Should Throw "SMTPPort is only supported in SharePoint 2016." + } + + It "Should throw an exception in the set method" { + { Set-TargetResource @testParams } | Should Throw "SMTPPort is only supported in SharePoint 2016." + } + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Context -Name "The web application exists and the properties match - SharePoint 2016" -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + SMTPServer = "smtp.contoso.com" + FromAddress = "from@email.com" + CharacterSet= "65001" + ReplyToAddress = "reply@email.com" + UseTLS = $false + SMTPPort = 25 + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + Url= "http://sharepoint.contoso.com" + OutboundMailServiceInstance= @{ + Server = @{ + Name = "smtp.contoso.com" + } + } + OutboundMailSenderAddress = "from@email.com" + OutboundMailReplyToAddress= "reply@email.com" + OutboundMailCodePage= "65001" + OutboundMailEnableSsl = $false + OutboundMailPort = 25 + } + } + + It "Should return web app properties from the get method" { + Get-TargetResource @testParams | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web application exists and the properties don't match - SharePoint 2016" -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + SMTPServer = "smtp.contoso.com" + FromAddress = "from@email.com" + ReplyToAddress = "reply@email.com" + CharacterSet= "65001" + UseTLS = $true + SMTPPort = 25 + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $result = @{ + Url= "http://sharepoint.contoso.com" + OutboundMailServiceInstance= @{ + Server = @{ + Name = "smtp.contoso.com" + } + } + OutboundMailSenderAddress = "from@email.com" + OutboundMailReplyToAddress= "reply@email.com" + OutboundMailCodePage= "65001" + OutboundMailEnableSsl = $false + OutboundMailPort = 25 + } + $result = $result | Add-Member -MemberType ScriptMethod ` + -Name UpdateMailSettings ` + -Value { + param( + [string] + $SMTPServer, + + [string] + $FromAddress, + + [string] + $ReplyToAddress, + + [string] + $CharacterSet, + + [bool] + $EnableSsl, + + [string] + $Port + ) + $Global:SPDscUpdateMailSettingsCalled = $true; + } -PassThru + return $result + } + + It "Should return false from the get method" { + (Get-TargetResource @testParams).SMTPPort | Should Be 25 + (Get-TargetResource @testParams).UseTLS | Should Be $false + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the new and set methods from the set function" { + $Global:SPDscUpdateMailSettingsCalled = $false + Set-TargetResource @testParams + $Global:SPDscUpdateMailSettingsCalled | Should Be $true + } + } + } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSubscriptionSettings.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSubscriptionSettings.Tests.ps1 index 9617991d5..93ed6fe59 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSubscriptionSettings.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSubscriptionSettings.Tests.ps1 @@ -112,14 +112,44 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Test_DB" + Server = @{ + Name = "TestServer\Instance" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru } -PassThru -Force + return $spServiceApp } @@ -146,25 +176,49 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { TypeName = "Microsoft SharePoint Foundation Subscription Settings Service Application" DisplayName = $testParams.Name ApplicationPool = @{ Name = "Wrong App Pool Name" } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { $Global:SPDscSubscriptionServiceUpdateCalled = $true } -PassThru - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru - } -PassThru -Force + + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Test_DB" + Server = @{ + Name = "TestServer\Instance" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + return $spServiceApp } @@ -218,13 +272,41 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Test_DB" + Server = @{ + Name = "TestServer\Instance" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru } -PassThru -Force return $spServiceApp } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 index 01d6cb92e..09e1c3772 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 @@ -73,8 +73,23 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Ensure=Present and the parameter AuthenticationMethod is not specified" -Fixture { + $testParams = @{ + Name = "SharePoint Sites" + ApplicationPool = "SharePoint Web Apps" + ApplicationPoolAccount = "DEMO\ServiceAccount" + Url = "http://sites.sharepoint.com" + Ensure = "Present" + } + It "throws exception in the set method" { + { Set-TargetResource @testParams } | Should Throw "When Ensure is Present, the AuthenticationMethod parameter is required." + } + It "throws exception in the test method" { + { Test-TargetResource @testParams } | Should Throw "When Ensure is Present, the AuthenticationMethod parameter is required." + } + } Context -Name "The web application that uses NTLM doesn't exist but should" -Fixture { $testParams = @{ From 1f8c82c28f5e64d7f8ba1fc6640bd4252cdb446b Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 19 May 2017 15:03:04 +0200 Subject: [PATCH 02/18] Implemented new Language Pack detection --- CHANGELOG.md | 1 + .../MSFT_SPDesignerSettings.psm1 | 8 +- .../MSFT_SPInstallLanguagePack.psm1 | 124 ++++++++---------- ...rePointDsc.SPInstallLanguagePack.Tests.ps1 | 45 ++++++- 4 files changed, 98 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ac632fb..557723f30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fixed missing brackets in error message in SPExcelServiceApp (589) * Removed the requirement for the ConfigWizard in SPInstallLanguagePack (594) * Fixed LP detection issue in SPInstallLanguagePack (596) +* Fixed issue with Access Denied in SPDesignerSettings (587) * ISSUE 551 - ADImport rework ## 1.7.0.0 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 index 78bc14fd1..132f7d0c5 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 @@ -120,9 +120,7 @@ function Get-TargetResource } # Check if site collections exists - $site = Get-SPSite | Where-Object -FilterScript { - $_.Url -eq $params.Url - } + $site = Get-SPSite $params.Url -ErrorAction SilentlyContinue if ($null -eq $site) { Write-Verbose -Message ("Site collection not found. SharePoint " + ` @@ -301,9 +299,7 @@ function Set-TargetResource Write-Verbose -Message "Start update SPD site collection settings" # Check if site collection exists - $site = Get-SPSite | Where-Object -FilterScript { - $_.Url -eq $url - } + $site = Get-SPSite $params.Url -ErrorAction SilentlyContinue if ($null -eq $site) { throw ("Site collection not found. SharePoint Designer settings " + ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 index 5dec4aa3e..f5635eec0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 @@ -45,6 +45,37 @@ function Get-TargetResource $products = Get-SPDscRegProductsInfo + $englishProducts = @() + foreach ($product in $products) + { + $parsedProduct = $product -split " - " + switch -Regex ($parsedProduct) + { + "Dari" { $languageEN = "Dari"} + "Serbian" { $languageEN = $parsedProduct[1] } + "Chinese" { + $parsedENProduct = $parsedProduct[1] -split "/" + $languageEN = $parsedENProduct[0] + } + "Portuguese" { + if ($parsedProduct[1] -match "\(Brasil\)") + { + $languageEN = "Portuguese (Brasil)" + } + else + { + $languageEN = "Portuguese (Portugal)" + } + } + Default { + $parsedENProduct = $parsedProduct[1] -split "/" + $parsedENProduct = $parsedENProduct[0] -split " " + $languageEN = $parsedENProduct[0] + } + } + $englishProducts += $languageEN + } + # Extract language from filename if ($osrvFolder.Name -match "\w*.(\w{2,3}-\w*-?\w*)") { @@ -72,84 +103,33 @@ function Get-TargetResource } # Extract English name of the language code - $updateLanguage = "" - if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \([^)]*\)") + $updateLanguage = $cultureInfo.EnglishName + switch ($cultureInfo.EnglishName) { - $languageEnglish = $matches[1] - $updateLanguage = $matches[0] - if ($languageEnglish.contains(",")) - { - $languages = $languageEnglish.Split(",") - $languageEnglish = $languages[0] - } - } - - # Extract Native name of the language code - if ($cultureInfo.NativeName -match "(\w*,*\s*\w*) ?\([^)]*\)") - { - $languageNative = $matches[1] - if ($languageNative.contains(",")) - { - $languages = $languageNative.Split(",") - $languageNative = $languages[0] + "Dari (Afghanistan)" { $languageEnglish = "Dari" } + "Chinese (Simplified, China)" { $languageEnglish = "Chinese (PRC)" } + "Chinese (Traditional, Taiwan)" { $languageEnglish = "Chinese (Taiwan)" } + "Portuguese (Brazil)" { $languageEnglish = "Portuguese (Brasil)" } + "Portuguese (Portugal)" { $languageEnglish = "Portuguese (Portugal)" } + "Serbian (Cyrillic, Serbia)" { $languageEnglish = "Serbian/српски" } + "Serbian (Latin, Serbia)" { $languageEnglish = "Serbian/srpski" } + Default { + if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \([^)]*\)") + { + $languageEnglish = $matches[1] + $updateLanguage = $matches[0] + if ($languageEnglish.contains(",")) + { + $languages = $languageEnglish.Split(",") + $languageEnglish = $languages[0] + } + } } } - - # Build language string used in Language Pack names - $languageString = $("$languageEnglish/$languageNative").Trim() - $languageString2 = $("$languageEnglish $languageNative").Trim() - switch ($updateLanguage) { - "Azerbaijani (Latin, Azerbaijan)" { - $languageString = "Azerbaijani/Azərbaycan­ılı" - $languageString2 = "NO MATCH" - } - "English (United States)" { - $languageString = "English" - $languageString2 = "NO MATCH" - } - "Portuguese (Brazil)" { - $languageString = "Portuguese/Português \(Brasil\)" - $languageString2 = "NO MATCH" - } - "Dari (Afghanistan)" { - $languageString = "درى Dari" - $languageString2 = "NO MATCH" - } - "Latvian (Latvia)" { - $languageString = "Latvian/latviski" - $languageString2 = "NO MATCH" - } - "Malay (Malaysia)" { - $languageString = "Malay/Bahasa Malaysia" - $languageString2 = "NO MATCH" - } - "Vietnamese (Vietnam)" { - $languageString = "Vietnamese/Tiếng Việt" - $languageString2 = "NO MATCH" - } - "Chinese (Simplified, China)" { - $languageString = 'Chinese \(PRC\)/中文\(简体\)' - $languageString2 = "NO MATCH" - } - "Chinese (Traditional, Taiwan)" { - $languageString = 'Chinese \(Taiwan\)/中文 \(繁體\)' - $languageString2 = "NO MATCH" - } - } Write-Verbose -Message "Update is for the $languageEnglish language" - # Find the product name for the specific language pack - $productFound = $false - foreach ($product in $products) - { - if ($product -match $languageString -or $product -match $languageString2) - { - $productFound = $true - } - } - - if ($productFound -eq $true) + if ($englishProducts -contains $languageEnglish -eq $true) { Write-Verbose -Message "Language Pack $languageEnglish is found" return @{ diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 index 48809b2bb..bf700c413 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 @@ -102,7 +102,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + Context -Name "Chinese Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" Ensure = "Present" @@ -143,7 +143,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + Context -Name "Portuguese Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" Ensure = "Present" @@ -184,6 +184,47 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Arabic Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.ar-SA" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Arabic/LOCAL ARABIC') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Arabic/LOCAL ARABIC') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + Context -Name "Language Pack is not installed, installation executed successfully" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" From 17744a1da7d3ac64173716a763e360db3080901d Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 19 May 2017 15:16:38 +0200 Subject: [PATCH 03/18] Last removal of special characters in LP detection --- .../MSFT_SPInstallLanguagePack.psm1 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 index f5635eec0..e0dca300c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 @@ -52,7 +52,16 @@ function Get-TargetResource switch -Regex ($parsedProduct) { "Dari" { $languageEN = "Dari"} - "Serbian" { $languageEN = $parsedProduct[1] } + "Serbian" { + if ($parsedProduct[1] -match "srpski") + { + $languageEN = "Serbian (Latin)" + } + else + { + $languageEN = "Serbian (Cyrillic)" + } + } "Chinese" { $parsedENProduct = $parsedProduct[1] -split "/" $languageEN = $parsedENProduct[0] @@ -111,8 +120,8 @@ function Get-TargetResource "Chinese (Traditional, Taiwan)" { $languageEnglish = "Chinese (Taiwan)" } "Portuguese (Brazil)" { $languageEnglish = "Portuguese (Brasil)" } "Portuguese (Portugal)" { $languageEnglish = "Portuguese (Portugal)" } - "Serbian (Cyrillic, Serbia)" { $languageEnglish = "Serbian/српски" } - "Serbian (Latin, Serbia)" { $languageEnglish = "Serbian/srpski" } + "Serbian (Cyrillic, Serbia)" { $languageEnglish = "Serbian (Cyrillic)" } + "Serbian (Latin, Serbia)" { $languageEnglish = "Serbian (Latin)" } Default { if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \([^)]*\)") { From 1596ac604f1e3694948921b95078705bed688020 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 19 May 2017 15:50:13 +0200 Subject: [PATCH 04/18] Updated changelog --- CHANGELOG.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557723f30..5e672cc69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,15 @@ ## Unreleased -* Updated Readme of SPInstall to include SharePoint Foundation is not supported (580) -* Added TLS and SMTP port support for SharePoint 2016 (540) -* Fixed missing brackets in error message in SPExcelServiceApp (589) -* Removed the requirement for the ConfigWizard in SPInstallLanguagePack (594) -* Fixed LP detection issue in SPInstallLanguagePack (596) -* Fixed issue with Access Denied in SPDesignerSettings (587) -* ISSUE 551 - ADImport rework +* Added TLS and SMTP port support for SharePoint 2016 +* Fixed issue in SPWebApplication where the Get method didn't return Classic + web applications properly +* Fixed issue in SPSubscriptionSettingsServiceApp not returning database values +* Updated Readme of SPInstall to include SharePoint Foundation is not supported +* Fixed issue with Access Denied in SPDesignerSettings +* Fixed missing brackets in error message in SPExcelServiceApp +* Removed the requirement for the ConfigWizard in SPInstallLanguagePack +* Fixed LP detection issue in SPInstallLanguagePack ## 1.7.0.0 @@ -52,9 +54,6 @@ joined to a farm * Bugfix in SPContentDatabase for setting WarningSiteCount as 0. * Fixing verbose message that identifies SP2016 as 2013 in MSFT_SPFarm -* Fixed issue in SPSubscriptionSettingsServiceApp not returning database values -* Fixed issue in SPWebApplication where the Get method didn't return Classic - web applications properly * Fixed SPProductUpdate looking for OSearch15 in SP2016 when stopping services * Added TermStoreAdministrators property to SPManagedMetadataServiceApp * Fixed an issue in SPSearchTopology that would leave a corrupt topology in From 14e15f537890c372642daf6794c25aa0114c1d0f Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Sat, 20 May 2017 20:29:03 +0200 Subject: [PATCH 05/18] Added some additional tests --- .../MSFT_SPExcelServiceApp.psm1 | 6 +- .../SharePointDsc.SPExcelServiceApp.Tests.ps1 | 2 +- ...rePointDsc.SPInstallLanguagePack.Tests.ps1 | 209 +++++++++++++++++- .../SharePointDsc.SPWebApplication.Tests.ps1 | 45 +++- 4 files changed, 255 insertions(+), 7 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 index 06e675b3f..808963c3e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 @@ -123,7 +123,7 @@ function Get-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "service applications via DSC, as SharePoint 2016 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") @@ -314,7 +314,7 @@ function Set-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "service applications via DSC, as SharePoint 2016 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") @@ -572,7 +572,7 @@ function Test-TargetResource if ((Get-SPDSCInstalledProductVersion).FileMajorPart -ne 15) { throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applicaions via DSC, as SharePoint 2016 deprecated " + ` + "service applications via DSC, as SharePoint 2016 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 index cb1236208..e14a12708 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 @@ -148,7 +148,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "When the serivce application doesn't exist and it shouldn't" -Fixture { + Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { $testParams = @{ Name = "Test App" ApplicationPool = "-" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 index bf700c413..c227f8a0e 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 @@ -102,7 +102,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "Chinese Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + Context -Name "Chinese (Taiwan) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" Ensure = "Present" @@ -143,7 +143,171 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "Portuguese Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + Context -Name "Chinese (China) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.zh-cn" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Chinese (PRC)/中文(简体)') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Chinese (PRC)/中文(简体)') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Dari Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.prs-AF" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - درى Dari') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - درى Dari') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Serbian (Latin) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.sr-Latn-RS" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Serbian/srpski') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Serbian/srpski') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Serbian (Cyrillic) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.sr-Cyrl-RS" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Serbian/српски') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Serbian/српски') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Portuguese (Brasil) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" Ensure = "Present" @@ -184,6 +348,47 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Portuguese (Portugal) Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { + $testParams = @{ + BinaryDir = "C:\SPInstall" + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-ChildItem -MockWith { + return @{ + Name = "C:\SPInstall\osmui.pt-pt" + } + } + + Mock -CommandName Get-SPDscRegProductsInfo -MockWith { + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + { + 15 { + return @("Microsoft SharePoint Server 2013", 'Language Pack for SharePoint and Project Server 2013 - Portuguese/Português') + } + 16 { + return @("Microsoft SharePoint Server 2016", 'Language Pack for SharePoint and Project Server 2016 - Portuguese/Português') + } + Default { + throw [Exception] "A supported version of SharePoint was not used in testing" + } + } + } + + It "Should return Ensure is Present from the get method" { + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + Context -Name "Arabic Language Pack (naming not according naming standard) is installed, installation not required" -Fixture { $testParams = @{ BinaryDir = "C:\SPInstall" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 index 09e1c3772..e38a35456 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 @@ -161,7 +161,50 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "The web appliation does exist and should that uses NTLM" -Fixture { + Context -Name "The web application does exist and should that uses Classic" -Fixture { + $testParams = @{ + Name = "SharePoint Sites" + ApplicationPool = "SharePoint Web Apps" + ApplicationPoolAccount = "DEMO\ServiceAccount" + Url = "http://sites.sharepoint.com" + AuthenticationMethod = "Classic" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return $null + } + + Mock -CommandName Get-SPWebapplication -MockWith { return @(@{ + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + Username = $testParams.ApplicationPoolAccount + } + ContentDatabases = @( + @{ + Name = "SP_Content_01" + Server = "sql.domain.local" + } + ) + IisSettings = @( + @{ Path = "C:\inetpub\wwwroot\something" } + ) + Url = $testParams.Url + })} + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + + } + + Context -Name "The web application does exist and should that uses NTLM" -Fixture { $testParams = @{ Name = "SharePoint Sites" ApplicationPool = "SharePoint Web Apps" From 30f542506195f0cef447578a5c729ad75fe4ebb6 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 24 May 2017 10:42:52 +0200 Subject: [PATCH 06/18] Review updates --- CHANGELOG.md | 2 +- .../MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 | 4 ++-- Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md | 3 ++- .../MSFT_SPOutgoingEmailSettings.psm1 | 4 ++-- .../MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e672cc69..27e9377b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ * Fixed issue with Access Denied in SPDesignerSettings * Fixed missing brackets in error message in SPExcelServiceApp * Removed the requirement for the ConfigWizard in SPInstallLanguagePack -* Fixed LP detection issue in SPInstallLanguagePack +* Fixed Language Pack detection issue in SPInstallLanguagePack ## 1.7.0.0 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 index 132f7d0c5..aae291bd3 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 @@ -120,7 +120,7 @@ function Get-TargetResource } # Check if site collections exists - $site = Get-SPSite $params.Url -ErrorAction SilentlyContinue + $site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $site) { Write-Verbose -Message ("Site collection not found. SharePoint " + ` @@ -299,7 +299,7 @@ function Set-TargetResource Write-Verbose -Message "Start update SPD site collection settings" # Check if site collection exists - $site = Get-SPSite $params.Url -ErrorAction SilentlyContinue + $site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $site) { throw ("Site collection not found. SharePoint Designer settings " + ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md index a28caa18e..611940ba3 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md @@ -7,7 +7,8 @@ file and validate the license key during the installation process. This module depends on the prerequisites already being installed, which can be done NOTE: This resource only supports SharePoint Server. SharePoint Foundation -is not supported. +is not supported. For examples to install SharePoint Foundation using DSC, see: +https://github.com/PowerShell/SharePointDsc/wiki/SPInstall (Example 3) ## Installing from network locations diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 index cc417fec0..d4a0fc90f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 @@ -126,13 +126,13 @@ function Set-TargetResource $installedVersion = Get-SPDSCInstalledProductVersion if (($PSBoundParameters.ContainsKey("UseTLS") -eq $true) ` - -and $installedVersion.FileMajorPart -ne 16) + -and $installedVersion.FileMajorPart -lt 16) { throw [Exception] "UseTLS is only supported in SharePoint 2016." } if (($PSBoundParameters.ContainsKey("SMTPPort") -eq $true) ` - -and $installedVersion.FileMajorPart -ne 16) + -and $installedVersion.FileMajorPart -lt 16) { throw [Exception] "SMTPPort is only supported in SharePoint 2016." } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 index 33c15ca1a..372edcc2b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 @@ -246,7 +246,7 @@ function Set-TargetResource # ApplicationPoolAccount parameter to create the application pool try { - $null = Get-SPManagedAccount $params.ApplicationPoolAccount -ErrorAction Stop + Get-SPManagedAccount $params.ApplicationPoolAccount -ErrorAction Stop | Out-Null $newWebAppParams.Add("ApplicationPoolAccount", $params.ApplicationPoolAccount) } catch From 29693abaa159fe9e3c272f8c25244dc003ccc87c Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 24 May 2017 10:45:01 +0200 Subject: [PATCH 07/18] Bugfix --- .../MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 index b7d3e05cb..529ebcd5d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 @@ -50,7 +50,7 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] - $wa = Get-SPWebApplication $params.WebAppUrl -ErrorAction SilentlyContinue + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { @@ -60,7 +60,7 @@ function Get-TargetResource if ($wa.RightsMask -eq [Microsoft.SharePoint.SPBasePermissions]::FullMask) { $returnval = @{ - WebAppUrl = "url" + WebAppUrl = $params.WebAppUrl AllPermissions = $true } } From a072d8dc57417c4afd5ca5062493f6491c3a5fb8 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 24 May 2017 11:10:42 +0200 Subject: [PATCH 08/18] Forgot to save changes --- .../MSFT_SPOutgoingEmailSettings.schema.mof | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof index 6125de66a..8f3c9376f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.schema.mof @@ -6,8 +6,8 @@ class MSFT_SPOutgoingEmailSettings : OMI_BaseResource [Required, Description("The from address to put on messages")] string FromAddress; [Required, Description("The email address that replies should be directed to")] string ReplyToAddress; [Required, Description("The character set to use on messages")] string CharacterSet; - [Write, Description("Use TLS when connecting to the SMTP server")] boolean UseTLS; - [Write, Description("The port which is used to connect to the SMTP server")] uint32 SMTPPort; + [Write, Description("Use TLS when connecting to the SMTP server (SharePoint 2016 only)")] boolean UseTLS; + [Write, Description("The port which is used to connect to the SMTP server (SharePoint 2016 only)")] uint32 SMTPPort; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; From 7e302bc8ee86978560c78560fcac315cab241101 Mon Sep 17 00:00:00 2001 From: Mike Lacher Date: Mon, 5 Jun 2017 09:16:25 -0400 Subject: [PATCH 09/18] updated changelog / updated tests --- CHANGELOG.md | 1 + .../MSFT_SPServiceAppProxyGroup.psm1 | 15 +++++++-------- ...rePointDsc.SPServiceAppProxyGroup.tests.ps1 | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e9377b4..2e8e75601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* Fixed issue in SPServiceAppProxyGroup causing some service names to return as null * Added TLS and SMTP port support for SharePoint 2016 * Fixed issue in SPWebApplication where the Get method didn't return Classic web applications properly diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 index 74e1d1c47..dcf4593f0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 @@ -70,7 +70,7 @@ function Get-TargetResource $Ensure = "Absent" } - $ServiceAppProxies = $ProxyGroup.Proxies.Name + $ServiceAppProxies = $ProxyGroup.Proxies.DisplayName return @{ Name = $params.name @@ -159,13 +159,12 @@ function Set-TargetResource Write-Verbose -Message "Creating new Service Application Proxy Group $($params.Name)" $ProxyGroup = New-SPServiceApplicationProxyGroup -Name $params.Name } - #Explicit Service Applications if ($params.ServiceAppProxies) { - if ($ProxyGroup.Proxies.Name) + if ($ProxyGroup.Proxies.DisplayName) { - $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.Name ` + $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.DisplayName ` -DifferenceObject $params.ServiceAppProxies if ($null -eq $Differences) @@ -234,9 +233,9 @@ function Set-TargetResource if ($params.ServiceAppProxiesToInclude) { - if ($ProxyGroup.Proxies.name) + if ($ProxyGroup.Proxies.DisplayName) { - $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.Name ` + $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.DisplayName ` -DifferenceObject $params.ServiceAppProxiesToInclude if ($null -eq $Differences) @@ -289,9 +288,9 @@ function Set-TargetResource if ($params.ServiceAppProxiesToExclude) { - if ($ProxyGroup.Proxies.name) + if ($ProxyGroup.Proxies.Displayname) { - $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.Name ` + $differences = Compare-Object -ReferenceObject $ProxyGroup.Proxies.DisplayName ` -DifferenceObject $params.ServiceAppProxiesToExclude ` -IncludeEqual diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 index 15015fe5f..fb07732fd 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 @@ -142,7 +142,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in $TestParams.ServiceAppProxies) { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -176,9 +176,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPServiceApplicationProxyGroup -MockWith { $proxiesToReturn = @() foreach ($ServiceAppProxy in $serviceAppProxiesConfigured) - { + { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -221,7 +221,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in $serviceAppProxiesConfigured) { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -257,7 +257,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in $serviceAppProxiesConfigured) { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -297,7 +297,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in $serviceAppProxiesConfigured) { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -332,7 +332,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in $serviceAppProxiesConfigured) { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -370,7 +370,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in "Web 1 User Profile Service Application") { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ @@ -406,7 +406,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { foreach ($ServiceAppProxy in "Web 1 User Profile Service Application") { $proxiesToReturn += @{ - Name = $ServiceAppProxy + DisplayName = $ServiceAppProxy } } return @{ From 16ac366f982283f9ccfed5a8053e4530888cc115 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Fri, 16 Jun 2017 12:39:39 +1000 Subject: [PATCH 10/18] Added support to set windows search service accounts --- CHANGELOG.md | 2 + .../MSFT_SPSearchServiceApp.psm1 | 48 ++++++++++- .../MSFT_SPSearchServiceApp.schema.mof | 1 + ...SharePointDsc.SPSearchServiceApp.Tests.ps1 | 86 +++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e9377b4..3ec43b584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ * Fixed missing brackets in error message in SPExcelServiceApp * Removed the requirement for the ConfigWizard in SPInstallLanguagePack * Fixed Language Pack detection issue in SPInstallLanguagePack +* Added support to set Windows service accounts for search related services to + SPSearchServiceApp resource ## 1.7.0.0 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 index b1b0f17c8..5a33366eb 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 @@ -43,6 +43,10 @@ function Get-TargetResource [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $WindowsServiceAccount, [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] @@ -112,7 +116,12 @@ function Get-TargetResource { $proxyName = $serviceAppProxy.Name } - } + } + + $searchService = Get-SPEnterpriseSearchService + $windowsAccount = New-Object -TypeName System.Management.Automation.PSCredential ` + -ArgumentList @($searchService.ProcessIdentity, $dummyPassword) + $returnVal = @{ Name = $serviceApp.DisplayName ProxyName = $proxyName @@ -123,6 +132,7 @@ function Get-TargetResource SearchCenterUrl = $serviceApp.SearchCenterUrl DefaultContentAccessAccount = $defaultAccount CloudIndex = $cloudIndex + WindowsServiceAccount = $windowsAccount InstallAccount = $params.InstallAccount } return $returnVal @@ -172,6 +182,10 @@ function Set-TargetResource [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $WindowsServiceAccount, [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] @@ -256,6 +270,12 @@ function Set-TargetResource $serviceApp.SearchCenterUrl = $params.SearchCenterUrl $serviceApp.Update() } + + if ($params.ContainsKey("WindowsServiceAccount") -eq $true) + { + Set-SPEnterpriseSearchService -ServiceAccount $WindowsServiceAccount.UserName ` + -ServicePassword $WindowsServiceAccount.Password + } } } } @@ -265,9 +285,10 @@ function Set-TargetResource # Update the service app that already exists Write-Verbose -Message "Updating Search Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $result) ` -ScriptBlock { $params = $args[0] + $result = $args[1] $serviceApp = Get-SPServiceApplication -Name $params.Name | ` Where-Object -FilterScript { @@ -295,6 +316,13 @@ function Set-TargetResource $serviceApp.SearchCenterUrl = $params.SearchCenterUrl $serviceApp.Update() } + + if ($params.ContainsKey("WindowsServiceAccount") -eq $true -and ` + $result.WindowsServiceAccount.UserName -ne $params.WindowsServiceAccount.UserName) + { + Set-SPEnterpriseSearchService -ServiceAccount $params.WindowsServiceAccount.UserName ` + -ServicePassword $params.WindowsServiceAccount.Password + } } } @@ -368,6 +396,10 @@ function Test-TargetResource [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $WindowsServiceAccount, [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] @@ -386,6 +418,18 @@ function Test-TargetResource if ($DefaultContentAccessAccount.UserName ` -ne $CurrentValues.DefaultContentAccessAccount.UserName) { + Write-Verbose -Message "Default content access account is different, returning false" + return $false + } + } + + if ($PSBoundParameters.ContainsKey("WindowsServiceAccount") ` + -and $Ensure -eq "Present") + { + if ($WindowsServiceAccount.UserName ` + -ne $CurrentValues.WindowsServiceAccount.UserName) + { + Write-Verbose -Message "Windows service account is different, returning false" return $false } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.schema.mof index f10eb47e7..e187966a6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.schema.mof @@ -10,6 +10,7 @@ class MSFT_SPSearchServiceApp : OMI_BaseResource [Write, Description("The default content access account for this search service app"), EmbeddedInstance("MSFT_Credential")] String DefaultContentAccessAccount; [Write, Description("Should this search service application be a cloud based service app")] boolean CloudIndex; [Write, Description("Present if the service app should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("Sets the windows services for search to run as this account"), EmbeddedInstance("MSFT_Credential")] string WindowsServiceAccount; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 index 5068249fe..002b03d78 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 @@ -43,6 +43,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Set-SPEnterpriseSearchServiceApplication -MockWith {} Mock -CommandName New-SPBusinessDataCatalogServiceApplication -MockWith { } Mock -CommandName Set-SPEnterpriseSearchServiceApplication -MockWith { } + Mock -CommandName Set-SPEnterpriseSearchService -MockWith {} Mock -CommandName Get-SPEnterpriseSearchServiceInstance -MockWith { return @{} @@ -62,6 +63,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.Search.Administration.Content" } + Mock -CommandName Get-SPEnterpriseSearchService -MockWith { + return @{ + ProcessIdentity = "DOMAIN\username" + } + } Mock Import-Module -MockWith {} -ParameterFilter { $_.Name -eq $ModuleName } @@ -71,6 +77,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Name = "Search Service Application" ApplicationPool = "SharePoint Search Services" Ensure = "Present" + WindowsServiceAccount = $mockCredential } Mock -CommandName Get-SPServiceApplication -MockWith { @@ -525,6 +532,85 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { Set-TargetResource @testParams } | Should Throw } } + + Context "A service app exists that has a correct windows service account in use" -Fixture { + $testParams = @{ + Name = "Search Service Application" + ApplicationPool = "SharePoint Search Services" + Ensure = "Present" + WindowsServiceAccount = $mockCredential + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Search Service Application" + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = $getTypeFullName } + } -PassThru -Force + return $spServiceApp + } + + it "Should return the current value in the get method" { + (Get-TargetResource @testParams).WindowsServiceAccount | Should Not BeNullOrEmpty + } + + it "Should return true in the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context "A service app exists that has an incorrect windows service account in use" -Fixture { + $testParams = @{ + Name = "Search Service Application" + ApplicationPool = "SharePoint Search Services" + Ensure = "Present" + WindowsServiceAccount = $mockCredential + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Search Service Application" + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = $getTypeFullName } + } -PassThru -Force + return $spServiceApp + } + + Mock -CommandName Get-SPEnterpriseSearchService -MockWith { + return @{ + ProcessIdentity = "WrongUserName" + } + } + + it "Should return the current value in the get method" { + (Get-TargetResource @testParams).WindowsServiceAccount | Should Not BeNullOrEmpty + } + + it "Should return false in the test method" { + Test-TargetResource @testParams | Should Be $false + } + + it "Should update the account in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled -CommandName "Set-SPEnterpriseSearchService" + } + } + } } From eb72c0aa1706b71d77bbcf0f9ef74fb8ed578a18 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 16 Jun 2017 13:59:58 +0200 Subject: [PATCH 11/18] Implemented several bugfixes --- CHANGELOG.md | 9 ++++ .../MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 | 9 +++- .../MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 | 9 +++- .../MSFT_SPProductUpdate.psm1 | 2 +- .../MSFT_SPQuotaTemplate.psm1 | 8 ++-- .../MSFT_SPRemoteFarmTrust.psm1 | 2 + .../MSFT_SPSessionStateService.psm1 | 4 +- .../MSFT_SPUserProfileProperty.psm1 | 2 +- .../MSFT_SPWebAppSiteUseAndDeletion.psm1 | 46 +++++++++++++++++-- .../SharePointDsc.Util.psm1 | 2 +- .../SPWebAppPolicy.psm1 | 8 ++-- .../SPWebApplication.GeneralSettings.psm1 | 11 ++++- 12 files changed, 92 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e9377b4..ef940a846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,15 @@ * Fixed missing brackets in error message in SPExcelServiceApp * Removed the requirement for the ConfigWizard in SPInstallLanguagePack * Fixed Language Pack detection issue in SPInstallLanguagePack +* Fixed issue in SPCreateFarm and SPJoinFarm where an exception was not handled + correctly (issue 621) +* Fixed issue in SPSessionStateService not returning correct database server + and name (issue 618) +* Fixed missing Ensure property default in SPRemoteFarmTrust (issue 614) +* Fixed issue in SPWebAppGeneralSettings where -1 was returned for the TimeZone (issue 610) +* Fixed incorrect UsagePoint check in SPQuotaTemplate (issue 605) +* Fixed issue in SPWebAppPolicy module where verbose messages are causing errors (issue 602) +* Fixed incorrect parameter naming in Get method of SPUserProfilePropery (issue 611) ## 1.7.0.0 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 index f200ef86b..6e9d9470c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 @@ -82,7 +82,14 @@ function Get-TargetResource $getSPMajorVersion = (Get-SPDSCInstalledProductVersion).FileMajorPart $cfgDbRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\$getSPMajorVersion.0\Secure\ConfigDB" - $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + try + { + $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + } + catch + { + Write-Verbose -Message "SharePoint registry key cannot be found." + } $serverIsJoined = $true if ($null -eq $configDbDsn) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 index 3dd0db88d..75ce0fdab 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 @@ -65,7 +65,14 @@ function Get-TargetResource $getSPMajorVersion = (Get-SPDSCInstalledProductVersion).FileMajorPart $cfgDbRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\$getSPMajorVersion.0\Secure\ConfigDB" - $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + try + { + $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + } + catch + { + Write-Verbose -Message "SharePoint registry key cannot be found." + } $serverIsJoined = $true if ($null -eq $configDbDsn) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index 223542d47..e604cec79 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -338,7 +338,7 @@ function Set-TargetResource $osearchStopped = $false $hostControllerStopped = $false - if ((Get-SPDSCInstalledProductVersion) -eq 15) + if ((Get-SPDSCInstalledProductVersion).FileMajorPart -eq 15) { $searchServiceName = "OSearch15" } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 index 43f04e54f..fe5cd3bde 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 @@ -43,7 +43,8 @@ function Get-TargetResource if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { - Throw "MaximumUsagePointsSolutions must be larger than WarningUsagePointsSolutions." + Throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` + "WarningUsagePointsSolutions.") } $result = Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -144,7 +145,8 @@ function Set-TargetResource if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { - Throw "MaximumUsagePointsSolutions must be larger than WarningUsagePointsSolutions." + Throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` + "WarningUsagePointsSolutions.") } switch ($Ensure) @@ -304,7 +306,7 @@ function Test-TargetResource Throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." } - if ($MaximumUsagePointsSolutions -le $WarningUsagePointsSolutions) + if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { Throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` "WarningUsagePointsSolutions.") diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/MSFT_SPRemoteFarmTrust.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/MSFT_SPRemoteFarmTrust.psm1 index 9b0be7ce8..0cacee9fd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/MSFT_SPRemoteFarmTrust.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/MSFT_SPRemoteFarmTrust.psm1 @@ -203,6 +203,8 @@ function Test-TargetResource() Write-Verbose -Message "Testing remote farm trust '$Name'" + $PSBoundParameters.Ensure = $Ensure + $CurrentValues = Get-TargetResource @PSBoundParameters return Test-SPDscParameterState -CurrentValues $CurrentValues ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/MSFT_SPSessionStateService.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/MSFT_SPSessionStateService.psm1 index e139a48bb..e426a6334 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/MSFT_SPSessionStateService.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/MSFT_SPSessionStateService.psm1 @@ -40,8 +40,8 @@ function Get-TargetResource $Ensure = "Present" } return @{ - DatabaseName = $svc.DatabaseId - DatabaseServer = $svc.DatabaseServer + DatabaseName = $svc.CatalogName + DatabaseServer = $svc.ServerName Ensure = $Ensure SessionTimeout = $svc.Timeout.TotalMinutes } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 index a5a5abcc1..1c2bab932 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 @@ -196,7 +196,7 @@ function Get-TargetResource return @{ Name = $userProfileProperty.Name - UserProfileServiceAppName = $params.UserProfileService + UserProfileService = $params.UserProfileService DisplayName = $userProfileProperty.DisplayName Type = $userProfileProperty.CoreProperty.Type Description = $userProfileProperty.Description diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 index 83bf936c2..99e1b3cf0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 @@ -21,7 +21,7 @@ function Get-TargetResource $AutomaticallyDeleteUnusedSiteCollections, [parameter(Mandatory = $false)] - [ValidateRange(28,168)] + [ValidateRange(2,168)] [System.UInt32] $UnusedSiteNotificationsBeforeDeletion, @@ -91,7 +91,7 @@ function Set-TargetResource $AutomaticallyDeleteUnusedSiteCollections, [parameter(Mandatory = $false)] - [ValidateRange(28,168)] + [ValidateRange(2,168)] [System.UInt32] $UnusedSiteNotificationsBeforeDeletion, @@ -115,16 +115,52 @@ function Set-TargetResource { throw ("No local SharePoint farm was detected. Site Use and Deletion settings " + ` "will not be applied") - return } $wa = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $wa) { throw "Configured web application could not be found" - return } + # Check if the specified value is in the range for the configured schedule + $job = Get-SPTimerJob -Identity job-dead-site-delete -WebApplication $params.Url + if ($null -eq $job) + { + throw "Dead Site Delete timer job for web application $($params.Url) could not be found" + } + else + { + # Check schedule value + switch ($job.Schedule.Description) + { + "Daily" { + if (($params.UnusedSiteNotificationsBeforeDeletion -lt 28) -or + ($params.UnusedSiteNotificationsBeforeDeletion -gt 168)) + { + throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >28 and " + ` + "<168 when the schedule is set to daily") + } + } + "Weekly" { + if (($params.UnusedSiteNotificationsBeforeDeletion -lt 4) -or + ($params.UnusedSiteNotificationsBeforeDeletion -gt 24)) + { + throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >24 and " + ` + "<24 when the schedule is set to weekly") + } + } + "Monthly" { + if (($params.UnusedSiteNotificationsBeforeDeletion -lt 2) -or + ($params.UnusedSiteNotificationsBeforeDeletion -gt 6)) + { + throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >2 and " + ` + "<6 when the schedule is set to monthly") + } + } + } + } + Write-Verbose -Message "Start update" # Set the Site Use and Deletion settings @@ -175,7 +211,7 @@ function Test-TargetResource $AutomaticallyDeleteUnusedSiteCollections, [parameter(Mandatory = $false)] - [ValidateRange(28,168)] + [ValidateRange(2,168)] [System.UInt32] $UnusedSiteNotificationsBeforeDeletion, diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 index 72791a48e..dc796e2d9 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 @@ -86,7 +86,7 @@ function Get-SPDscFarmVersionInfo ($patchableUnit -notmatch "OMUI") -and ($patchableUnit -notmatch "XMUI") -and ($patchableUnit -notmatch "Project Server") -and - ($patchableUnit -notmatch "Microsoft SharePoint Server 2013")) + ($patchableUnit -notmatch "Microsoft SharePoint Server (2013|2016)")) { $patchableUnitsInfo = $singleProductInfo.GetPatchableUnitInfoByDisplayName($patchableUnit) $currentVersion = "" diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 index 3543fd010..3cc63ae9b 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 @@ -82,8 +82,8 @@ function Compare-SPDSCWebAppPolicy() { if ($policy.ActAsSystemAccount -ne $setting.ActAsSystemAccount) { - Write-Verbose -Message "System User different for " + ` - "$($policy.IdentityType) user '$($policy.Username)'" + Write-Verbose -Message ("System User different for " + ` + "$($policy.IdentityType) user '$($policy.Username)'") if (-not (Assert-SPDSCPolicyUser -CurrentDifferences $diff ` -UsernameToCheck $policy.Username.ToLower())) @@ -156,8 +156,8 @@ function Compare-SPDSCWebAppPolicy() { if ($policy.ActAsSystemAccount -ne $setting.ActAsSystemAccount) { - Write-Verbose -Message "System User different for " + ` - "$($policy.IdentityType) user '$($policy.Username)'" + Write-Verbose -Message ("System User different for " + ` + "$($policy.IdentityType) user '$($policy.Username)'") if (-not (Assert-SPDSCPolicyUser -CurrentDifferences $diff ` -UsernameToCheck $policy.Username.ToLower())) diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 index ba617c18b..a6e26f479 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 @@ -7,8 +7,17 @@ function Get-SPDSCWebApplicationGeneralConfig $WebApplication ) + if ($WebApplication.DefaultTimeZone -eq -1) + { + $timezone = $null + } + else + { + $timezone = $WebApplication.DefaultTimeZone + } + return @{ - TimeZone = $WebApplication.DefaultTimeZone + TimeZone = $timezone Alerts = $WebApplication.AlertsEnabled AlertsLimit = $WebApplication.AlertsMaximum RSS = $WebApplication.SyndicationEnabled From abe4e6524c5057473c18f7b16f21a3d533ab96f2 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 29 Jun 2017 09:06:52 +0200 Subject: [PATCH 12/18] Changes ready for testing --- .../MSFT_SPBlobCacheSettings.schema.mof | 2 +- .../MSFT_SPProductUpdate.psm1 | 18 +++ .../MSFT_SPProductUpdate/readme.md | 9 +- .../MSFT_SPUserProfileProperty.psm1 | 2 +- .../MSFT_SPUserProfileServiceApp.psm1 | 51 +++++-- .../MSFT_SPUserProfileServiceApp.schema.mof | 1 + ...SFT_SPUserProfileSyncConnection.schema.mof | 2 +- .../SharePointDsc.SPProductUpdate.Tests.ps1 | 28 ++++ ...PointDsc.SPUserProfileServiceApp.Tests.ps1 | 126 +++++++++++++++++- 9 files changed, 225 insertions(+), 14 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.schema.mof index 6d2238168..81ac90cf5 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.schema.mof @@ -2,7 +2,7 @@ class MSFT_SPBlobCacheSettings : OMI_BaseResource { [Key, Description("The URL of the web application")] string WebAppUrl; - [Required, Description("The zone of the web application for which blob cache has to be configured"), ValueMap{"Default","Intranet","Internet","Custom","Extranet"}, Values{"Default","Intranet","Internet","Custom","Extranet"}] string Zone; + [Key, Description("The zone of the web application for which blob cache has to be configured"), ValueMap{"Default","Intranet","Internet","Custom","Extranet"}, Values{"Default","Intranet","Internet","Custom","Extranet"}] string Zone; [Required, Description("Specify if the blob cache has to be enabled")] Boolean EnableCache; [Write, Description("The location where the blob cache has to store its files")] string Location; [Write, Description("The maximum size (in GB) of disk space the blob cache is allowed to use")] Uint16 MaxSizeInGB; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index e604cec79..850934dfb 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -49,6 +49,15 @@ function Get-TargetResource throw "Setup file cannot be found." } + Write-Verbose -Message "Checking file status of $SetupFile" + $zone = Get-Item $SetupFile -Stream "Zone.Identifier" -EA SilentlyContinue + + if ($null -ne $zone) + { + throw ("Setup file is blocked! Please use Unblock-File to unblock the file " + ` + "before continuing.") + } + $setupFileInfo = Get-ItemProperty $SetupFile $fileVersion = $setupFileInfo.VersionInfo.FileVersion Write-Verbose -Message "Update has version $fileVersion" @@ -236,6 +245,15 @@ function Set-TargetResource throw "Setup file cannot be found." } + Write-Verbose -Message "Checking file status of $SetupFile" + $zone = Get-Item $SetupFile -Stream "Zone.Identifier" -EA SilentlyContinue + + if ($null -ne $zone) + { + throw ("Setup file is blocked! Please use Unblock-File to unblock the file " + ` + "before continuing.") + } + $now = Get-Date if ($BinaryInstallDays) { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md index fad618590..56e3ded85 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md @@ -10,6 +10,13 @@ the update can be installed. This module requires the Configuration Wizard resource to fully complete the installation of the update, which can be done through the use of SPConfigWizard. +NOTE: +When files are downloaded from the Internet, a Zone.Identifier alternate data +stream is added to indicate that the file is potentially from an unsafe source. +To use these files, make sure you first unblock them using Unblock-File: +https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/unblock-file +SPProductUpdate will throw an error when it detects the file is blocked. + IMPORTANT: This resource retrieves build information from the Configuration Database. Therefore it requires SharePoint to be installed and a farm created. If you @@ -19,6 +26,6 @@ implement the following order: 1. Install the SharePoint Binaries (SPInstall) 2. (Optional) Install SharePoint Language Pack(s) Binaries (SPInstallLanguagePack) -3. Create SPFarm (SPCreateFarm) +3. Create SPFarm (SPFarm) 4. Install Cumulative Updates (SPProductUpdate) 5. Run the Configuration Wizard (SPConfigWizard) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 index 1c2bab932..a70b222f5 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 @@ -176,7 +176,7 @@ function Get-TargetResource -ArgumentList $context $syncConnection = $userProfileConfigManager.ConnectionManager | ` Where-Object -FilterScript { - $null -ne $_.PropertyMapping.Item($params.Name) + $null -ne $_.PropertyMapping -and $null -ne $_.PropertyMapping.Item($params.Name) } if($null -ne $syncConnection) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index 057381434..70d7f4f27 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -52,6 +52,10 @@ function Get-TargetResource [System.Boolean] $EnableNetBIOS = $false, + [parameter(Mandatory = $false)] + [System.Boolean] + $NoILMUsed = $false, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -144,6 +148,7 @@ function Get-TargetResource SyncDBServer = $databases.SynchronizationDatabase.Server.Name InstallAccount = $params.InstallAccount EnableNetBIOS = $serviceApp.NetBIOSDomainNamesEnabled + NoILMUsed = $serviceApp.NoILMUsed Ensure = "Present" } } @@ -204,6 +209,10 @@ function Set-TargetResource [System.Boolean] $EnableNetBIOS = $false, + [parameter(Mandatory = $false)] + [System.Boolean] + $NoILMUsed = $false, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -240,13 +249,22 @@ function Set-TargetResource -ScriptBlock { $params = $args[0] - $enableNetBIOS = $false + $updateEnableNetBIOS = $false if ($params.ContainsKey("EnableNetBIOS")) - { - $enableNetBIOS =$params.EnableNetBIOS + { + $updateEnableNetBIOS = $true + $enableNetBIOS = $params.EnableNetBIOS $params.Remove("EnableNetBIOS") | Out-Null } + $updateNoILMUsed = $false + if ($params.ContainsKey("NoILMUsed")) + { + $updateNoILMUsed = $true + $NoILMUsed = $params.NoILMUsed + $params.Remove("NoILMUsed") | Out-Null + } + if ($params.ContainsKey("InstallAccount")) { $params.Remove("InstallAccount") | Out-Null @@ -277,7 +295,7 @@ function Set-TargetResource $serviceApps = Get-SPServiceApplication -Name $params.Name ` -ErrorAction SilentlyContinue - $app =$serviceApps | Select-Object -First 1 + $app = $serviceApps | Select-Object -First 1 if ($null -eq $serviceApps) { $app = New-SPProfileServiceApplication @params @@ -289,13 +307,21 @@ function Set-TargetResource } } - if ($app.NetBIOSDomainNamesEnabled -ne $enableNetBIOS) + if (($updateEnableNetBIOS -eq $true) -or ($updateNoILMUsed -eq $true)) { - $app.NetBIOSDomainNamesEnabled = $enableNetBIOS + if (($updateEnableNetBIOS -eq $true) -and ` + ($app.NetBIOSDomainNamesEnabled -ne $enableNetBIOS)) + { + $app.NetBIOSDomainNamesEnabled = $enableNetBIOS + } + + if (($updateNoILMUsed -eq $true) -and ` + ($app.NoILMUsed -ne $NoILMUsed)) + { + $app.NoILMUsed = $NoILMUsed + } $app.Update() } - - } # Remove the FarmAccount from the local Administrators group, if it was added above @@ -387,6 +413,10 @@ function Test-TargetResource [System.Boolean] $EnableNetBIOS = $false, + [parameter(Mandatory = $false)] + [System.Boolean] + $NoILMUsed = $false, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -407,7 +437,10 @@ function Test-TargetResource { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Name","EnableNetBIOS", "Ensure") + -ValuesToCheck @("Name", + "EnableNetBIOS", + "NoILMUsed", + "Ensure") } else { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.schema.mof index 6406a45d8..5c320b893 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.schema.mof @@ -13,6 +13,7 @@ class MSFT_SPUserProfileServiceApp : OMI_BaseResource [Write, Description("The name of the sync database")] string SyncDBName; [Write, Description("The name of the database server to host the sync database")] string SyncDBServer; [Write, Description("Whether Farm should resolve NetBIOS domain names")] boolean EnableNetBIOS; + [Write, Description("Specifies if the service application should be configured to use AD Import")] boolean NoILMUsed; [Write, Description("Present if the service app should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.schema.mof index 45e345f60..be9b5ec5f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.schema.mof @@ -5,7 +5,7 @@ class MSFT_SPUserProfileSyncConnection : OMI_BaseResource [Required, Description("The name of the AD forest to read from")] string Forest; [Required, Description("The name of the user profile service that this connection is attached to")] string UserProfileService; [Required, Description("The credentials to connect to Active Directory with"), EmbeddedInstance("MSFT_Credential")] string ConnectionCredentials; - [Required, Description("A listo f the OUs to import users from")] string IncludedOUs[]; + [Required, Description("A list of the OUs to import users from")] string IncludedOUs[]; [Write, Description("A list of the OUs to ignore users from")] string ExcludedOUs[]; [Write, Description("The specific AD server to connect to")] string Server; [Write, Description("Should SSL be used for the connection")] boolean UseSSL; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 index 7c966a3d9..5f6f97fe4 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 @@ -98,6 +98,34 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Specified update file is blocked" -Fixture { + $testParams = @{ + SetupFile = "C:\Install\CUMay2016\ubersrv2013-kb3115029-fullfile-x64-glb.exe" + ShutdownServices = $true + Ensure = "Present" + } + + Mock -CommandName Test-Path -MockWith { + return $true + } + + Mock -CommandName Get-Item -MockWith { + return "Zone data" + } + + It "Should throw exception in the get method" { + { Get-TargetResource @testParams } | Should Throw "Setup file is blocked! Please use Unblock-File to unblock the file" + } + + It "Should throw exception in the set method" { + { Set-TargetResource @testParams } | Should Throw "Setup file is blocked! Please use Unblock-File to unblock the file" + } + + It "Should throw exception in the test method" { + { Test-TargetResource @testParams } | Should Throw "Setup file is blocked! Please use Unblock-File to unblock the file" + } + } + Context -Name "Ensure is set to Absent" -Fixture { $testParams = @{ SetupFile = "C:\Install\CUMay2016\ubersrv2013-kb3115029-fullfile-x64-glb.exe" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 index 5099d8ffa..4ec9fa830 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 @@ -35,7 +35,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName New-SPProfileServiceApplication -MockWith { return (@{ - NetBIOSDomainNamesEnabled = $false} + NetBIOSDomainNamesEnabled = $false + NoILMUsed = $false + } ) } Mock -CommandName New-SPProfileServiceApplicationProxy -MockWith { } @@ -224,6 +226,128 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "When service applications exist in the current farm and NoILMUsed isn't enabled but it needs to be" -Fixture { + $testParams = @{ + Name = "User Profile Service App" + ApplicationPool = "SharePoint Service Applications" + NoILMUsed = $true + FarmAccount = $mockCredential + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @( + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name TypeName ` + -Value "User Profile Service Application" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name DisplayName ` + -Value $testParams.Name ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name "NoILMUsed" ` + -Value $false ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + $Global:SPDscUPSAUpdateCalled = $true + } -PassThru | + Add-Member -MemberType NoteProperty ` + -Name ApplicationPool ` + -Value @{ + Name = $testParams.ApplicationPool + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SocialDatabase" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return @{ + Name = "SP_SocialDB" + Server = @{ + Name = "SQL.domain.local" + } + } + } -PassThru + ), + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "ProfileDatabase" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + return @{ + Name = "SP_ProfileDB" + Server = @{ + Name = "SQL.domain.local" + } + } + } -PassThru + ), + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SynchronizationDatabase" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + return @{ + Name = "SP_ProfileSyncDB" + Server = @{ + Name = "SQL.domain.local" + } + } + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + ) + } + + It "Should return false from the Get method" { + (Get-TargetResource @testParams).NoILMUsed | Should Be $false + } + + It "Should call Update method on Service Application before finishing set method" { + $Global:SPDscUPSAUpdateCalled = $false + Set-TargetResource @testParams + $Global:SPDscUPSAUpdateCalled | Should Be $true + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should return true when the Test method is called" { + $testParams.NoILMUsed = $false + Test-TargetResource @testParams | Should Be $true + } + } + Context -Name "When a service application exists and is configured correctly" -Fixture { $testParams = @{ Name = "User Profile Service App" From 26ebd7f1c99833b2b43a96ed6486dcc618389150 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 29 Jun 2017 09:07:08 +0200 Subject: [PATCH 13/18] Missed Changelog during commit --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef940a846..37accf081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,14 @@ * Fixed issue in SPWebAppGeneralSettings where -1 was returned for the TimeZone (issue 610) * Fixed incorrect UsagePoint check in SPQuotaTemplate (issue 605) * Fixed issue in SPWebAppPolicy module where verbose messages are causing errors (issue 602) -* Fixed incorrect parameter naming in Get method of SPUserProfilePropery (issue 611) +* Fixed incorrect parameter naming in Get method of SPUserProfilePropery (issue 611) +* Fixed issue in SPBlobCacheSettings when trying to declare same URL with + different zone (issue 609) +* Improve documentation on SPProductUpdate to specify the need to unblock downloaded + files (issue 464) +* Added check if file is blocked in SPProductUpdate to prevent endless wait (issue 464) +* Enhance SPUserProfileServiceApp to allow for NoILM to be enabled (issue 622) +* Fixed issue in SPUserProfileProperty where PropertyMapping was Null (issue 613) ## 1.7.0.0 From 72cd9343aa8c04f5f96b83f4ae1753811a113a0a Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 29 Jun 2017 22:37:05 +0200 Subject: [PATCH 14/18] Updated changelog --- CHANGELOG.md | 24 ++++++------ .../SPUserProfileServiceApp/2-NoILMUsed.ps1 | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPUserProfileServiceApp/2-NoILMUsed.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 54cadb523..5b7f3297f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,21 +15,21 @@ * Added support to set Windows service accounts for search related services to SPSearchServiceApp resource * Fixed issue in SPCreateFarm and SPJoinFarm where an exception was not handled - correctly (issue 621) + correctly * Fixed issue in SPSessionStateService not returning correct database server - and name (issue 618) -* Fixed missing Ensure property default in SPRemoteFarmTrust (issue 614) -* Fixed issue in SPWebAppGeneralSettings where -1 was returned for the TimeZone (issue 610) -* Fixed incorrect UsagePoint check in SPQuotaTemplate (issue 605) -* Fixed issue in SPWebAppPolicy module where verbose messages are causing errors (issue 602) -* Fixed incorrect parameter naming in Get method of SPUserProfilePropery (issue 611) + and name +* Fixed missing Ensure property default in SPRemoteFarmTrust +* Fixed issue in SPWebAppGeneralSettings where -1 was returned for the TimeZone +* Fixed incorrect UsagePoint check in SPQuotaTemplate +* Fixed issue in SPWebAppPolicy module where verbose messages are causing errors +* Fixed incorrect parameter naming in Get method of SPUserProfilePropery * Fixed issue in SPBlobCacheSettings when trying to declare same URL with - different zone (issue 609) + different zone * Improve documentation on SPProductUpdate to specify the need to unblock downloaded - files (issue 464) -* Added check if file is blocked in SPProductUpdate to prevent endless wait (issue 464) -* Enhance SPUserProfileServiceApp to allow for NoILM to be enabled (issue 622) -* Fixed issue in SPUserProfileProperty where PropertyMapping was Null (issue 613) + files +* Added check if file is blocked in SPProductUpdate to prevent endless wait +* Enhance SPUserProfileServiceApp to allow for NoILM to be enabled +* Fixed issue in SPUserProfileProperty where PropertyMapping was Null ## 1.7.0.0 diff --git a/Modules/SharePointDsc/Examples/Resources/SPUserProfileServiceApp/2-NoILMUsed.ps1 b/Modules/SharePointDsc/Examples/Resources/SPUserProfileServiceApp/2-NoILMUsed.ps1 new file mode 100644 index 000000000..3f6396f70 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPUserProfileServiceApp/2-NoILMUsed.ps1 @@ -0,0 +1,37 @@ +<# +.EXAMPLE + This example adds a new user profile service application to the local farm +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount, + + [Parameter(Mandatory = $true)] + [PSCredential] + $FarmAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPUserProfileServiceApp UserProfileServiceApp + { + Name = "User Profile Service Application" + ApplicationPool = "SharePoint Service Applications" + MySiteHostLocation = "http://my.sharepoint.contoso.local" + ProfileDBName = "SP_UserProfiles" + ProfileDBServer = "SQL.contoso.local\SQLINSTANCE" + SocialDBName = "SP_Social" + SocialDBServer = "SQL.contoso.local\SQLINSTANCE" + SyncDBName = "SP_ProfileSync" + SyncDBServer = "SQL.contoso.local\SQLINSTANCE" + EnableNetBIOS = $false + NoILMUsed = $true + FarmAccount = $FarmAccount + PsDscRunAsCredential = $SetupAccount + } + } + } From e14172bd9dd3eaee1d86408fc0d93f8ca18b0594 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 30 Jun 2017 11:47:43 +0200 Subject: [PATCH 15/18] Updated tests and incorporated review comments --- .../MSFT_SPProductUpdate.psm1 | 4 +- .../MSFT_SPProductUpdate/readme.md | 3 +- .../MSFT_SPQuotaTemplate.psm1 | 6 +- .../MSFT_SPWebAppSiteUseAndDeletion.psm1 | 2 +- .../SharePointDsc.SPQuotaTemplate.Tests.ps1 | 81 +++++++++++++++++++ ...ntDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 | 69 ++++++++++++++++ 6 files changed, 157 insertions(+), 8 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index 850934dfb..ba57f5d6e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -50,7 +50,7 @@ function Get-TargetResource } Write-Verbose -Message "Checking file status of $SetupFile" - $zone = Get-Item $SetupFile -Stream "Zone.Identifier" -EA SilentlyContinue + $zone = Get-Item -Path $SetupFile -Stream "Zone.Identifier" -EA SilentlyContinue if ($null -ne $zone) { @@ -58,7 +58,7 @@ function Get-TargetResource "before continuing.") } - $setupFileInfo = Get-ItemProperty $SetupFile + $setupFileInfo = Get-ItemProperty -Path $SetupFile $fileVersion = $setupFileInfo.VersionInfo.FileVersion Write-Verbose -Message "Update has version $fileVersion" diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md index 56e3ded85..63eb93240 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/readme.md @@ -13,8 +13,7 @@ through the use of SPConfigWizard. NOTE: When files are downloaded from the Internet, a Zone.Identifier alternate data stream is added to indicate that the file is potentially from an unsafe source. -To use these files, make sure you first unblock them using Unblock-File: -https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/unblock-file +To use these files, make sure you first unblock them using Unblock-File. SPProductUpdate will throw an error when it detects the file is blocked. IMPORTANT: diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 index fe5cd3bde..124e29dae 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 @@ -38,7 +38,7 @@ function Get-TargetResource if ($StorageMaxInMB -lt $StorageWarningInMB) { - Throw "StorageMaxInMB must be larger than StorageWarningInMB." + Throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." } if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) @@ -140,7 +140,7 @@ function Set-TargetResource if ($StorageMaxInMB -lt $StorageWarningInMB) { - Throw "StorageMaxInMB must be larger than StorageWarningInMB." + Throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." } if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) @@ -301,7 +301,7 @@ function Test-TargetResource Write-Verbose -Message "Testing Quota Template settings for quota $Name" - if ($StorageMaxInMB -le $StorageWarningInMB) + if ($StorageMaxInMB -lt $StorageWarningInMB) { Throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 index 99e1b3cf0..3269748d2 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 @@ -146,7 +146,7 @@ function Set-TargetResource if (($params.UnusedSiteNotificationsBeforeDeletion -lt 4) -or ($params.UnusedSiteNotificationsBeforeDeletion -gt 24)) { - throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >24 and " + ` + throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >4 and " + ` "<24 when the schedule is set to weekly") } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 index 17f6f9451..015b65e27 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 @@ -39,6 +39,87 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } # Test contexts + Context -Name "WarningUsagePointsSolutions is lower than MaximumUsagePointsSolutions" -Fixture { + $testParams = @{ + Name = "Test" + StorageMaxInMB = 1024 + StorageWarningInMB = 512 + MaximumUsagePointsSolutions = 1000 + WarningUsagePointsSolutions = 1800 + Ensure = "Present" + } + + Mock -CommandName Get-SPFarm -MockWith { + throw "Unable to detect local farm" + } + + It "Should throw an exception in the get method to say MaxPoints need to be larger than WarningPoints" { + { Get-TargetResource @testParams } | Should throw "MaximumUsagePointsSolutions must be equal to or larger than" + } + + It "Should throw an exception in the test method to say MaxPoints need to be larger than WarningPoints" { + { Test-TargetResource @testParams } | Should throw "MaximumUsagePointsSolutions must be equal to or larger than" + } + + It "Should throw an exception in the set method to say MaxPoints need to be larger than WarningPoints" { + { Set-TargetResource @testParams } | Should throw "MaximumUsagePointsSolutions must be equal to or larger than" + } + } + + Context -Name "StorageWarningInMB is lower than StorageMaxInMB" -Fixture { + $testParams = @{ + Name = "Test" + StorageMaxInMB = 1024 + StorageWarningInMB = 1512 + MaximumUsagePointsSolutions = 1000 + WarningUsagePointsSolutions = 800 + Ensure = "Present" + } + + Mock -CommandName Get-SPFarm -MockWith { + throw "Unable to detect local farm" + } + + It "Should throw an exception in the get method to say StorageMax need to be larger than StorageWarning" { + { Get-TargetResource @testParams } | Should throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + } + + It "Should throw an exception in the test method to say StorageMax need to be larger than StorageWarning" { + { Test-TargetResource @testParams } | Should throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + } + + It "Should throw an exception in the set method to say StorageMax need to be larger than StorageWarning" { + { Set-TargetResource @testParams } | Should throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + } + } + + Context -Name "Using Max or Warning parameters with Ensure=Absent" -Fixture { + $testParams = @{ + Name = "Test" + StorageMaxInMB = 1024 + StorageWarningInMB = 512 + MaximumUsagePointsSolutions = 1000 + WarningUsagePointsSolutions = 800 + Ensure = "Absent" + } + + Mock -CommandName Get-SPFarm -MockWith { + throw "Unable to detect local farm" + } + + It "Should return Ensure=Absent" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should throw an exception in the test method to say Max and Warning parameters should not be used" { + { Test-TargetResource @testParams } | Should throw "Do not use StorageMaxInMB, StorageWarningInMB" + } + + It "Should throw an exception in the set method to say Max and Warning parameters should not be used" { + { Set-TargetResource @testParams } | Should throw "Do not use StorageMaxInMB, StorageWarningInMB" + } + } + Context -Name "The server is not part of SharePoint farm" -Fixture { $testParams = @{ Name = "Test" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 index 94c9472d6..14abab6f1 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 @@ -73,6 +73,68 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "UnusedSiteNotificationsBeforeDeletion is out of range" -Fixture { + $testParams = @{ + Url = "http://example.contoso.local" + SendUnusedSiteCollectionNotifications = $true + UnusedSiteNotificationPeriod = 90 + AutomaticallyDeleteUnusedSiteCollections = $true + UnusedSiteNotificationsBeforeDeletion = 24 + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $returnVal = @{ + SendUnusedSiteCollectionNotifications = $false + UnusedSiteNotificationPeriod = @{ TotalDays = 45; } + AutomaticallyDeleteUnusedSiteCollections = $false + UnusedSiteNotificationsBeforeDeletion = 28 + } + $returnVal = $returnVal | Add-Member -MemberType ScriptMethod -Name Update -Value { $Global:SPDscSiteUseUpdated = $true } -PassThru + return $returnVal + } + + Mock -CommandName Get-SPFarm -MockWith { return @{} } + + It "Should throw an exception - Daily schedule" { + Mock -CommandName Get-SPTimerJob -MockWith { + return @{ + Schedule = @{ + Description = "Daily" + } + } + } + $testParams.UnusedSiteNotificationsBeforeDeletion = 24 + + { Set-TargetResource @testParams } | Should throw "Value of UnusedSiteNotificationsBeforeDeletion has to be >28 and" + } + + It "Should throw an exception - Weekly schedule" { + Mock -CommandName Get-SPTimerJob -MockWith { + return @{ + Schedule = @{ + Description = "Weekly" + } + } + } + $testParams.UnusedSiteNotificationsBeforeDeletion = 28 + + { Set-TargetResource @testParams } | Should throw "Value of UnusedSiteNotificationsBeforeDeletion has to be >4 and" + } + + It "Should throw an exception - Weekly schedule" { + Mock -CommandName Get-SPTimerJob -MockWith { + return @{ + Schedule = @{ + Description = "Monthly" + } + } + } + $testParams.UnusedSiteNotificationsBeforeDeletion = 12 + + { Set-TargetResource @testParams } | Should throw "Value of UnusedSiteNotificationsBeforeDeletion has to be >2 and" + } + } + Context -Name "The server is in a farm and the incorrect settings have been applied" -Fixture { $testParams = @{ Url = "http://example.contoso.local" @@ -94,6 +156,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPFarm -MockWith { return @{} } + Mock -CommandName Get-SPTimerJob -MockWith { + return @{ + Schedule = @{ + Description = "Daily" + } + } + } It "Should return values from the get method" { Get-TargetResource @testParams | Should Not BeNullOrEmpty From 34cfbbbbbcbdd6114e062e60e07d5f0b767cc94e Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 30 Jun 2017 18:51:48 +0200 Subject: [PATCH 16/18] Added some tests to increase overall code coverage --- .../MSFT_SPWorkManagementServiceApp.psm1 | 116 +++++++++--------- .../SharePointDsc.SPShellAdmins.Tests.ps1 | 26 ++++ .../SharePointDsc.SPWebAppPolicy.Tests.ps1 | 16 +++ ...ntDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 | 27 ++++ ...ntDsc.SPWorkManagementServiceApp.Tests.ps1 | 35 +++++- 5 files changed, 155 insertions(+), 65 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 index c1b988f05..c4685082a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 @@ -162,7 +162,7 @@ function Set-TargetResource Write-Verbose -Message "Setting Work management service app '$Name'" $PSBoundParameters.Ensure = $Ensure - if ($Ensure -ne "Absent" -and $null -eq $ApplicationPool) + if ($Ensure -ne "Absent" -and $PSBoundParameters.ContainsKey("ApplicationPool") -eq $false) { throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" } @@ -222,68 +222,66 @@ function Set-TargetResource Set-SPWorkManagementServiceApplication -Identity $serviceApp -ApplicationPool $appPool } } - else - { - Write-Verbose -Message "Updating Application Pool of Work Management Service Application $Name" - Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { - $params = $args[0] - - $setParams = @{} - if ($params.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) - { - $setParams.Add("MinimumTimeBetweenEwsSyncSubscriptionSearches", - $params.MinimumTimeBetweenEwsSyncSubscriptionSearches) - } - if ($params.ContainsKey("MinimumTimeBetweenProviderRefreshes")) - { - $setParams.Add("MinimumTimeBetweenProviderRefreshes", - $params.MinimumTimeBetweenProviderRefreshes) - } - if ($params.ContainsKey("MinimumTimeBetweenSearchQueries")) - { - $setParams.Add("MinimumTimeBetweenSearchQueries", - $params.MinimumTimeBetweenSearchQueries) - } - if ($params.ContainsKey("NumberOfSubscriptionSyncsPerEwsSyncRun")) - { - $setParams.Add("NumberOfSubscriptionSyncsPerEwsSyncRun", - $params.NumberOfSubscriptionSyncsPerEwsSyncRun) - } - if ($params.ContainsKey("NumberOfUsersEwsSyncWillProcessAtOnce")) - { - $setParams.Add("NumberOfUsersEwsSyncWillProcessAtOnce", - $params.NumberOfUsersEwsSyncWillProcessAtOnce) - } - if ($params.ContainsKey("NumberOfUsersPerEwsSyncBatch")) - { - $setParams.Add("NumberOfUsersPerEwsSyncBatch", - $params.NumberOfUsersPerEwsSyncBatch) - } - $setParams.Add("Name", $params.Name) - $setParams.Add("ApplicationPool", $params.ApplicationPool) + Write-Verbose -Message "Updating Application Pool of Work Management Service Application $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $setParams = @{} + if ($params.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) + { + $setParams.Add("MinimumTimeBetweenEwsSyncSubscriptionSearches", + $params.MinimumTimeBetweenEwsSyncSubscriptionSearches) + } + if ($params.ContainsKey("MinimumTimeBetweenProviderRefreshes")) + { + $setParams.Add("MinimumTimeBetweenProviderRefreshes", + $params.MinimumTimeBetweenProviderRefreshes) + } + if ($params.ContainsKey("MinimumTimeBetweenSearchQueries")) + { + $setParams.Add("MinimumTimeBetweenSearchQueries", + $params.MinimumTimeBetweenSearchQueries) + } + if ($params.ContainsKey("NumberOfSubscriptionSyncsPerEwsSyncRun")) + { + $setParams.Add("NumberOfSubscriptionSyncsPerEwsSyncRun", + $params.NumberOfSubscriptionSyncsPerEwsSyncRun) + } + if ($params.ContainsKey("NumberOfUsersEwsSyncWillProcessAtOnce")) + { + $setParams.Add("NumberOfUsersEwsSyncWillProcessAtOnce", + $params.NumberOfUsersEwsSyncWillProcessAtOnce) + } + if ($params.ContainsKey("NumberOfUsersPerEwsSyncBatch")) + { + $setParams.Add("NumberOfUsersPerEwsSyncBatch", + $params.NumberOfUsersPerEwsSyncBatch) + } - if ($setParams.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) - { - $setParams.MinimumTimeBetweenEwsSyncSubscriptionSearches = New-TimeSpan -Days $setParams.MinimumTimeBetweenEwsSyncSubscriptionSearches - } - if ($setParams.ContainsKey("MinimumTimeBetweenProviderRefreshes")) - { - $setParams.MinimumTimeBetweenProviderRefreshes = New-TimeSpan -Days $setParams.MinimumTimeBetweenProviderRefreshes - } - if ($setParams.ContainsKey("MinimumTimeBetweenSearchQueries")) - { - $setParams.MinimumTimeBetweenSearchQueries = New-TimeSpan -Days $setParams.MinimumTimeBetweenSearchQueries - } - $setParams.Add("Confirm", $false) - $appService = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" - } + $setParams.Add("Name", $params.Name) + $setParams.Add("ApplicationPool", $params.ApplicationPool) - $appService | Set-SPWorkManagementServiceApplication @setPArams | Out-Null + if ($setParams.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) + { + $setParams.MinimumTimeBetweenEwsSyncSubscriptionSearches = New-TimeSpan -Days $setParams.MinimumTimeBetweenEwsSyncSubscriptionSearches } + if ($setParams.ContainsKey("MinimumTimeBetweenProviderRefreshes")) + { + $setParams.MinimumTimeBetweenProviderRefreshes = New-TimeSpan -Days $setParams.MinimumTimeBetweenProviderRefreshes + } + if ($setParams.ContainsKey("MinimumTimeBetweenSearchQueries")) + { + $setParams.MinimumTimeBetweenSearchQueries = New-TimeSpan -Days $setParams.MinimumTimeBetweenSearchQueries + } + $setParams.Add("Confirm", $false) + $appService = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" + } + + $appService | Set-SPWorkManagementServiceApplication @setPArams | Out-Null } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 index 216e62157..4885ceb42 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 @@ -46,6 +46,32 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "ContentDatabases and AllContentDatabases parameters used simultaniously" -Fixture { + $testParams = @{ + Name = "ShellAdmins" + Members = "contoso\user1", "contoso\user2" + ContentDatabases = @( + (New-CimInstance -ClassName MSFT_SPContentDatabasePermissions -Property @{ + Name = "SharePoint_Content_Contoso1" + Members = "contoso\user1", "contoso\user2" + } -ClientOnly) + ) + AllContentDatabases = $true + } + + It "Should return null from the get method" { + Get-TargetResource @testParams | Should BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an exception in the set method" { + { Set-TargetResource @testParams } | Should throw "Cannot use the ContentDatabases parameter together with the AllContentDatabases parameter" + } + } + Context -Name "Members and MembersToInclude parameters used simultaniously - General permissions" -Fixture { $testParams = @{ Name = "ShellAdmins" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 index ba2a9d8bb..0486ba3cb 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 @@ -190,6 +190,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -264,6 +265,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -338,6 +340,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -408,6 +411,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -566,6 +570,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Claims" ActAsSystemAccount = $false } -ClientOnly) ) @@ -654,6 +659,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\sp_psr" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -745,11 +751,13 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user2" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -818,6 +826,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Claims" ActAsSystemAccount = $false } -ClientOnly) ) @@ -882,11 +891,13 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user2" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -955,6 +966,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Read" + IdentityType = "Claims" ActAsSystemAccount = $false } -ClientOnly) ) @@ -1072,6 +1084,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -1143,6 +1156,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $false } -ClientOnly) ) @@ -1214,6 +1228,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $true } -ClientOnly) ) @@ -1285,6 +1300,7 @@ namespace Microsoft.SharePoint.Administration { (New-CimInstance -ClassName MSFT_SPWebAppPolicy -Property @{ Username = "contoso\user1" PermissionLevel = "Full Control" + IdentityType = "Native" ActAsSystemAccount = $true } -ClientOnly) ) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 index 14abab6f1..254fd4b05 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 @@ -135,6 +135,33 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "The Dead Site Delete timer job does not exist" -Fixture { + $testParams = @{ + Url = "http://example.contoso.local" + SendUnusedSiteCollectionNotifications = $true + UnusedSiteNotificationPeriod = 90 + AutomaticallyDeleteUnusedSiteCollections = $true + UnusedSiteNotificationsBeforeDeletion = 30 + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $returnVal = @{ + SendUnusedSiteCollectionNotifications = $false + UnusedSiteNotificationPeriod = @{ TotalDays = 45; } + AutomaticallyDeleteUnusedSiteCollections = $false + UnusedSiteNotificationsBeforeDeletion = 28 + } + return $returnVal + } + + Mock -CommandName Get-SPFarm -MockWith { return @{} } + Mock -CommandName Get-SPTimerJob -MockWith { return $null } + + It "Should update the Site Use and Deletion settings" { + { Set-TargetResource @testParams } | Should throw "Dead Site Delete timer job for web application" + } + } + Context -Name "The server is in a farm and the incorrect settings have been applied" -Fixture { $testParams = @{ Url = "http://example.contoso.local" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 index eebc7e958..c22de82a2 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 @@ -54,10 +54,24 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "When Ensure=Present and ApplicationPool parameter is missing" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication { return $null } + + It "Should throw an exception in the set method" { + { Set-TargetResource @testParams } | Should throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" + } + } + Context -Name "When no service applications exist in the current farm" -Fixture { $testParams = @{ Name = "Test Work Management App" ApplicationPool = "Test App Pool" + ProxyName = "Test Work Management App Proxy" } Mock -CommandName Get-SPServiceApplication { return $null } @@ -99,6 +113,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } + + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPWorkManagementServiceApplication + } } Context -Name "When a service application exists and is configured correctly" -Fixture { @@ -145,12 +164,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $testParams = @{ Name = "Test Work Management App" ApplicationPool = "Test App Pool" - MinimumTimeBetweenEwsSyncSubscriptionSearches =10 - MinimumTimeBetweenProviderRefreshes=10 - MinimumTimeBetweenSearchQueries=10 - NumberOfSubscriptionSyncsPerEwsSyncRun=10 - NumberOfUsersEwsSyncWillProcessAtOnce=10 - NumberOfUsersPerEwsSyncBatch=10 + MinimumTimeBetweenEwsSyncSubscriptionSearches =20 + MinimumTimeBetweenProviderRefreshes=20 + MinimumTimeBetweenSearchQueries=20 + NumberOfSubscriptionSyncsPerEwsSyncRun=20 + NumberOfUsersEwsSyncWillProcessAtOnce=20 + NumberOfUsersPerEwsSyncBatch=20 } Mock -CommandName Get-SPServiceApplication { @@ -173,6 +192,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Set-SPWorkManagementServiceApplication { } + It "Should return values from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } From bbeeb08209162ff615692ba7664e4179ef509900 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Mon, 3 Jul 2017 10:54:31 +1000 Subject: [PATCH 17/18] Preparing to release v1.8 --- CHANGELOG.md | 4 ++-- Modules/SharePointDsc/SharePointDsc.psd1 | 2 +- appveyor.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b7f3297f..ddd72c3bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change log for SharePointDsc -## Unreleased +## 1.8 * Fixed issue in SPServiceAppProxyGroup causing some service names to return as null * Added TLS and SMTP port support for SharePoint 2016 @@ -31,7 +31,7 @@ * Enhance SPUserProfileServiceApp to allow for NoILM to be enabled * Fixed issue in SPUserProfileProperty where PropertyMapping was Null -## 1.7.0.0 +## 1.7 * Update SPSearchIndexPartition made ServiceAppName as a Key * New resouce: SPTrustedRootAuthority diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index 7d50d0f94..09cae0c9a 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.7.0.0' +ModuleVersion = '1.8.0.0' # ID used to uniquely identify this module GUID = '6c1176a0-4fac-4134-8ca2-3fa8a21a7b90' diff --git a/appveyor.yml b/appveyor.yml index 57558be0b..0705763f5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.7.0.{build} +version: 1.8.0.{build} image: WMF 5 install: From 4f5387f2d98c0e78b01856ae7c9681e68bd64b51 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Mon, 3 Jul 2017 11:38:10 +1000 Subject: [PATCH 18/18] Version 1.8 release --- Modules/SharePointDsc/SharePointDsc.psd1 | 74 +++++++------------ .../en-us/about_SPBlobCacheSettings.help.txt | 2 +- .../en-us/about_SPInstall.help.txt | 4 + .../about_SPOutgoingEmailSettings.help.txt | 8 ++ .../en-us/about_SPProductUpdate.help.txt | 8 +- .../en-us/about_SPSearchServiceApp.help.txt | 4 + .../about_SPUserProfileServiceApp.help.txt | 42 +++++++++++ ...about_SPUserProfileSyncConnection.help.txt | 2 +- .../en-us/about_SPWebApplication.help.txt | 2 +- 9 files changed, 96 insertions(+), 50 deletions(-) diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index ed0cd8ae4..4bcfa6465 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -126,52 +126,34 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = " -* Update SPSearchIndexPartition made ServiceAppName as a Key -* New resouce: SPTrustedRootAuthority -* Update SPFarmSolution to eject from loop after 30m. -* New resource: SPMachineTranslationServiceApp -* New resource: SPPowerPointAutomationServiceApp -* Bugfix in SPSearchFileType made ServiceAppName a key property. -* New resource: SPWebApplicationExtension -* Added new resource SPAccessServices2010 -* Added MSFT_SPSearchCrawlMapping Resource to manage Crawl Mappings for - Search Service Application -* Added new resource SPSearchAuthoritativePage -* Bugfix in SPWebAppThrottlingSettings for setting large list window time. -* Fix typo in method Get-TargetResource of SPFeature -* Fix bug in SPManagedAccount not returning the correct account name value -* Fix typo in method Get-TargetResource of SPSearchIndexPartition -* Update documentation of SPInstallLanguagePack to add guidance on package - change in SP2016 -* Added returning the required RunCentralAdmin parameter to - Get-TargetResource in SPFarm -* Added web role check for SPBlobCacheSettings -* Improved error message when rule could not be found in - SPHealthAnalyzerRuleState -* Extended the documentation to specify that the default value of Ensure - is Present -* Added documentation about the user of Host Header Site Collections and - the HostHeader parameter in SPWebApplication -* Fixed missing brackets in SPWebAppPolicy module file -* Fixed issue with SPSecureStoreServiceApp not returning database information -* Fixed issue with SPManagedMetadataServiceApp not returning ContentTypeHubUrl - in SP2016 -* Updated SPTrustedIdentityTokenIssuer to allow to specify the signing - certificate from file path as an alternative to the certificate store -* New resource: SPSearchCrawlerImpactRule -* Fixed issue in SPSite where the used template wasn't returned properly -* Fixed issue in SPWebApplicationGeneralSettings which didn't return the - security validation timeout properly -* Fixed bug in SPCreateFarm and SPJoinFarm when a SharePoint Server is already - joined to a farm -* Bugfix in SPContentDatabase for setting WarningSiteCount as 0. -* Fixing verbose message that identifies SP2016 as 2013 in MSFT_SPFarm -* Fixed SPProductUpdate looking for OSearch15 in SP2016 when stopping services -* Added TermStoreAdministrators property to SPManagedMetadataServiceApp -* Fixed an issue in SPSearchTopology that would leave a corrupt topology in - place if a server was removed and re-added to a farm -* Fixed bug in SPFarm that caused issues with database names that have dashes - in the names +* Fixed issue in SPServiceAppProxyGroup causing some service names to return as null +* Added TLS and SMTP port support for SharePoint 2016 +* Fixed issue in SPWebApplication where the Get method didn't return Classic + web applications properly +* Fixed issue in SPSubscriptionSettingsServiceApp not returning database values +* Updated Readme of SPInstall to include SharePoint Foundation is not supported +* Fixed issue with Access Denied in SPDesignerSettings +* Fixed missing brackets in error message in SPExcelServiceApp +* Removed the requirement for the ConfigWizard in SPInstallLanguagePack +* Fixed Language Pack detection issue in SPInstallLanguagePack +* Added support to set Windows service accounts for search related services to + SPSearchServiceApp resource +* Fixed issue in SPCreateFarm and SPJoinFarm where an exception was not handled + correctly +* Fixed issue in SPSessionStateService not returning correct database server + and name +* Fixed missing Ensure property default in SPRemoteFarmTrust +* Fixed issue in SPWebAppGeneralSettings where -1 was returned for the TimeZone +* Fixed incorrect UsagePoint check in SPQuotaTemplate +* Fixed issue in SPWebAppPolicy module where verbose messages are causing errors +* Fixed incorrect parameter naming in Get method of SPUserProfilePropery +* Fixed issue in SPBlobCacheSettings when trying to declare same URL with + different zone +* Improve documentation on SPProductUpdate to specify the need to unblock downloaded + files +* Added check if file is blocked in SPProductUpdate to prevent endless wait +* Enhance SPUserProfileServiceApp to allow for NoILM to be enabled +* Fixed issue in SPUserProfileProperty where PropertyMapping was Null " } # End of PSData hashtable diff --git a/Modules/SharePointDsc/en-us/about_SPBlobCacheSettings.help.txt b/Modules/SharePointDsc/en-us/about_SPBlobCacheSettings.help.txt index f1bf121a8..bc524e718 100644 --- a/Modules/SharePointDsc/en-us/about_SPBlobCacheSettings.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPBlobCacheSettings.help.txt @@ -27,7 +27,7 @@ The URL of the web application .PARAMETER Zone - Required - string + Key - string Allowed values: Default, Intranet, Internet, Custom, Extranet The zone of the web application for which blob cache has to be configured diff --git a/Modules/SharePointDsc/en-us/about_SPInstall.help.txt b/Modules/SharePointDsc/en-us/about_SPInstall.help.txt index 827c7b957..937fce5d5 100644 --- a/Modules/SharePointDsc/en-us/about_SPInstall.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPInstall.help.txt @@ -9,6 +9,10 @@ file and validate the license key during the installation process. This module depends on the prerequisites already being installed, which can be done + NOTE: This resource only supports SharePoint Server. SharePoint Foundation + is not supported. For examples to install SharePoint Foundation using DSC, see: + https://github.com/PowerShell/SharePointDsc/wiki/SPInstall (Example 3) + ## Installing from network locations If you wish to install SharePoint from a network location this can diff --git a/Modules/SharePointDsc/en-us/about_SPOutgoingEmailSettings.help.txt b/Modules/SharePointDsc/en-us/about_SPOutgoingEmailSettings.help.txt index 5fb27d486..b09350b20 100644 --- a/Modules/SharePointDsc/en-us/about_SPOutgoingEmailSettings.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPOutgoingEmailSettings.help.txt @@ -30,6 +30,14 @@ Required - string The character set to use on messages +.PARAMETER UseTLS + Write - boolean + Use TLS when connecting to the SMTP server (SharePoint 2016 only) + +.PARAMETER SMTPPort + Write - uint32 + The port which is used to connect to the SMTP server (SharePoint 2016 only) + .PARAMETER InstallAccount Write - String POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 diff --git a/Modules/SharePointDsc/en-us/about_SPProductUpdate.help.txt b/Modules/SharePointDsc/en-us/about_SPProductUpdate.help.txt index d478fe6ff..907f29fdc 100644 --- a/Modules/SharePointDsc/en-us/about_SPProductUpdate.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPProductUpdate.help.txt @@ -13,6 +13,12 @@ resource to fully complete the installation of the update, which can be done through the use of SPConfigWizard. + NOTE: + When files are downloaded from the Internet, a Zone.Identifier alternate data + stream is added to indicate that the file is potentially from an unsafe source. + To use these files, make sure you first unblock them using Unblock-File. + SPProductUpdate will throw an error when it detects the file is blocked. + IMPORTANT: This resource retrieves build information from the Configuration Database. Therefore it requires SharePoint to be installed and a farm created. If you @@ -22,7 +28,7 @@ 1. Install the SharePoint Binaries (SPInstall) 2. (Optional) Install SharePoint Language Pack(s) Binaries (SPInstallLanguagePack) - 3. Create SPFarm (SPCreateFarm) + 3. Create SPFarm (SPFarm) 4. Install Cumulative Updates (SPProductUpdate) 5. Run the Configuration Wizard (SPConfigWizard) diff --git a/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt index fe9cf0f94..d2e2bf507 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt @@ -51,6 +51,10 @@ Allowed values: Present, Absent Present if the service app should exist, absent if it should not +.PARAMETER WindowsServiceAccount + Write - string + Sets the windows services for search to run as this account + .PARAMETER InstallAccount Write - String POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt index d112b75f9..4aa51ed58 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt @@ -62,6 +62,10 @@ Write - boolean Whether Farm should resolve NetBIOS domain names +.PARAMETER NoILMUsed + Write - boolean + Specifies if the service application should be configured to use AD Import + .PARAMETER Ensure Write - string Allowed values: Present, Absent @@ -109,3 +113,41 @@ } +.EXAMPLE + This example adds a new user profile service application to the local farm + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount, + + [Parameter(Mandatory = $true)] + [PSCredential] + $FarmAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPUserProfileServiceApp UserProfileServiceApp + { + Name = "User Profile Service Application" + ApplicationPool = "SharePoint Service Applications" + MySiteHostLocation = "http://my.sharepoint.contoso.local" + ProfileDBName = "SP_UserProfiles" + ProfileDBServer = "SQL.contoso.local\SQLINSTANCE" + SocialDBName = "SP_Social" + SocialDBServer = "SQL.contoso.local\SQLINSTANCE" + SyncDBName = "SP_ProfileSync" + SyncDBServer = "SQL.contoso.local\SQLINSTANCE" + EnableNetBIOS = $false + NoILMUsed = $true + FarmAccount = $FarmAccount + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileSyncConnection.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileSyncConnection.help.txt index 277f902fd..8b4409e0a 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileSyncConnection.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileSyncConnection.help.txt @@ -26,7 +26,7 @@ .PARAMETER IncludedOUs Required - string - A listo f the OUs to import users from + A list of the OUs to import users from .PARAMETER ExcludedOUs Write - string diff --git a/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt b/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt index a37cb4587..42d76ab7f 100644 --- a/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt @@ -40,7 +40,7 @@ .PARAMETER AuthenticationMethod Write - string - Allowed values: NTLM, Kerberos, Claims + Allowed values: NTLM, Kerberos, Claims, Classic What authentication mode should be used for the web app .PARAMETER AuthenticationProvider