diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 000000000..84f3eaaa3 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,44 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +limitPerRun: 30 + +pulls: + daysUntilStale: 14 + daysUntilClose: false + exemptProjects: true + exemptMilestones: true + staleLabel: abandoned + exemptLabels: + - needs review + - on hold + - waiting for CLA pass + + markComment: > + Labeling this pull request (PR) as abandoned since it has gone 14 days or more + since the last update. An abandoned PR can be continued by another contributor. + The abandoned label will be removed if work on this PR is taken up again. + +issues: + daysUntilStale: 30 + daysUntilClose: 40 + exemptProjects: true + exemptMilestones: true + staleLabel: stale + exemptLabels: + - bug + - enhancement + - tests + - documentation + - resource proposal + - on hold + + markComment: > + This issue has been automatically marked as stale because + it has not had activity from the community in the last 30 days. It will be + closed if no further activity occurs within 10 days. If the issue is labelled + with any of the work labels (e.g bug, enhancement, documentation, or tests) + then the issue will not auto-close. + + closeComment: > + This issue has been automatically closed because it is has not had activity + from the community in the last 40 days. diff --git a/CHANGELOG.md b/CHANGELOG.md index b48cc121b..b9bd40ed0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,44 @@ # Change log for SharePointDsc +## 2.4 + +* SPCacheAccounts + * Fixed issue where the Test method would fail if SetWebAppPolicy was set to + false. +* SPDistributedCacheService + * Updated resource to allow updating the cache size +* SPFarm + * Implemented ability to deploy Central Administration site to a server at a + later point in time +* SPInfoPathFormsServiceConfig + * Fixed issue with trying to set the MaxSizeOfUserFormState parameter +* SPProductUpdate + * Fixed an issue where the resource failed when the search was already paused +* SPProjectServerLicense + * Fixed issue with incorrect detection of the license +* SPSearchContentSource + * Fixed issue where the Get method returned a conversion error when the content + source contained just one address + * Fixed issue 840 where the parameter StartHour was never taken into account +* SPSearchServiceApp + * Fixed issue where the service account was not set correctly when the service + application was first created + * Fixed issue where the Get method throws an error when the service app wasn't + created properly +* SPSearchTopology + * Fixed issue where Get method threw an error when the specified service + application didn't exist yet. +* SPServiceAppSecurity + * Fixed issue where error was thrown when no permissions were set on the + service application +* SPShellAdmins + * Updated documentation to specify required permissions for successfully using + this resource +* SPTrustedIdentityTokenIssuerProviderRealms + * Fixed code styling issues +* SPUserProfileServiceApp + * Fixed code styling issues + ## 2.3 * Changes to SharePointDsc diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 index aedba1616..03d6809b6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 @@ -19,7 +19,7 @@ function Get-TargetResource [Parameter()] [System.Boolean] $SetWebAppPolicy = $true, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -29,7 +29,7 @@ function Get-TargetResource $result = Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] - + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) @@ -42,12 +42,12 @@ function Get-TargetResource InstallAccount = $params.InstallAccount } } - + $returnVal = @{ InstallAccount = $params.InstallAccount WebAppUrl = $params.WebAppUrl } - + $policiesSet = $true if ($wa.UseClaimsAuthentication -eq $true) { @@ -92,12 +92,12 @@ function Get-TargetResource { $policiesSet = $false } - + if ($wa.Policies.UserName -notcontains ((New-SPClaimsPrincipal -Identity $params.SuperUserAlias ` -IdentityType WindowsSamAccountName).ToEncodedString())) { $policiesSet = $false - } + } } else { @@ -109,7 +109,7 @@ function Get-TargetResource { $returnVal.Add("SuperUserAlias", "") } - + if ($wa.Properties.ContainsKey("portalsuperreaderaccount")) { $returnVal.Add("SuperReaderAlias", $wa.Properties["portalsuperreaderaccount"]) @@ -118,19 +118,19 @@ function Get-TargetResource { $returnVal.Add("SuperReaderAlias", "") } - + if ($wa.Policies.UserName -notcontains $params.SuperReaderAlias) { $policiesSet = $false } - + if ($wa.Policies.UserName -notcontains $params.SuperUserAlias) { $policiesSet = $false } } $returnVal.Add("SetWebAppPolicy", $policiesSet) - + return $returnVal } return $result @@ -157,15 +157,15 @@ function Set-TargetResource [Parameter()] [System.Boolean] $SetWebAppPolicy = $true, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting cache accounts for $WebAppUrl" - + $PSBoundParameters.SetWebAppPolicy = $SetWebAppPolicy - + Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] @@ -174,7 +174,7 @@ function Set-TargetResource { throw [Exception] "The web applications $($params.WebAppUrl) can not be found to set cache accounts" } - + if ($wa.UseClaimsAuthentication -eq $true) { $wa.Properties["portalsuperuseraccount"] = (New-SPClaimsPrincipal -Identity $params.SuperUserAlias ` @@ -187,7 +187,7 @@ function Set-TargetResource $wa.Properties["portalsuperuseraccount"] = $params.SuperUserAlias $wa.Properties["portalsuperreaderaccount"] = $params.SuperReaderAlias } - + if ($params.SetWebAppPolicy -eq $true) { if ($wa.UseClaimsAuthentication -eq $true) @@ -201,7 +201,7 @@ function Set-TargetResource $policy = $wa.Policies.Add($claimsReader, "Super Reader (Claims)") $policyRole = $wa.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead) $policy.PolicyRoleBindings.Add($policyRole) - + $claimsSuper = (New-SPClaimsPrincipal -Identity $params.SuperUserAlias ` -IdentityType WindowsSamAccountName).ToEncodedString() if ($wa.Policies.UserName -contains $claimsSuper) @@ -222,7 +222,7 @@ function Set-TargetResource $readPolicy = $wa.Policies.Add($params.SuperReaderAlias, "Super Reader") $readPolicyRole = $wa.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead) $readPolicy.PolicyRoleBindings.Add($readPolicyRole) - + if ($wa.Policies.UserName -contains $params.SuperUserAlias) { $wa.Policies.Remove($params.SuperUserAlias) @@ -232,7 +232,7 @@ function Set-TargetResource $policy.PolicyRoleBindings.Add($policyRole) } } - + $wa.Update() } } @@ -259,7 +259,7 @@ function Test-TargetResource [Parameter()] [System.Boolean] $SetWebAppPolicy = $true, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount ) @@ -270,11 +270,21 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("SuperUserAlias", ` - "SuperReaderAlias", ` - "SetWebAppPolicy") + if ($SetWebAppPolicy -eq $true) + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("SuperUserAlias", ` + "SuperReaderAlias", ` + "SetWebAppPolicy") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("SuperUserAlias", ` + "SuperReaderAlias") + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 index e88c85681..6883d6d6d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 @@ -204,7 +204,7 @@ function Set-TargetResource $_.Status -eq "Online" } - While (($count -lt $maxCount) -and ($null -eq $serviceCheck)) + while (($count -lt $maxCount) -and ($null -eq $serviceCheck)) { Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - " + ` "Waiting for distributed cache to start " + ` @@ -258,7 +258,7 @@ function Set-TargetResource $_.Status -ne "Disabled" } - While (($count -lt $maxCount) -and ($null -ne $serviceCheck)) + while (($count -lt $maxCount) -and ($null -ne $serviceCheck)) { Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting " + ` "for distributed cache to stop on all servers " + ` @@ -285,7 +285,7 @@ function Set-TargetResource $_.Status -ne "Online" } - While (($count -lt $maxCount) -and ($null -ne $serviceCheck)) + while (($count -lt $maxCount) -and ($null -ne $serviceCheck)) { Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting " + ` "for distributed cache to start on all servers " + ` @@ -313,6 +313,67 @@ function Set-TargetResource } } } + elseif ($CurrentState.CacheSizeInMB -ne $CacheSizeInMB) + { + Write-Verbose -Message "Updating distributed cache service cache size" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" + } | Stop-SPServiceInstance -Confirm:$false + + $count = 0 + $maxCount = 30 + + $serviceCheck = Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" -and ` + $_.Status -ne "Disabled" + } + + while (($count -lt $maxCount) -and ($null -ne $serviceCheck)) + { + Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting " + ` + "for distributed cache to stop on all servers " + ` + "(waited $count of $maxCount minutes)") + Start-Sleep -Seconds 60 + $serviceCheck = Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" -and ` + $_.Status -ne "Disabled" + } + $count++ + } + + Update-SPDistributedCacheSize -CacheSizeInMB $params.CacheSizeInMB + + Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" + } | Start-SPServiceInstance + + $count = 0 + $maxCount = 30 + + $serviceCheck = Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" -and ` + $_.Status -ne "Online" + } + + while (($count -lt $maxCount) -and ($null -ne $serviceCheck)) + { + Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting " + ` + "for distributed cache to start on all servers " + ` + "(waited $count of $maxCount minutes)") + Start-Sleep -Seconds 60 + $serviceCheck = Get-SPServiceInstance | Where-Object -FilterScript { + $_.GetType().Name -eq "SPDistributedCacheServiceInstance" -and ` + $_.Status -ne "Online" + } + $count++ + } + } + } } else { @@ -401,7 +462,9 @@ function Test-TargetResource { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Ensure", "CreateFirewallRules") + -ValuesToCheck @("Ensure", ` + "CreateFirewallRules", ` + "CacheSizeInMB") } else { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index 4a516a2d9..f2fb5707a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -324,13 +324,6 @@ function Set-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters - if ($CurrentValues.Ensure -eq "Present") - { - throw ("This server is already connected to a farm. " + ` - "Please manually remove it to apply this change.") - } - - # Set default values to ensure they are passed to Invoke-SPDSCCommand if (-not $PSBoundParameters.ContainsKey("CentralAdministrationPort")) { @@ -341,6 +334,69 @@ function Set-TargetResource $PSBoundParameters.Add("CentralAdministrationAuth", "NTLM") } + if ($CurrentValues.Ensure -eq "Present") + { + if ($CurrentValues.RunCentralAdmin -ne $RunCentralAdmin) + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + # Provision central administration + if ($params.RunCentralAdmin -eq $true) + { + $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` + | Where-Object -FilterScript { + $_.TypeName -eq "Central Administration" + } + if ($null -eq $serviceInstance) + { + $domain = (Get-CimInstance -ClassName Win32_ComputerSystem).Domain + $fqdn = "$($env:COMPUTERNAME).$domain" + $serviceInstance = Get-SPServiceInstance -Server $fqdn ` + | Where-Object -FilterScript { + $_.TypeName -eq "Central Administration" + } + } + if ($null -eq $serviceInstance) + { + throw [Exception] "Unable to locate Central Admin service instance on this server" + } + Start-SPServiceInstance -Identity $serviceInstance + } + else + { + # Unprovision central administration + $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` + | Where-Object -FilterScript { + $_.TypeName -eq "Central Administration" + } + if ($null -eq $serviceInstance) + { + $domain = (Get-CimInstance -ClassName Win32_ComputerSystem).Domain + $fqdn = "$($env:COMPUTERNAME).$domain" + $serviceInstance = Get-SPServiceInstance -Server $fqdn ` + | Where-Object -FilterScript { + $_.TypeName -eq "Central Administration" + } + } + if ($null -eq $serviceInstance) + { + throw [Exception] "Unable to locate Central Admin service instance on this server" + } + Stop-SPServiceInstance -Identity $serviceInstance + } + } + return + } + else + { + throw ("This server is already connected to a farm. " + ` + "Please manually remove it to apply this change.") + } + } + $actionResult = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters, $PSScriptRoot) ` -ScriptBlock { @@ -450,7 +506,7 @@ function Set-TargetResource { try { - $joinObject = Connect-SPConfigurationDatabase @executeArgs + Connect-SPConfigurationDatabase @executeArgs | Out-Null $connectedToFarm = $true } catch @@ -635,7 +691,7 @@ function Test-TargetResource return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Ensure") + -ValuesToCheck @("Ensure", "RunCentralAdmin") } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 index 689242778..11739a70d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 @@ -260,7 +260,7 @@ function Set-TargetResource if($params.ContainsKey("MaxSizeOfUserFormState")) { - $config.MaxSizeOfUserFormState = ($config.MaxSizeOfUserFormState * 1024) + $config.MaxSizeOfUserFormState = ($params.MaxSizeOfUserFormState * 1024) } $config.Update() diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index 41bd5b6a6..a3eb513ee 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -7,7 +7,7 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] $SetupFile, - + [Parameter()] [System.Boolean] $ShutdownServices, @@ -16,16 +16,16 @@ function Get-TargetResource [ValidateSet("mon","tue","wed","thu","fri","sat","sun")] [System.String[]] $BinaryInstallDays, - + [Parameter()] [System.String] $BinaryInstallTime, - + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -96,7 +96,7 @@ function Get-TargetResource { throw "Error while converting language information: $language" } - + # Extract English name of the language code if ($cultureInfo.EnglishName -match "(\w*,*\s*\w*) \(\w*\)") { @@ -207,7 +207,7 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] $SetupFile, - + [Parameter()] [System.Boolean] $ShutdownServices, @@ -216,16 +216,16 @@ function Set-TargetResource [ValidateSet("mon","tue","wed","thu","fri","sat","sun")] [System.String[]] $BinaryInstallDays, - + [Parameter()] [System.String] $BinaryInstallTime, - + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -253,7 +253,7 @@ function Set-TargetResource throw ("Setup file is blocked! Please use Unblock-File to unblock the file " + ` "before continuing.") } - + $now = Get-Date if ($BinaryInstallDays) { @@ -365,32 +365,35 @@ function Set-TargetResource $searchServiceName = "OSearch16" } - $osearchSvc = Get-Service -Name $searchServiceName - $hostControllerSvc = Get-Service -Name "SPSearchHostController" + $osearchSvc = Get-Service -Name $searchServiceName + $hostControllerSvc = Get-Service -Name "SPSearchHostController" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` -ScriptBlock { - $searchPaused = $true $searchSAs = Get-SPEnterpriseSearchServiceApplication foreach ($searchSA in $searchSAs) { - $searchSA.Pause() + if ($searchSA.isPaused() -eq 0) + { + $searchSA.Pause() + } } } - - if($osearchSvc.Status -eq "Running") + $searchPaused = $true + + if($osearchSvc.Status -eq "Running") { $osearchStopped = $true Set-Service -Name $searchServiceName -StartupType Disabled - $osearchSvc.Stop() - } + $osearchSvc.Stop() + } - if($hostControllerSvc.Status -eq "Running") + if($hostControllerSvc.Status -eq "Running") { $hostControllerStopped = $true - Set-Service "SPSearchHostController" -StartupType Disabled - $hostControllerSvc.Stop() - } + Set-Service "SPSearchHostController" -StartupType Disabled + $hostControllerSvc.Stop() + } $hostControllerSvc.WaitForStatus('Stopped','00:01:00') @@ -414,7 +417,7 @@ function Set-TargetResource } Write-Verbose -Message "Beginning installation of the SharePoint update" - + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $SetupFile ` -ScriptBlock { @@ -449,8 +452,8 @@ function Set-TargetResource if ($ShutdownServices) { Write-Verbose -Message "Restart stopped services" - Set-Service -Name "SPTimerV4" -StartupType Automatic - Set-Service -Name "IISADMIN" -StartupType Automatic + Set-Service -Name "SPTimerV4" -StartupType Automatic + Set-Service -Name "IISADMIN" -StartupType Automatic $timerSvc = Get-Service -Name "SPTimerV4" $timerSvc.Start() @@ -460,11 +463,11 @@ function Set-TargetResource -Wait ` -PassThru - $osearchSvc = Get-Service -Name $searchServiceName - $hostControllerSvc = Get-Service -Name "SPSearchHostController" + $osearchSvc = Get-Service -Name $searchServiceName + $hostControllerSvc = Get-Service -Name "SPSearchHostController" - # Ensuring Search Services were stopped by script before Starting" - if($osearchStopped -eq $true) + # Ensuring Search Services were stopped by script before Starting" + if($osearchStopped -eq $true) { Set-Service -Name $searchServiceName -StartupType Manual $osearchSvc.Start() @@ -472,23 +475,26 @@ function Set-TargetResource if($hostControllerStopped -eq $true) { - Set-Service "SPSearchHostController" -StartupType Automatic - $hostControllerSvc.Start() - } + Set-Service "SPSearchHostController" -StartupType Automatic + $hostControllerSvc.Start() + } - # Resuming Search Service Application if paused### - $result = Invoke-SPDSCCommand -Credential $InstallAccount ` - -ScriptBlock { - if($searchPaused -eq $true) - { + if($searchPaused -eq $true) + { + # Resuming Search Service Application if paused### + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -ScriptBlock { $searchSAs = Get-SPEnterpriseSearchServiceApplication foreach ($searchSA in $searchSAs) { - $searchSA.Resume() + if (($searchSA.IsPaused() -band 0x80) -ne 0) + { + $searchSA.Resume() + } } } } - + Write-Verbose -Message "Services restarted." } } @@ -502,7 +508,7 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] $SetupFile, - + [Parameter()] [System.Boolean] $ShutdownServices, @@ -511,16 +517,16 @@ function Test-TargetResource [ValidateSet("mon","tue","wed","thu","fri","sat","sun")] [System.String[]] $BinaryInstallDays, - + [Parameter()] [System.String] $BinaryInstallTime, - + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 index c06031aca..165ef1cdd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 @@ -35,7 +35,7 @@ function Get-TargetResource { $currentLicense = Get-ProjectServerLicense - if ($currentLicense -match "Project Server [0-9]{4} : (?[a-zA-Z]+)") + if ($currentLicense[0] -match "Project Server [0-9]{4} : (?[a-zA-Z]+)") { if ($Matches.Status -eq "Active") { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 index c12caadb7..e02ca0cf8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 @@ -4,11 +4,11 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $ServiceAppName, @@ -16,55 +16,55 @@ function Get-TargetResource [ValidateSet("SharePoint","Website","FileShare")] [System.String] $ContentSourceType, - + [Parameter(Mandatory = $true)] [System.String[]] $Addresses, - + [Parameter(Mandatory = $true)] [ValidateSet("CrawlEverything","CrawlFirstOnly","Custom")] - [System.String] + [System.String] $CrawlSetting, - - [Parameter()] + + [Parameter()] [System.Boolean] $ContinuousCrawl, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $IncrementalSchedule, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $FullSchedule, - - [Parameter()] - [ValidateSet("Normal","High")] - [System.String] + + [Parameter()] + [ValidateSet("Normal","High")] + [System.String] $Priority, - [Parameter()] + [Parameter()] [System.UInt32] $LimitPageDepth, - + [Parameter()] [System.UInt32] $LimitServerHops, - + [Parameter()] [ValidateSet("Present","Absent")] - [System.String] + [System.String] $Ensure = "Present", - + [Parameter()] [System.Boolean] $Force, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount ) - + Write-Verbose -Message "Getting Content Source Setting for '$Name'" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -72,17 +72,17 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] $ScriptRoot = $args[1] - + $relativePath = "..\..\Modules\SharePointDsc.Search\SPSearchContentSource.Schedules.psm1" $modulePath = Join-Path -Path $ScriptRoot ` -ChildPath $relativePath ` -Resolve Import-Module -Name $modulePath - + $source = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName ` -Identity $params.Name ` -ErrorAction SilentlyContinue - if ($null -eq $source) + if ($null -eq $source) { return @{ Name = $params.Name @@ -91,44 +91,44 @@ function Get-TargetResource Ensure = "Absent" } } - - switch ($source.Type) + + switch ($source.Type) { "SharePoint" { $crawlSetting = "CrawlEverything" - if ($source.SharePointCrawlBehavior -eq "CrawlSites") + if ($source.SharePointCrawlBehavior -eq "CrawlSites") { - $crawlSetting = "CrawlFirstOnly" + $crawlSetting = "CrawlFirstOnly" } - + $incrementalSchedule = Get-SPDSCSearchCrawlSchedule ` -Schedule $source.IncrementalCrawlSchedule $fullSchedule = Get-SPDSCSearchCrawlSchedule ` -Schedule $source.FullCrawlSchedule - + $result = @{ Name = $params.Name ServiceAppName = $params.ServiceAppName Ensure = "Present" ContentSourceType = "SharePoint" - Addresses = $source.StartAddresses.AbsoluteUri + Addresses = [array] $source.StartAddresses.AbsoluteUri CrawlSetting = $crawlSetting ContinuousCrawl = $source.EnableContinuousCrawls IncrementalSchedule = $incrementalSchedule FullSchedule = $fullSchedule Priority = $source.CrawlPriority InstallAccount = $params.InstallAccount - } + } } "Web" { $crawlSetting = "Custom" - if ($source.MaxPageEnumerationDepth -eq [System.Int32]::MaxValue) + if ($source.MaxPageEnumerationDepth -eq [System.Int32]::MaxValue) { - $crawlSetting = "CrawlEverything" + $crawlSetting = "CrawlEverything" } - if ($source.MaxPageEnumerationDepth -eq 0) + if ($source.MaxPageEnumerationDepth -eq 0) { - $crawlSetting = "CrawlFirstOnly" + $crawlSetting = "CrawlFirstOnly" } $incrementalSchedule = Get-SPDSCSearchCrawlSchedule ` @@ -141,7 +141,7 @@ function Get-TargetResource ServiceAppName = $params.ServiceAppName Ensure = "Present" ContentSourceType = "Website" - Addresses = $source.StartAddresses.AbsoluteUri + Addresses = [array] $source.StartAddresses.AbsoluteUri CrawlSetting = $crawlSetting IncrementalSchedule = $incrementalSchedule FullSchedule = $fullSchedule @@ -152,12 +152,12 @@ function Get-TargetResource } "File" { $crawlSetting = "CrawlFirstOnly" - if ($source.FollowDirectories -eq $true) + if ($source.FollowDirectories -eq $true) { - $crawlSetting = "CrawlEverything" + $crawlSetting = "CrawlEverything" } - - $addresses = $source.StartAddresses.AbsoluteUri + + $addresses = [array] $source.StartAddresses.AbsoluteUri $addresses = $addresses.Replace("file:///","\\").Replace("/", "\") $incrementalSchedule = Get-SPDSCSearchCrawlSchedule ` @@ -182,7 +182,7 @@ function Get-TargetResource "sources. Please use only 'SharePoint', 'FileShare' or 'Website'.") } } - return $result + return $result } return $result } @@ -192,11 +192,11 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $ServiceAppName, @@ -204,50 +204,50 @@ function Set-TargetResource [ValidateSet("SharePoint","Website","FileShare")] [System.String] $ContentSourceType, - + [Parameter(Mandatory = $true)] [System.String[]] $Addresses, - + [Parameter(Mandatory = $true)] [ValidateSet("CrawlEverything","CrawlFirstOnly","Custom")] - [System.String] + [System.String] $CrawlSetting, - - [Parameter()] + + [Parameter()] [System.Boolean] $ContinuousCrawl, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $IncrementalSchedule, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $FullSchedule, - - [Parameter()] - [ValidateSet("Normal","High")] - [System.String] + + [Parameter()] + [ValidateSet("Normal","High")] + [System.String] $Priority, - [Parameter()] + [Parameter()] [System.UInt32] $LimitPageDepth, - + [Parameter()] [System.UInt32] $LimitServerHops, - + [Parameter()] [ValidateSet("Present","Absent")] - [System.String] + [System.String] $Ensure = "Present", - + [Parameter()] [System.Boolean] $Force, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -258,55 +258,55 @@ function Set-TargetResource switch ($ContentSourceType) { "SharePoint" { - if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + throw "Parameter LimitPageDepth is not valid for SharePoint content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for SharePoint content sources" + throw "Parameter LimitServerHops is not valid for SharePoint content sources" } if ($ContinuousCrawl -eq $true -and ` - $PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) + $PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) { throw ("You can not specify an incremental crawl schedule on a content source " + ` - "that will use continous crawl") + "that will use continous crawl") } - if ($CrawlSetting -eq "Custom") + if ($CrawlSetting -eq "Custom") { throw ("Parameter 'CrawlSetting' can only be set to custom for website content " + ` - "sources") + "sources") } } "Website" { - if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) + if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for website content sources" + throw "Parameter ContinuousCrawl is not valid for website content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for website content sources" + throw "Parameter LimitServerHops is not valid for website content sources" } } "FileShare" { - if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for file share content sources" + throw "Parameter LimitPageDepth is not valid for file share content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for file share content sources" + throw "Parameter LimitServerHops is not valid for file share content sources" } - if ($CrawlSetting -eq "Custom") + if ($CrawlSetting -eq "Custom") { - throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" } } - } - + } + $CurrentValues = Get-TargetResource @PSBoundParameters - - if ($ContentSourceType -ne $CurrentValues.ContentSourceType -and $Force -eq $false) + + if ($ContentSourceType -ne $CurrentValues.ContentSourceType -and $Force -eq $false) { throw ("The type of the a search content source can not be changed from " + ` "'$($CurrentValues.ContentSourceType)' to '$ContentSourceType' without " + ` @@ -316,64 +316,64 @@ function Set-TargetResource } if (($ContentSourceType -ne $CurrentValues.ContentSourceType -and $Force -eq $true) ` - -or ($Ensure -eq "Absent" -and $CurrentValues.Ensure -ne $Ensure)) + -or ($Ensure -eq "Absent" -and $CurrentValues.Ensure -ne $Ensure)) { # Remove the existing content source Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters) ` -ScriptBlock { - $params = $args[0] + $params = $args[0] Remove-SPEnterpriseSearchCrawlContentSource -Identity $params.Name ` -SearchApplication $params.ServiceAppName ` -Confirm:$false - } + } } - - if ($Ensure -eq "Present") + + if ($Ensure -eq "Present") { # Create the new content source and then apply settings to it Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters) ` -ScriptBlock { - $params = $args[0] - + $params = $args[0] + $OFS = "," $startAddresses = "$($params.Addresses)" - + $source = Get-SPEnterpriseSearchCrawlContentSource ` -SearchApplication $params.ServiceAppName ` -Identity $params.Name ` -ErrorAction SilentlyContinue - if ($null -eq $source) + if ($null -eq $source) { switch ($params.ContentSourceType) { "SharePoint" { - $newType = "SharePoint" + $newType = "SharePoint" } "Website" { $newType = "Web" } "FileShare" { - $newType = "File" + $newType = "File" } } $source = New-SPEnterpriseSearchCrawlContentSource ` -SearchApplication $params.ServiceAppName ` -Type $newType ` -Name $params.Name ` - -StartAddresses $startAddresses + -StartAddresses $startAddresses } - + $allSetArguments = @{ Identity = $params.Name SearchApplication = $params.ServiceAppName Confirm = $false } - + if ($params.ContentSourceType -eq "SharePoint" -and ` - $source.EnableContinuousCrawls -eq $true) + $source.EnableContinuousCrawls -eq $true) { Set-SPEnterpriseSearchCrawlContentSource @allSetArguments ` -EnableContinuousCrawls $false @@ -381,24 +381,24 @@ function Set-TargetResource "correctly before continuing updating the configuration.") Start-Sleep -Seconds 300 } - - if ($source.CrawlStatus -ne "Idle") + + if ($source.CrawlStatus -ne "Idle") { Write-Verbose -Message ("Content source '$($params.Name)' is not idle, " + ` "stopping current crawls to allow settings to be updated") - + $source = Get-SPEnterpriseSearchCrawlContentSource ` -SearchApplication $params.ServiceAppName ` -Identity $params.Name - + $source.StopCrawl() $loopCount = 0 - + $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource ` -SearchApplication $params.ServiceAppName ` -Identity $params.Name - while ($sourceToWait.CrawlStatus -ne "Idle" -or $loopCount > 15) + while ($sourceToWait.CrawlStatus -ne "Idle" -and $loopCount -lt 15) { $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource ` -SearchApplication $params.ServiceAppName ` @@ -415,35 +415,35 @@ function Set-TargetResource $primarySetArgs = @{ StartAddresses = $startAddresses } - - if ($params.ContainsKey("ContinuousCrawl") -eq $true) + + if ($params.ContainsKey("ContinuousCrawl") -eq $true) { $primarySetArgs.Add("EnableContinuousCrawls", $params.ContinuousCrawl) } - if ($params.ContainsKey("Priority") -eq $true) + if ($params.ContainsKey("Priority") -eq $true) { - switch ($params.Priority) + switch ($params.Priority) { "High" { - $primarySetArgs.Add("CrawlPriority", "2") + $primarySetArgs.Add("CrawlPriority", "2") } "Normal" { - $primarySetArgs.Add("CrawlPriority", "1") + $primarySetArgs.Add("CrawlPriority", "1") } } } - Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @primarySetArgs - + Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @primarySetArgs + # Set the incremental search values if ($params.ContainsKey("IncrementalSchedule") -eq $true -and ` - $null -ne $params.IncrementalSchedule) + $null -ne $params.IncrementalSchedule) { $incrementalSetArgs = @{ ScheduleType = "Incremental" } - switch ($params.IncrementalSchedule.ScheduleType) + switch ($params.IncrementalSchedule.ScheduleType) { "None" { $incrementalSetArgs.Add("RemoveCrawlSchedule", $true) @@ -456,15 +456,15 @@ function Set-TargetResource $propertyTest = Test-SPDSCObjectHasProperty ` -Object $params.IncrementalSchedule ` -PropertyName "CrawlScheduleDaysOfWeek" - - if ($propertyTest -eq $true) + + if ($propertyTest -eq $true) { $OFS = "," $enumValue = ` [enum]::Parse([Microsoft.Office.Server.Search.Administration.DaysOfWeek], ` "$($params.IncrementalSchedule.CrawlScheduleDaysOfWeek)") - - $incrementalSetArgs.Add("CrawlScheduleDaysOfWeek", $enumValue) + + $incrementalSetArgs.Add("CrawlScheduleDaysOfWeek", $enumValue) } } "Monthly" { @@ -473,7 +473,7 @@ function Set-TargetResource -Object $params.IncrementalSchedule ` -PropertyName "CrawlScheduleDaysOfMonth" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { $incrementalSetArgs.Add("CrawlScheduleDaysOfMonth", ` $params.IncrementalSchedule.CrawlScheduleDaysOfMonth) @@ -483,7 +483,7 @@ function Set-TargetResource -Object $params.IncrementalSchedule ` -PropertyName "CrawlScheduleMonthsOfYear" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { foreach ($month in $params.IncrementalSchedule.CrawlScheduleMonthsOfYear) { @@ -493,20 +493,20 @@ function Set-TargetResource } } } - + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.IncrementalSchedule ` -PropertyName "CrawlScheduleRepeatDuration" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $incrementalSetArgs.Add("CrawlScheduleRepeatDuration", + $incrementalSetArgs.Add("CrawlScheduleRepeatDuration", $params.IncrementalSchedule.CrawlScheduleRepeatDuration) } $propertyTest = Test-SPDSCObjectHasProperty -Object $params.IncrementalSchedule ` -PropertyName "CrawlScheduleRepeatInterval" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $incrementalSetArgs.Add("CrawlScheduleRepeatInterval", + $incrementalSetArgs.Add("CrawlScheduleRepeatInterval", $params.IncrementalSchedule.CrawlScheduleRepeatInterval) } @@ -514,19 +514,27 @@ function Set-TargetResource -PropertyName "CrawlScheduleRunEveryInterval" if ($propertyTest -eq $true) { - $incrementalSetArgs.Add("CrawlScheduleRunEveryInterval", + $incrementalSetArgs.Add("CrawlScheduleRunEveryInterval", $params.IncrementalSchedule.CrawlScheduleRunEveryInterval) } + + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.IncrementalSchedule ` + -PropertyName "StartHour" + if ($propertyTest -eq $true) + { + $incrementalSetArgs.Add("CrawlScheduleStartDateTime", + "$($params.IncrementalSchedule.StartHour):$($params.IncrementalSchedule.StartMinute)") + } Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @incrementalSetArgs } - + # Set the full search values - if ($params.ContainsKey("FullSchedule") -eq $true) + if ($params.ContainsKey("FullSchedule") -eq $true) { $fullSetArgs = @{ ScheduleType = "Full" } - switch ($params.FullSchedule.ScheduleType) + switch ($params.FullSchedule.ScheduleType) { "None" { $fullSetArgs.Add("RemoveCrawlSchedule", $true) @@ -538,7 +546,7 @@ function Set-TargetResource $fullSetArgs.Add("WeeklyCrawlSchedule", $true) $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleDaysOfWeek" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { foreach ($day in $params.FullSchedule.CrawlScheduleDaysOfWeek) { @@ -551,15 +559,15 @@ function Set-TargetResource $fullSetArgs.Add("MonthlyCrawlSchedule", $true) $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleDaysOfMonth" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $fullSetArgs.Add("CrawlScheduleDaysOfMonth", + $fullSetArgs.Add("CrawlScheduleDaysOfMonth", $params.FullSchedule.CrawlScheduleDaysOfMonth) } $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleMonthsOfYear" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { foreach ($month in $params.FullSchedule.CrawlScheduleMonthsOfYear) { @@ -569,30 +577,38 @@ function Set-TargetResource } } } - + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleRepeatDuration" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $fullSetArgs.Add("CrawlScheduleRepeatDuration", + $fullSetArgs.Add("CrawlScheduleRepeatDuration", $params.FullSchedule.CrawlScheduleRepeatDuration) } $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleRepeatInterval" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $fullSetArgs.Add("CrawlScheduleRepeatInterval", + $fullSetArgs.Add("CrawlScheduleRepeatInterval", $params.FullSchedule.CrawlScheduleRepeatInterval) } $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "CrawlScheduleRunEveryInterval" - if ($propertyTest -eq $true) + if ($propertyTest -eq $true) { - $fullSetArgs.Add("CrawlScheduleRunEveryInterval", + $fullSetArgs.Add("CrawlScheduleRunEveryInterval", $params.FullSchedule.CrawlScheduleRunEveryInterval) } + + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` + -PropertyName "StartHour" + if ($propertyTest -eq $true) + { + $fullSetArgs.Add("CrawlScheduleStartDateTime", + "$($params.FullSchedule.StartHour):$($params.FullSchedule.StartMinute)") + } Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @fullSetArgs } } @@ -605,11 +621,11 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $ServiceAppName, @@ -617,123 +633,123 @@ function Test-TargetResource [ValidateSet("SharePoint","Website","FileShare")] [System.String] $ContentSourceType, - + [Parameter(Mandatory = $true)] [System.String[]] $Addresses, - + [Parameter(Mandatory = $true)] [ValidateSet("CrawlEverything","CrawlFirstOnly","Custom")] - [System.String] + [System.String] $CrawlSetting, - - [Parameter()] + + [Parameter()] [System.Boolean] $ContinuousCrawl, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $IncrementalSchedule, - + [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $FullSchedule, - - [Parameter()] - [ValidateSet("Normal","High")] - [System.String] + + [Parameter()] + [ValidateSet("Normal","High")] + [System.String] $Priority, - [Parameter()] + [Parameter()] [System.UInt32] $LimitPageDepth, - + [Parameter()] [System.UInt32] $LimitServerHops, - + [Parameter()] [ValidateSet("Present","Absent")] - [System.String] + [System.String] $Ensure = "Present", - + [Parameter()] [System.Boolean] $Force, - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount ) - + Write-Verbose -Message "Testing Content Source Setting for '$Name'" $PSBoundParameters.Ensure = $Ensure - + switch ($ContentSourceType) { "SharePoint" { - if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + throw "Parameter LimitPageDepth is not valid for SharePoint content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for SharePoint content sources" + throw "Parameter LimitServerHops is not valid for SharePoint content sources" } if ($ContinuousCrawl -eq $true -and ` - $PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) + $PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) { throw ("You can not specify an incremental crawl schedule on a content source " + ` - "that will use continous crawl") + "that will use continous crawl") } - if ($CrawlSetting -eq "Custom") + if ($CrawlSetting -eq "Custom") { throw ("Parameter 'CrawlSetting' can only be set to custom for website content " + ` - "sources") + "sources") } } "Website" { - if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) + if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for website content sources" + throw "Parameter ContinuousCrawl is not valid for website content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for website content sources" + throw "Parameter LimitServerHops is not valid for website content sources" } } "FileShare" { - if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for file share content sources" + throw "Parameter LimitPageDepth is not valid for file share content sources" } - if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) + if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for file share content sources" + throw "Parameter LimitServerHops is not valid for file share content sources" } - if ($CrawlSetting -eq "Custom") + if ($CrawlSetting -eq "Custom") { - throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" } } - } + } $CurrentValues = Get-TargetResource @PSBoundParameters - - if ($Ensure -eq "Absent" -or $CurrentValues.Ensure -eq "Absent") + + if ($Ensure -eq "Absent" -or $CurrentValues.Ensure -eq "Absent") { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Ensure") } - + $relativePath = "..\..\Modules\SharePointDsc.Search\SPSearchContentSource.Schedules.psm1" $modulePath = Join-Path -Path $PSScriptRoot ` -ChildPath $relativePath ` -Resolve Import-Module -Name $modulePath - - if (($PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) -and ($null -ne $IncrementalSchedule)) + + if (($PSBoundParameters.ContainsKey("IncrementalSchedule") -eq $true) -and ($null -ne $IncrementalSchedule)) { $propertyTest = Test-SPDSCSearchCrawlSchedule -CurrentSchedule $CurrentValues.IncrementalSchedule ` -DesiredSchedule $IncrementalSchedule @@ -742,7 +758,7 @@ function Test-TargetResource return $false } } - + if (($PSBoundParameters.ContainsKey("FullSchedule") -eq $true) -and ($null -ne $FullSchedule)) { $propertyTest = Test-SPDSCSearchCrawlSchedule -CurrentSchedule $CurrentValues.FullSchedule ` @@ -752,33 +768,33 @@ function Test-TargetResource return $false } } - + # Compare the addresses as Uri objects to handle things like trailing /'s on URLs $currentAddresses = @() - foreach ($address in $CurrentValues.Addresses) + foreach ($address in $CurrentValues.Addresses) { - $currentAddresses += New-Object -TypeName System.Uri -ArgumentList $address + $currentAddresses += New-Object -TypeName System.Uri -ArgumentList $address } $desiredAddresses = @() - foreach ($address in $Addresses) + foreach ($address in $Addresses) { - $desiredAddresses += New-Object -TypeName System.Uri -ArgumentList $address + $desiredAddresses += New-Object -TypeName System.Uri -ArgumentList $address } - + if ($null -ne (Compare-Object -ReferenceObject $currentAddresses ` - -DifferenceObject $desiredAddresses)) + -DifferenceObject $desiredAddresses)) { return $false } - + return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("ContentSourceType", - "CrawlSetting", - "ContinousCrawl", - "Priority", - "LimitPageDepth", - "LimitServerHops", + -ValuesToCheck @("ContentSourceType", + "CrawlSetting", + "ContinousCrawl", + "Priority", + "LimitPageDepth", + "LimitServerHops", "Ensure") } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 index 3e1adffe8..eda711acb 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 @@ -1,55 +1,55 @@ function Get-TargetResource { - # Ignoring this because we need to generate a stub credential to return up the current + # Ignoring this because we need to generate a stub credential to return up the current # crawl account as a PSCredential [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] + [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ProxyName, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseServer, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseName, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SearchCenterUrl, - - [Parameter()] - [System.Boolean] + + [Parameter()] + [System.Boolean] $CloudIndex, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $WindowsServiceAccount, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -60,48 +60,51 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] $scriptRoot = $args[1] - + Import-Module -Name (Join-Path $scriptRoot "MSFT_SPSearchServiceApp.psm1") - + [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") - [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") + [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue - + $nullReturn = @{ Name = $params.Name ApplicationPool = $params.ApplicationPool Ensure = "Absent" } - - if ($null -eq $serviceApps) + + if ($null -eq $serviceApps) { - return $nullReturn + return $nullReturn } $serviceApp = $serviceApps | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" } - if ($null -eq $serviceApp) + if ($null -eq $serviceApp) { return $nullReturn - } - else + } + else { $c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($serviceApp.Name) $sc = New-Object -TypeName Microsoft.Office.Server.Search.Administration.Content ` -ArgumentList $c; $dummyPassword = ConvertTo-SecureString -String "-" -AsPlainText -Force - $defaultAccount = New-Object -TypeName System.Management.Automation.PSCredential ` - -ArgumentList @($sc.DefaultGatheringAccount, $dummyPassword) + if ($null -ne $sc.DefaultGatheringAccount) + { + $defaultAccount = New-Object -TypeName System.Management.Automation.PSCredential ` + -ArgumentList @($sc.DefaultGatheringAccount, $dummyPassword) + } $cloudIndex = $false $version = Get-SPDSCInstalledProductVersion if(($version.FileMajorPart -gt 15) ` - -or ($version.FileMajorPart -eq 15 -and $version.FileBuildPart -ge 4745)) + -or ($version.FileMajorPart -eq 15 -and $version.FileBuildPart -ge 4745)) { $cloudIndex = $serviceApp.CloudIndex } @@ -112,11 +115,11 @@ function Get-TargetResource $serviceAppProxy = $serviceAppProxies | Where-Object -FilterScript { $serviceApp.IsConnected($_) } - if ($null -ne $serviceAppProxy) + if ($null -ne $serviceAppProxy) { $proxyName = $serviceAppProxy.Name } - } + } $searchService = Get-SPEnterpriseSearchService $windowsAccount = New-Object -TypeName System.Management.Automation.PSCredential ` @@ -146,49 +149,49 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ProxyName, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseServer, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseName, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SearchCenterUrl, - - [Parameter()] - [System.Boolean] + + [Parameter()] + [System.Boolean] $CloudIndex, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $WindowsServiceAccount, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -196,59 +199,59 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters - if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") { # Create the service app as it doesn't exist - + Write-Verbose -Message "Creating Search Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] - - $serviceInstance = Get-SPEnterpriseSearchServiceInstance -Local + + $serviceInstance = Get-SPEnterpriseSearchServiceInstance -Local Start-SPEnterpriseSearchServiceInstance -Identity $serviceInstance ` - -ErrorAction SilentlyContinue + -ErrorAction SilentlyContinue $newParams = @{ Name = $params.Name ApplicationPool = $params.ApplicationPool } - if ($params.ContainsKey("DatabaseServer") -eq $true) + if ($params.ContainsKey("DatabaseServer") -eq $true) { - $newParams.Add("DatabaseServer", $params.DatabaseServer) + $newParams.Add("DatabaseServer", $params.DatabaseServer) } - if ($params.ContainsKey("DatabaseName") -eq $true) + if ($params.ContainsKey("DatabaseName") -eq $true) { - $newParams.Add("DatabaseName", $params.DatabaseName) + $newParams.Add("DatabaseName", $params.DatabaseName) } - + if ($params.ContainsKey("CloudIndex") -eq $true -and $params.CloudIndex -eq $true) { $version = Get-SPDSCInstalledProductVersion if (($version.FileMajorPart -gt 15) ` - -or ($version.FileMajorPart -eq 15 -and $version.FileBuildPart -ge 4745)) + -or ($version.FileMajorPart -eq 15 -and $version.FileBuildPart -ge 4745)) { - $newParams.Add("CloudIndex", $params.CloudIndex) - } - else + $newParams.Add("CloudIndex", $params.CloudIndex) + } + else { throw ("Please install SharePoint 2016 or SharePoint 2013 with August " + ` "2015 CU or higher before attempting to create a cloud enabled " + ` "search service application") } } - - $app = New-SPEnterpriseSearchServiceApplication @newParams - if ($app) + + $app = New-SPEnterpriseSearchServiceApplication @newParams + if ($app) { - if ($null -eq $params.ProxyName) + if ($null -eq $params.ProxyName) { $pName = "$($params.Name) Proxy" - } - else + } + else { $pName = $params.ProxyName } New-SPEnterpriseSearchServiceApplicationProxy -Name $pName -SearchApplication $app - if ($params.ContainsKey("DefaultContentAccessAccount") -eq $true) + if ($params.ContainsKey("DefaultContentAccessAccount") -eq $true) { $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool $account = $params.DefaultContentAccessAccount @@ -259,9 +262,9 @@ function Set-TargetResource DefaultContentAccessAccountPassword = $account.Password } Set-SPEnterpriseSearchServiceApplication @setParams - } - - if ($params.ContainsKey("SearchCenterUrl") -eq $true) + } + + if ($params.ContainsKey("SearchCenterUrl") -eq $true) { $serviceApp = Get-SPServiceApplication -Name $params.Name | ` Where-Object -FilterScript { @@ -273,14 +276,14 @@ function Set-TargetResource if ($params.ContainsKey("WindowsServiceAccount") -eq $true) { - Set-SPEnterpriseSearchService -ServiceAccount $WindowsServiceAccount.UserName ` - -ServicePassword $WindowsServiceAccount.Password + Set-SPEnterpriseSearchService -ServiceAccount $params.WindowsServiceAccount.UserName ` + -ServicePassword $params.WindowsServiceAccount.Password } } } } - if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { # Update the service app that already exists Write-Verbose -Message "Updating Search Service Application $Name" @@ -289,7 +292,7 @@ function Set-TargetResource -ScriptBlock { $params = $args[0] $result = $args[1] - + $serviceApp = Get-SPServiceApplication -Name $params.Name | ` Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" @@ -299,19 +302,19 @@ function Set-TargetResource ApplicationPool = $appPool Identity = $serviceApp } - if ($params.ContainsKey("DefaultContentAccessAccount") -eq $true) + if ($params.ContainsKey("DefaultContentAccessAccount") -eq $true) { $account = $params.DefaultContentAccessAccount $setParams.Add("DefaultContentAccessAccountName", $account.UserName) $setParams.Add("DefaultContentAccessAccountPassword", $account.Password) - } + } Set-SPEnterpriseSearchServiceApplication @setParams - - if ($params.ContainsKey("SearchCenterUrl") -eq $true) + + if ($params.ContainsKey("SearchCenterUrl") -eq $true) { $serviceApp = Get-SPServiceApplication -Name $params.Name | ` Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" + $_.GetType().FullName -eq "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" } $serviceApp.SearchCenterUrl = $params.SearchCenterUrl $serviceApp.Update() @@ -321,12 +324,12 @@ function Set-TargetResource $result.WindowsServiceAccount.UserName -ne $params.WindowsServiceAccount.UserName) { Set-SPEnterpriseSearchService -ServiceAccount $params.WindowsServiceAccount.UserName ` - -ServicePassword $params.WindowsServiceAccount.Password + -ServicePassword $params.WindowsServiceAccount.Password } } } - - if ($Ensure -eq "Absent") + + if ($Ensure -eq "Absent") { # The service app should not exit Write-Verbose -Message "Removing Search Service Application $Name" @@ -334,7 +337,7 @@ function Set-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" @@ -360,49 +363,49 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ProxyName, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseServer, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DatabaseName, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SearchCenterUrl, - - [Parameter()] - [System.Boolean] + + [Parameter()] + [System.Boolean] $CloudIndex, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $DefaultContentAccessAccount, [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $WindowsServiceAccount, - - [Parameter()] - [System.Management.Automation.PSCredential] + + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -413,10 +416,10 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters if ($PSBoundParameters.ContainsKey("DefaultContentAccessAccount") ` - -and $Ensure -eq "Present") + -and $Ensure -eq "Present") { if ($DefaultContentAccessAccount.UserName ` - -ne $CurrentValues.DefaultContentAccessAccount.UserName) + -ne $CurrentValues.DefaultContentAccessAccount.UserName) { Write-Verbose -Message "Default content access account is different, returning false" return $false @@ -424,30 +427,30 @@ function Test-TargetResource } if ($PSBoundParameters.ContainsKey("WindowsServiceAccount") ` - -and $Ensure -eq "Present") + -and $Ensure -eq "Present") { if ($WindowsServiceAccount.UserName ` - -ne $CurrentValues.WindowsServiceAccount.UserName) + -ne $CurrentValues.WindowsServiceAccount.UserName) { Write-Verbose -Message "Windows service account is different, returning false" return $false } } - - if ($Ensure -eq "Present") + + if ($Ensure -eq "Present") { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Ensure", - "ApplicationPool", - "SearchCenterUrl") - } - else + -ValuesToCheck @("Ensure", + "ApplicationPool", + "SearchCenterUrl") + } + else { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Ensure") - } + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 index 5ff11d4d6..355ab2373 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 @@ -69,7 +69,8 @@ function Get-TargetResource -PassThru } - $allComponents = Get-SPEnterpriseSearchComponent -SearchTopology $currentTopology + $allComponents = Get-SPEnterpriseSearchComponent -SearchTopology $currentTopology ` + -ErrorAction SilentlyContinue $AdminComponents = @() $AdminComponents += ($allComponents | Where-Object -FilterScript { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 90629c69b..40e7356c7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -4,41 +4,41 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ServiceAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Administrators","SharingPermissions")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Administrators","SharingPermissions")] + [System.String] $SecurityType, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $Members, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $MembersToInclude, - [Parameter()] - [System.String[]] + [Parameter()] + [System.String[]] $MembersToExclude, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Getting all security options for $SecurityType in $ServiceAppName" - if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) + if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { throw ("Cannot use the Members parameter together with the MembersToInclude or " + ` "MembersToExclude parameters") } - if (!$Members -and !$MembersToInclude -and !$MembersToExclude) + if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") @@ -50,8 +50,8 @@ function Get-TargetResource $params = $args[0] $serviceApp = Get-SPServiceApplication -Name $params.ServiceAppName - - if ($null -eq $serviceApp) + + if ($null -eq $serviceApp) { return @{ ServiceAppName = "" @@ -59,8 +59,8 @@ function Get-TargetResource InstallAccount = $params.InstallAccount } } - - switch ($params.SecurityType) + + switch ($params.SecurityType) { "Administrators" { $security = $serviceApp | Get-SPServiceApplicationSecurity -Admin @@ -69,12 +69,12 @@ function Get-TargetResource $security = $serviceApp | Get-SPServiceApplicationSecurity } } - + $members = @() - foreach ($securityEntry in $security.AccessRules) + foreach ($securityEntry in $security.AccessRules) { $user = $securityEntry.Name - if ($user -like "i:*|*" -or $user -like "c:*|*") + if ($user -like "i:*|*" -or $user -like "c:*|*") { $user = (New-SPClaimsPrincipal -Identity $user -IdentityType EncodedClaim).Value if ($user -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") @@ -91,7 +91,7 @@ function Get-TargetResource AccessLevel = $accessLevel } } - + return @{ ServiceAppName = $params.ServiceAppName SecurityType = $params.SecurityType @@ -109,61 +109,61 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ServiceAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Administrators","SharingPermissions")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Administrators","SharingPermissions")] + [System.String] $SecurityType, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $Members, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $MembersToInclude, - [Parameter()] - [System.String[]] + [Parameter()] + [System.String[]] $MembersToExclude, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting all security options for $SecurityType in $ServiceAppName" - - if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) + + if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { throw ("Cannot use the Members parameter together with the MembersToInclude or " + ` "MembersToExclude parameters") } - if (!$Members -and !$MembersToInclude -and !$MembersToExclude) + if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") } $CurrentValues = Get-TargetResource @PSBoundParameters - - if ([System.String]::IsNullOrEmpty($CurrentValues.ServiceAppName) -eq $true) + + if ([System.String]::IsNullOrEmpty($CurrentValues.ServiceAppName) -eq $true) { throw "Unable to locate service application $ServiceAppName" } - + Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters, $CurrentValues) ` -ScriptBlock { $params = $args[0] $CurrentValues = $args[1] - + $serviceApp = Get-SPServiceApplication -Name $params.ServiceAppName - switch ($params.SecurityType) + switch ($params.SecurityType) { "Administrators" { $security = $serviceApp | Get-SPServiceApplicationSecurity -Admin @@ -172,28 +172,28 @@ function Set-TargetResource $security = $serviceApp | Get-SPServiceApplicationSecurity } } - - if ($params.ContainsKey("Members") -eq $true) + + if ($params.ContainsKey("Members") -eq $true) { - foreach($desiredMember in $params.Members) + foreach($desiredMember in $params.Members) { $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` -IdentityType WindowsSecurityGroupName } - - if ($CurrentValues.Members.Username -contains $desiredMember.Username) + + if ($CurrentValues.Members.Username -contains $desiredMember.Username) { if (($CurrentValues.Members | Where-Object -FilterScript { - $_.Username -eq $desiredMember.Username - } | Select-Object -First 1).AccessLevel -ne $desiredMember.AccessLevel) + $_.Username -eq $desiredMember.Username + } | Select-Object -First 1).AccessLevel -ne $desiredMember.AccessLevel) { Revoke-SPObjectSecurity -Identity $security ` -Principal $claim @@ -202,24 +202,24 @@ function Set-TargetResource -Principal $claim ` -Rights $desiredMember.AccessLevel } - } - else + } + else { Grant-SPObjectSecurity -Identity $security -Principal $claim -Rights $desiredMember.AccessLevel } } - - foreach($currentMember in $CurrentValues.Members) + + foreach($currentMember in $CurrentValues.Members) { - if ($params.Members.Username -notcontains $currentMember.Username) + if ($params.Members.Username -notcontains $currentMember.Username) { $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` -IdentityType WindowsSecurityGroupName @@ -229,26 +229,26 @@ function Set-TargetResource } } - if ($params.ContainsKey("MembersToInclude") -eq $true) + if ($params.ContainsKey("MembersToInclude") -eq $true) { - foreach($desiredMember in $params.MembersToInclude) + foreach($desiredMember in $params.MembersToInclude) { $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` -IdentityType WindowsSecurityGroupName } - if ($CurrentValues.Members.Username -contains $desiredMember.Username) + if ($CurrentValues.Members.Username -contains $desiredMember.Username) { if (($CurrentValues.Members | Where-Object -FilterScript { - $_.Username -eq $desiredMember.Username - } | Select-Object -First 1).AccessLevel -ne $desiredMember.AccessLevel) + $_.Username -eq $desiredMember.Username + } | Select-Object -First 1).AccessLevel -ne $desiredMember.AccessLevel) { Revoke-SPObjectSecurity -Identity $security ` -Principal $claim @@ -257,8 +257,8 @@ function Set-TargetResource -Principal $claim ` -Rights $desiredMember.AccessLevel } - } - else + } + else { Grant-SPObjectSecurity -Identity $security ` -Principal $claim ` @@ -267,19 +267,19 @@ function Set-TargetResource } } - if ($params.ContainsKey("MembersToExclude") -eq $true) + if ($params.ContainsKey("MembersToExclude") -eq $true) { - foreach($excludeMember in $params.MembersToExclude) + foreach($excludeMember in $params.MembersToExclude) { - if ($CurrentValues.Members.Username -contains $excludeMember) + if ($CurrentValues.Members.Username -contains $excludeMember) { $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` -IdentityType WindowsSecurityGroupName @@ -288,8 +288,8 @@ function Set-TargetResource } } } - - switch ($params.SecurityType) + + switch ($params.SecurityType) { "Administrators" { $security = $serviceApp | Set-SPServiceApplicationSecurity -ObjectSecurity $security ` @@ -308,29 +308,29 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ServiceAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Administrators","SharingPermissions")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Administrators","SharingPermissions")] + [System.String] $SecurityType, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $Members, - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance[]] + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] $MembersToInclude, - [Parameter()] - [System.String[]] + [Parameter()] + [System.String[]] $MembersToExclude, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -338,40 +338,54 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters - if ([System.String]::IsNullOrEmpty($CurrentValues.ServiceAppName) -eq $true) + if ([System.String]::IsNullOrEmpty($CurrentValues.ServiceAppName) -eq $true) { - return $false + return $false } - - if ($Members) + + if ($Members) { Write-Verbose -Message "Processing Members parameter" - + if ($null -eq $CurrentValues.Members) { Write-Verbose -Message "Security list does not match" return $false } + if ($CurrentValues.Members.Count -eq 0) + { + if ($Members.Count -gt 0) + { + Write-Verbose -Message "Security list does not match" + return $false + } + else + { + Write-Verbose -Message "Configured and specified security lists are both empty" + return $true + } + } + $differences = Compare-Object -ReferenceObject $CurrentValues.Members.Username ` -DifferenceObject $Members.Username - if ($null -eq $differences) + if ($null -eq $differences) { Write-Verbose -Message "Security list matches - checking that permissions match on each object" - foreach($currentMember in $CurrentValues.Members) + foreach($currentMember in $CurrentValues.Members) { if ($currentMember.AccessLevel -ne ($Members | Where-Object -FilterScript { - $_.Username -eq $currentMember.Username - } | Select-Object -First 1).AccessLevel) + $_.Username -eq $currentMember.Username + } | Select-Object -First 1).AccessLevel) { Write-Verbose -Message "$($currentMember.Username) has incorrect permission level. Test failed." return $false } } return $true - } - else + } + else { Write-Verbose -Message "Security list does not match" return $false @@ -379,22 +393,22 @@ function Test-TargetResource } $result = $true - if ($MembersToInclude) + if ($MembersToInclude) { Write-Verbose -Message "Processing MembersToInclude parameter" - foreach ($member in $MembersToInclude) + foreach ($member in $MembersToInclude) { - if (-not($CurrentValues.Members.Username -contains $member.Username)) + if (-not($CurrentValues.Members.Username -contains $member.Username)) { Write-Verbose -Message "$($member.Username) does not have access. Set result to false" $result = $false - } - else + } + else { Write-Verbose -Message "$($member.Username) already has access. Checking permission..." if ($member.AccessLevel -ne ($CurrentValues.Members | Where-Object -FilterScript { - $_.Username -eq $member.Username - } | Select-Object -First 1).AccessLevel) + $_.Username -eq $member.Username + } | Select-Object -First 1).AccessLevel) { Write-Verbose -Message "$($member.Username) has incorrect permission level. Test failed." return $false @@ -403,17 +417,17 @@ function Test-TargetResource } } - if ($MembersToExclude) + if ($MembersToExclude) { Write-Verbose -Message "Processing MembersToExclude parameter" - foreach ($member in $MembersToExclude) + foreach ($member in $MembersToExclude) { - if ($CurrentValues.Members.Username -contains $member.Username) + if ($CurrentValues.Members.Username -contains $member.Username) { Write-Verbose -Message "$member already has access. Set result to false" $result = $false - } - else + } + else { Write-Verbose -Message "$member does not have access. Skipping" } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPShellAdmins/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPShellAdmins/readme.md index 979611faf..4493df601 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPShellAdmins/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPShellAdmins/readme.md @@ -23,6 +23,16 @@ Requirements: * Do not combine the ContentDatabase property with the AllContentDatabases property. +Required permissions: + +The documentation of the Shell Admin cmdlets states that you need the following +permissions to successfully run this resource: +"When you run this cmdlet to add a user to the SharePoint_Shell_Access role, +you must have membership in the securityadmin fixed server role on the SQL +Server instance, membership in the db_owner fixed database role on all +affected databases, and local administrative permission on the local computer." +https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/add-spshelladmin?view=sharepoint-ps + Notes: 1.) If a content database is created using the Central Admin, the farm account is the owner of that content database in SQL Server. When this is true, you diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 index 000656adc..e32ba1696 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 @@ -29,13 +29,13 @@ function Get-TargetResource $InstallAccount ) - if ($ProviderRealms.Count -gt 0 -and ($ProviderRealmsToInclude.Count -gt 0 -or $ProviderRealmsToExclude.Count -gt 0)) + if ($ProviderRealms.Count -gt 0 -and ($ProviderRealmsToInclude.Count -gt 0 -or $ProviderRealmsToExclude.Count -gt 0)) { throw ("Cannot use the ProviderRealms parameter together with the " + ` "ProviderRealmsToInclude or ProviderRealmsToExclude parameters") } - if ($ProviderRealms.Count -eq 0 -and $ProviderRealmsToInclude.Count -eq 0 -and $ProviderRealmsToExclude.Count -eq 0) + if ($ProviderRealms.Count -eq 0 -and $ProviderRealmsToInclude.Count -eq 0 -and $ProviderRealmsToExclude.Count -eq 0) { throw ("At least one of the following parameters must be specified: " + ` "ProviderRealms, ProviderRealmsToInclude, ProviderRealmsToExclude") @@ -77,7 +77,7 @@ function Get-TargetResource $spTrust = Get-SPTrustedIdentityTokenIssuer -Identity $params.IssuerName ` -ErrorAction SilentlyContinue - if ($spTrust -eq $null) + if ($null -eq $spTrust) { throw ("SPTrustedIdentityTokenIssuer '$($params.IssuerName)' not found") } @@ -152,7 +152,7 @@ function Set-TargetResource $trust = Get-SPTrustedIdentityTokenIssuer -Identity $params.IssuerName ` -ErrorAction SilentlyContinue - if ($trust -eq $null) + if ($null -eq $trust) { throw ("SPTrustedIdentityTokenIssuer '$($params.IssuerName)' not found") } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index 6d9bce52c..6d71d5db0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -165,7 +165,8 @@ function Get-TargetResource } $upMySiteLocation = $null $upMySiteManagedPath = $null - try { + try + { $ca = Get-SPWebApplication -IncludeCentralAdministration | Where-Object -FilterScript {$_.IsAdministrationWebApplication} $caSite = $ca.Sites[0] $serviceContext = Get-SPServiceContext($caSite) @@ -173,7 +174,8 @@ function Get-TargetResource $upMySiteLocation = $userProfileManager.MySiteHostUrl $upMySiteManagedPath = $userProfileManager.PersonalSiteInclusion } - catch { + catch + { throw "The provided My Site Location is not a valid My Site Host." } diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index 538b705de..1fee6edec 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '2.3.0.0' +ModuleVersion = '2.4.0.0' # ID used to uniquely identify this module GUID = '6c1176a0-4fac-4134-8ca2-3fa8a21a7b90' @@ -128,27 +128,42 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = " - * Changes to SharePointDsc - * Added a Branches section to the README.md with Codecov and build badges for - both master and dev branch. - * All Resources - * Added information about the Resource Type in each ReadMe.md files. + * SPCacheAccounts + * Fixed issue where the Test method would fail if SetWebAppPolicy was set to + false. + * SPDistributedCacheService + * Updated resource to allow updating the cache size * SPFarm - * Fixed issue where the resource throws an exception if the farm already - exists and the server has been joined using the FQDN (issue 795) - * SPTimerJobState - * Fixed issue where the Set method for timerjobs deployed to multiple web - applications failed. + * Implemented ability to deploy Central Administration site to a server at a + later point in time + * SPInfoPathFormsServiceConfig + * Fixed issue with trying to set the MaxSizeOfUserFormState parameter + * SPProductUpdate + * Fixed an issue where the resource failed when the search was already paused + * SPProjectServerLicense + * Fixed issue with incorrect detection of the license + * SPSearchContentSource + * Fixed issue where the Get method returned a conversion error when the content + source contained just one address + * Fixed issue 840 where the parameter StartHour was never taken into account + * SPSearchServiceApp + * Fixed issue where the service account was not set correctly when the service + application was first created + * Fixed issue where the Get method throws an error when the service app wasn't + created properly + * SPSearchTopology + * Fixed issue where Get method threw an error when the specified service + application didn't exist yet. + * SPServiceAppSecurity + * Fixed issue where error was thrown when no permissions were set on the + service application + * SPShellAdmins + * Updated documentation to specify required permissions for successfully using + this resource * SPTrustedIdentityTokenIssuerProviderRealms - * Added the resource. + * Fixed code styling issues * SPUserProfileServiceApp - * Now supported specifying the host Managed path, and properly sets the host. - * Changed error for running with Farm Account into being a warning - * SPUserProfileSyncConnection - * Added support for filtering disabled users - * Fixed issue where UseSSL was set to true resulted in an error - * Fixed issue where the connection was recreated when the name contained a - dot (SP2016) + * Fixed code styling issues " } # End of PSData hashtable diff --git a/Modules/SharePointDsc/en-US/about_SPShellAdmins.help.txt b/Modules/SharePointDsc/en-US/about_SPShellAdmins.help.txt index d7978dd38..3af584384 100644 --- a/Modules/SharePointDsc/en-US/about_SPShellAdmins.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPShellAdmins.help.txt @@ -26,6 +26,16 @@ * Do not combine the ContentDatabase property with the AllContentDatabases property. + Required permissions: + + The documentation of the Shell Admin cmdlets states that you need the following + permissions to successfully run this resource: + "When you run this cmdlet to add a user to the SharePoint_Shell_Access role, + you must have membership in the securityadmin fixed server role on the SQL + Server instance, membership in the db_owner fixed database role on all + affected databases, and local administrative permission on the local computer." + https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/add-spshelladmin?view=sharepoint-ps + Notes: 1.) If a content database is created using the Central Admin, the farm account is the owner of that content database in SQL Server. When this is true, you diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 index bcdabd2a5..dcbc69133 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -19,38 +19,38 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope # Initialize tests - try - { - [Microsoft.SharePoint.Administration.SPPolicyRoleType] + try + { + [Microsoft.SharePoint.Administration.SPPolicyRoleType] } - catch + catch { Add-Type -TypeDefinition @" namespace Microsoft.SharePoint.Administration { public enum SPPolicyRoleType { FullRead, FullControl, DenyWrite, DenyAll }; -} +} "@ - } + } - # Mocks for all contexts - Mock -CommandName New-SPClaimsPrincipal -MockWith { + # Mocks for all contexts + Mock -CommandName New-SPClaimsPrincipal -MockWith { $Global:SPDscClaimsPrincipalUser = $Identity return ( New-Object -TypeName Object | Add-Member -MemberType ScriptMethod ` -Name "ToEncodedString" ` - -Value { - return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" + -Value { + return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" } -PassThru ) } -ParameterFilter { $IdentityType -eq "WindowsSamAccountName" } - - Mock -CommandName New-SPClaimsPrincipal -MockWith { + + Mock -CommandName New-SPClaimsPrincipal -MockWith { return @{ Value = $Identity -replace "i:0#.w|" } } -ParameterFilter { $IdentityType -eq "EncodedClaim" } - - # Test contexts + + # Test contexts Context -Name "The web application specified does not exist" -Fixture { $testParams = @{ WebAppUrl = "http://test.sharepoint.com" @@ -75,7 +75,7 @@ namespace Microsoft.SharePoint.Administration { } } - Context -Name "The specified cache accounts have not been configured" -Fixture { + Context -Name "The specified cache accounts have not been configured, Claims WebApp" -Fixture { $testParams = @{ WebAppUrl = "http://test.sharepoint.com" SuperUserAlias = "DEMO\SuperUser" @@ -86,7 +86,7 @@ namespace Microsoft.SharePoint.Administration { $policiesObject = New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name Add ` - -Value { + -Value { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty ` -Name PolicyRoleBindings ` @@ -97,7 +97,7 @@ namespace Microsoft.SharePoint.Administration { -Value {} ` -PassThru ) -PassThru - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod ` -Name Remove ` -Value {} ` @@ -146,6 +146,140 @@ namespace Microsoft.SharePoint.Administration { } } + Context -Name "The specified cache accounts have not been configured, non-claims WebApp" -Fixture { + $testParams = @{ + WebAppUrl = "http://test.sharepoint.com" + SuperUserAlias = "DEMO\SuperUser" + SuperReaderAlias = "DEMO\SuperReader" + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $policiesObject = New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name Add ` + -Value { + return New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name PolicyRoleBindings ` + -Value ( + New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name Add ` + -Value {} ` + -PassThru + ) -PassThru + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Remove ` + -Value {} ` + -PassThru + + return New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Properties ` + -Value @{} ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Policies ` + -Value $policiesObject ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name PolicyRoles ` + -Value ( + New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name GetSpecialRole ` + -Value { return @{} } ` + -PassThru + ) -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value {} ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name UseClaimsAuthentication ` + -Value $false ` + -PassThru + } + + It "Should return empty strings from the Get method" { + $results = Get-TargetResource @testParams + $results.SuperUserAlias | Should BeNullOrEmpty + $results.SuperReaderAlias | Should BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should update the accounts when set is called" { + Set-TargetResource @testParams + } + } + + Context -Name "The cache accounts have been configured correctly, SetWebAppPolicy set to False" -Fixture { + $testParams = @{ + WebAppUrl = "http://test.sharepoint.com" + SuperUserAlias = "DEMO\SuperUser" + SuperReaderAlias = "DEMO\SuperReader" + SetWebAppPolicy = $false + } + + Mock -CommandName Get-SPWebApplication -MockWith { + return New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Properties ` + -Value @{ + portalsuperuseraccount = $testParams.SuperUserAlias + portalsuperreaderaccount = $testParams.SuperReaderAlias + } -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Policies ` + -Value @( + @{ + UserName = $testParams.SuperUserAlias + }, + @{ + UserName = $testParams.SuperReaderAlias + }, + @{ + UserName = "i:0#.w|$($testParams.SuperUserAlias)" + }, + @{ + UserName = "i:0#.w|$($testParams.SuperReaderAlias)" + } + ) -PassThru | + Add-Member -MemberType NoteProperty ` + -Name PolicyRoles ` + -Value ( + New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name GetSpecialRole ` + -Value { + return @{} + } -PassThru + ) -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value {} ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name UseClaimsAuthentication ` + -Value $false ` + -PassThru + } + + It "Should return the values from the get method" { + $results = Get-TargetResource @testParams + $results.SuperUserAlias | Should Not BeNullOrEmpty + $results.SuperReaderAlias | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + Context -Name "The cache accounts have been configured correctly" -Fixture { $testParams = @{ WebAppUrl = "http://test.sharepoint.com" @@ -153,7 +287,7 @@ namespace Microsoft.SharePoint.Administration { SuperReaderAlias = "DEMO\SuperReader" } - Mock -CommandName Get-SPWebApplication -MockWith { + Mock -CommandName Get-SPWebApplication -MockWith { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty ` -Name Properties ` @@ -183,8 +317,8 @@ namespace Microsoft.SharePoint.Administration { New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name GetSpecialRole ` - -Value { - return @{} + -Value { + return @{} } -PassThru ) -PassThru | Add-Member -MemberType ScriptMethod ` @@ -215,7 +349,7 @@ namespace Microsoft.SharePoint.Administration { SuperReaderAlias = "DEMO\SuperReader" } - Mock -CommandName Get-SPWebApplication -MockWith { + Mock -CommandName Get-SPWebApplication -MockWith { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty -Name Properties @{ portalsuperuseraccount = $testParams.SuperUserAlias @@ -227,7 +361,7 @@ namespace Microsoft.SharePoint.Administration { New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name Add ` - -Value { + -Value { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty ` -Name PolicyRoleBindings ` @@ -238,7 +372,7 @@ namespace Microsoft.SharePoint.Administration { -Value {} ` -PassThru ) -PassThru - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod ` -Name Remove ` -Value {} ` @@ -250,8 +384,8 @@ namespace Microsoft.SharePoint.Administration { New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name GetSpecialRole ` - -Value { - return @{} + -Value { + return @{} } -PassThru ) -PassThru | Add-Member -MemberType ScriptMethod ` @@ -280,7 +414,7 @@ namespace Microsoft.SharePoint.Administration { SuperReaderAlias = "DEMO\SuperReader" } - Mock -CommandName Get-SPWebApplication -MockWith { + Mock -CommandName Get-SPWebApplication -MockWith { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty -Name Properties @{ portalsuperuseraccount = "WRONG\AccountName" @@ -290,7 +424,7 @@ namespace Microsoft.SharePoint.Administration { New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name Add ` - -Value { + -Value { return New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty ` -Name PolicyRoleBindings ` @@ -301,7 +435,7 @@ namespace Microsoft.SharePoint.Administration { -Value {} ` -PassThru ) -PassThru - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod ` -Name Remove ` -Value {} ` @@ -313,8 +447,8 @@ namespace Microsoft.SharePoint.Administration { New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name GetSpecialRole ` - -Value { - return @{} + -Value { + return @{} } -PassThru ) -PassThru | Add-Member -MemberType ScriptMethod ` diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 index 50f399e8c..6ae7170ed 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 @@ -36,7 +36,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName New-NetFirewallRule -MockWith { } Mock -CommandName Disable-NetFirewallRule -MockWith { } Mock -CommandName Add-SPDistributedCacheServiceInstance -MockWith { } - Mock Update-SPDistributedCacheSize -MockWith { } + Mock -CommandName Update-SPDistributedCacheSize -MockWith { } Mock -CommandName Get-SPManagedAccount -MockWith { return @{} } @@ -168,6 +168,98 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Distributed cache is not configured, waiting for stop of DC" -Fixture { + $testParams = @{ + Name = "AppFabricCache" + Ensure = "Present" + CacheSizeInMB = 1024 + ServiceAccount = "DOMAIN\user" + CreateFirewallRules = $true + } + + Mock Start-Sleep -MockWith {} + + Mock Use-CacheCluster -MockWith { + throw [Exception] "ERRPS001 Error in reading provider and connection string values." + } + Mock -CommandName Stop-SPServiceInstance -MockWith {} + Mock -CommandName Start-SPServiceInstance -MockWith {} + + Mock -CommandName Get-SPServiceInstance -MockWith { + switch ($Global:SPDscRunCount) + { + { 0,3,4,5 -contains $_ } + { + $Global:SPDscRunCount++ + return @(New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Status ` + -Value "Disabled" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Service ` + -Value "SPDistributedCacheService Name=AppFabricCachingService" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Server ` + -Value @{ + Name = $env:COMPUTERNAME + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {} ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SPDistributedCacheServiceInstance" ` + -PassThru + } -PassThru -Force) + } + { 1,2,6,7 -contains $_ } + { + $Global:SPDscRunCount = $Global:SPDscRunCount + 1 + return @(New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Status ` + -Value "Online" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Service ` + -Value "SPDistributedCacheService Name=AppFabricCachingService" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Server ` + -Value @{ + Name = $env:COMPUTERNAME + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {} ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SPDistributedCacheServiceInstance" ` + -PassThru + } -PassThru -Force) + } + } + } + + $Global:SPDscRunCount = 0 + It "Should set up the cache correctly" { + Set-TargetResource @testParams + Assert-MockCalled Add-SPDistributedCacheServiceInstance + } + } + Context -Name "Distributed cache is not configured, ServerProvisionOrder specified" -Fixture { $testParams = @{ Name = "AppFabricCache" @@ -282,6 +374,112 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Distributed cache is configured but the cachesize is incorrect" -Fixture { + $testParams = @{ + Name = "AppFabricCache" + Ensure = "Present" + CacheSizeInMB = 1024 + ServiceAccount = "DOMAIN\user" + CreateFirewallRules = $true + } + + $Global:SPDscDCacheOnline = $true + + Mock -CommandName Get-AFCacheHostConfiguration -MockWith { + return @{ + Size = 2048 + } + } + Mock -CommandName Get-CacheHost -MockWith { + return @{ + PortNo = 22233 + } + } + Mock -CommandName Start-Sleep -MockWith {} + + Mock -CommandName Get-SPServiceInstance -MockWith { + switch ($Global:SPDscRunCount) + { + { 0,3,4,5 -contains $_ } + { + $Global:SPDscRunCount++ + return @(New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Status ` + -Value "Disabled" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Service ` + -Value "SPDistributedCacheService Name=AppFabricCachingService" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Server ` + -Value @{ + Name = $env:COMPUTERNAME + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {} ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SPDistributedCacheServiceInstance" ` + -PassThru + } -PassThru -Force) + } + { 1,2,6,7 -contains $_ } + { + $Global:SPDscRunCount = $Global:SPDscRunCount + 1 + return @(New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Status ` + -Value "Online" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Service ` + -Value "SPDistributedCacheService Name=AppFabricCachingService" ` + -PassThru | + Add-Member -MemberType NoteProperty ` + -Name Server ` + -Value @{ + Name = $env:COMPUTERNAME + } -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {} ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "SPDistributedCacheServiceInstance" ` + -PassThru + } -PassThru -Force) + } + } + } + + $Global:SPDscRunCount = 0 + It "Should return CacheSizeInMB = 2048 from the get method" { + (Get-TargetResource @testParams).CacheSizeInMB | Should Be 2048 + } + + It "Should configure the distributed cache service cache size" { + Set-TargetResource @testParams + Assert-MockCalled Update-SPDistributedCacheSize + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + Context -Name "Distributed cache is configured but the required firewall rules are not deployed" -Fixture { $testParams = @{ Name = "AppFabricCache" @@ -301,7 +499,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Test-TargetResource @testParams | Should Be $false } - It "shuts down the distributed cache service" { + It "Should configure the firewall rules" { Set-TargetResource @testParams Assert-MockCalled Enable-NetFirewallRule } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 99603db4e..79b1ffce7 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -319,6 +319,186 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "Server is connected to farm, but Central Admin isn't started" -Fixture { + $testParams = @{ + Ensure = "Present" + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "sql.contoso.com" + FarmAccount = $mockFarmAccount + Passphrase = $mockPassphrase + AdminContentDatabaseName = "SP_AdminContent" + RunCentralAdmin = $true + } + + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + return "Connection string example" + } + + Mock -CommandName Get-SPFarm -MockWith { + return @{ + Name = $testParams.FarmConfigDatabaseName + DatabaseServer = @{ + Name = $testParams.DatabaseServer + } + AdminContentDatabaseName = $testParams.AdminContentDatabaseName + } + } + Mock -CommandName Get-SPDSCConfigDBStatus -MockWith { + return @{ + Locked = $false + ValidPermissions = $true + DatabaseExists = $true + } + } + Mock -CommandName Get-SPDatabase -MockWith { + return @(@{ + Name = $testParams.FarmConfigDatabaseName + Type = "Configuration Database" + NormalizedDataSource = $testParams.DatabaseServer + }) + } + Mock -CommandName Get-SPWebApplication -MockWith { + return @{ + IsAdministrationWebApplication = $true + ContentDatabases = @(@{ + Name = $testParams.AdminContentDatabaseName + }) + IISSettings = @(@{ + DisableKerberos = $true + }) + Url = "http://localhost:9999" + } + } + Mock -CommandName Get-CimInstance -MockWith { + return @{ + Domain = "domain.com" + } + } + + Mock -CommandName Get-SPServiceInstance -MockWith { + switch ($global:SPDscSIRunCount) + { + { 2 -contains $_ } + { + $global:SPDscSIRunCount++ + return @(@{ + TypeName = "Central Administration" + Status = "Online" + }) + } + { 0,1 -contains $_ } + { + $global:SPDscSIRunCount++ + return $null + } + } + } + + $global:SPDscSIRunCount = 0 + It "Should return false from the get method" { + (Get-TargetResource @testParams).RunCentralAdmin | Should Be $false + } + + $global:SPDscSIRunCount = 0 + It "Should start the central administration instance" { + Set-TargetResource @testParams + Assert-MockCalled -CommandName "Start-SPServiceInstance" + } + + $global:SPDscCentralAdminCheckDone = $false + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + } + + Context -Name "This server is connected to the farm and is running CA, but shouldn't" -Fixture { + $testParams = @{ + Ensure = "Present" + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "sql.contoso.com" + FarmAccount = $mockFarmAccount + Passphrase = $mockPassphrase + AdminContentDatabaseName = "SP_AdminContent" + RunCentralAdmin = $false + } + + Mock -CommandName "Get-SPDSCRegistryKey" -MockWith { + return "Connection string example" + } + + Mock -CommandName "Get-SPFarm" -MockWith { + return @{ + Name = $testParams.FarmConfigDatabaseName + DatabaseServer = @{ + Name = $testParams.DatabaseServer + } + AdminContentDatabaseName = $testParams.AdminContentDatabaseName + } + } + Mock -CommandName "Get-SPDSCConfigDBStatus" -MockWith { + return @{ + Locked = $false + ValidPermissions = $true + DatabaseExists = $true + } + } + Mock -CommandName "Get-SPDatabase" -MockWith { + return @(@{ + Name = $testParams.FarmConfigDatabaseName + Type = "Configuration Database" + NormalizedDataSource = $testParams.DatabaseServer + }) + } + Mock -CommandName "Get-SPWebApplication" -MockWith { + return @{ + IsAdministrationWebApplication = $true + ContentDatabases = @(@{ + Name = $testParams.AdminContentDatabaseName + }) + IISSettings = @(@{ + DisableKerberos = $true + }) + Url = "http://localhost:9999" + } + } + Mock -CommandName Start-Sleep -MockWith {} + Mock -CommandName Get-SPServiceInstance -MockWith { + switch ($global:SPDscSIRunCount) + { + { 0,2 -contains $_ } + { + $global:SPDscSIRunCount++ + return @(@{ + TypeName = "Central Administration" + Status = "Online" + }) + } + { 1 -contains $_ } + { + $global:SPDscSIRunCount++ + return $null + } + } + } + Mock -CommandName "Stop-SPServiceInstance" -MockWith {} + + $global:SPDscSIRunCount = 0 + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + $global:SPDscSIRunCount = 0 + It "Should return present from the get method" { + Set-TargetResource @testParams + Assert-MockCalled Stop-SPServiceInstance + } + + $global:SPDscSIRunCount = 0 + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $false + } + } + Context -Name "A config database exists, and this server is connected to it and should be" -Fixture { $testParams = @{ Ensure = "Present" @@ -369,6 +549,20 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Url = "http://localhost:9999" } } + Mock -CommandName "Get-SPServiceInstance" -MockWith { + if ($global:SPDscCentralAdminCheckDone -eq $true) + { + return @(@{ + TypeName = "Central Administration" + Status = "Online" + }) + } + else + { + $global:SPDscCentralAdminCheckDone = $true + return $null + } + } It "Should return present from the get method" { (Get-TargetResource @testParams).Ensure | Should Be "Present" @@ -699,13 +893,29 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName "Get-SPWebApplication" -MockWith { return $null } + Mock -CommandName "Get-SPServiceInstance" -MockWith { + if ($global:SPDscCentralAdminCheckDone -eq $true) + { + return @(@{ + TypeName = "Central Administration" + Status = "Online" + }) + } + else + { + $global:SPDscCentralAdminCheckDone = $true + return $null + } + } It "Should still return present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + $result = Get-TargetResource @testParams + $result.Ensure | Should Be "Present" + $result.RunCentralAdmin | Should BeNullOrEmpty } - It "Should still return true in the test method" { - Test-TargetResource @testParams | Should Be $true + It "Should return false in the test method" { + Test-TargetResource @testParams | Should Be $false } } @@ -770,6 +980,20 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Url = "http://localhost:9999" } } + Mock -CommandName "Get-SPServiceInstance" -MockWith { + if ($global:SPDscCentralAdminCheckDone -eq $true) + { + return @(@{ + TypeName = "Central Administration" + Status = "Online" + }) + } + else + { + $global:SPDscCentralAdminCheckDone = $true + return $null + } + } It "Should return present from the get method" { (Get-TargetResource @testParams).Ensure | Should Be "Present" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 index 4cf11e64b..e1e881c74 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -21,7 +21,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Mocks for all contexts Mock -CommandName Test-Path { return $true - } + } Mock -CommandName Get-Service -MockWith { $service = @{ @@ -29,19 +29,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $service = $service | Add-Member -MemberType ScriptMethod ` -Name Stop ` - -Value { + -Value { return $null - } -PassThru + } -PassThru $service = $service | Add-Member -MemberType ScriptMethod ` -Name Start ` - -Value { + -Value { return $null - } -PassThru + } -PassThru $service = $service | Add-Member -MemberType ScriptMethod ` -Name WaitForStatus ` - -Value { + -Value { return $null - } -PassThru + } -PassThru return $service } @@ -73,7 +73,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - # Test contexts + # Test contexts Context -Name "Specified update file not found" -Fixture { $testParams = @{ SetupFile = "C:\Install\CUMay2016\ubersrv2013-kb3115029-fullfile-x64-glb.exe" @@ -81,8 +81,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Ensure = "Present" } - Mock -CommandName Test-Path -MockWith { - return $false + Mock -CommandName Test-Path -MockWith { + return $false } It "Should throw exception in the get method" { @@ -105,7 +105,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Ensure = "Present" } - Mock -CommandName Test-Path -MockWith { + Mock -CommandName Test-Path -MockWith { return $true } @@ -152,7 +152,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -162,9 +162,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -172,16 +172,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2016-kb2880554-fullfile-x64-en-us.exe" - } + } } } - + Mock -CommandName Get-SPDscFarmProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } @@ -213,9 +213,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -223,16 +223,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2016-kb2880554-fullfile-x64-en-us.exe" - } + } } } - + Mock -CommandName Get-SPDscFarmProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } @@ -259,7 +259,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -269,9 +269,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -279,16 +279,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2016-kb2880554-fullfile-x64-en-us.exe" - } + } } } - + Mock -CommandName Get-SPDscFarmProductsInfo -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } @@ -321,7 +321,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -331,9 +331,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -341,7 +341,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Cumulative Update" } Name = "serverlpksp2016-kb2880554-fullfile-x64-en-us.exe" - } + } } } @@ -350,7 +350,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } @@ -383,7 +383,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -395,7 +395,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" } } - else + else { return @{ VersionInfo = @{ @@ -412,7 +412,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } @@ -434,7 +434,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -444,9 +444,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-en-us.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -454,7 +454,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-en-us.exe" - } + } } } @@ -463,17 +463,45 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013") } - else + else { return @("Microsoft SharePoint Server 2016") } } + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + $returnval = @{} + $returnval = $returnval | Add-Member -MemberType ScriptMethod ` + -Name IsPaused ` + -Value { + if ($Global:SPDscSearchPaused -eq $false) + { + return 0 + } + else + { + return 128 + } + } -PassThru -Force + $returnval = $returnval | Add-Member -MemberType ScriptMethod ` + -Name Pause ` + -Value { + $Global:SPDscSearchPaused = $true + } -PassThru -Force + $returnval = $returnval | Add-Member -MemberType ScriptMethod ` + -Name Resume ` + -Value { + $Global:SPDscSearchPaused = $false + } -PassThru -Force + return $returnval + } + It "Should return Ensure is Present from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } + $Global:SPDscSearchPaused = $false It "Should run the Start-Process function in the set method" { Set-TargetResource @testParams Assert-MockCalled Start-Process @@ -490,7 +518,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -500,9 +528,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-nl-nl.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -510,7 +538,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-nl-nl.exe" - } + } } } @@ -519,7 +547,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") } - else + else { return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") } @@ -551,9 +579,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-nl-nl.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -561,7 +589,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-nl-nl.exe" - } + } } } @@ -570,7 +598,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") } - else + else { return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") } @@ -597,7 +625,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -607,9 +635,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -626,7 +654,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") } - else + else { return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") } @@ -643,7 +671,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -653,9 +681,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-ab-yz.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -663,7 +691,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-ab-yz.exe" - } + } } } @@ -672,7 +700,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") } - else + else { return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") } @@ -689,7 +717,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -699,9 +727,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-fr-fr.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -709,7 +737,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-fr-fr.exe" - } + } } } @@ -718,7 +746,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { return @("Microsoft SharePoint Server 2013", "Language Pack for SharePoint and Project Server 2013 - Dutch/Nederlands") } - else + else { return @("Microsoft SharePoint Server 2016", "Language Pack for SharePoint and Project Server 2016 - Dutch/Nederlands") } @@ -735,7 +763,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ShutdownServices = $true Ensure = "Present" } - + Mock -CommandName Get-ItemProperty -MockWith { if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { @@ -745,9 +773,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2013-kb2880554-fullfile-x64-fr-fr.exe" - } + } } - else + else { return @{ VersionInfo = @{ @@ -755,7 +783,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { FileDescription = "Service Pack Language Pack" } Name = "serverlpksp2016-kb2880554-fullfile-x64-fr-fr.exe" - } + } } } @@ -789,7 +817,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should return null from the set method" { Set-TargetResource @testParams | Should BeNullOrEmpty } @@ -809,7 +837,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should return null from the set method" { Set-TargetResource @testParams | Should BeNullOrEmpty } @@ -829,7 +857,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should throw exception in the set method" { { Set-TargetResource @testParams } | Should Throw "Time window incorrectly formatted." } @@ -849,7 +877,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should throw exception in the set method" { { Set-TargetResource @testParams } | Should Throw "Error converting start time" } @@ -869,7 +897,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should throw exception in the set method" { { Set-TargetResource @testParams } | Should Throw "Error converting end time" } @@ -889,7 +917,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-Date -MockWith { return $testDate } - + It "Should throw exception in the set method" { { Set-TargetResource @testParams } | Should Throw "Error: Start time cannot be larger than end time" } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 index 0530d6002..ddb9e9241 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -18,7 +18,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope - switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) + switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) { 15 { Context -Name "All methods throw exceptions as Project Server support in SharePointDsc is only for 2016" -Fixture { @@ -46,17 +46,17 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-ProjectServerLicense -MockWith { - return "Project Server 2016 : Disabled" + return @("Project Server 2016 : Disabled", "Enabled date : 1/1/2000") } It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + (Get-TargetResource @testParams).Ensure | Should Be "Absent" } - + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } - + It "Should enable the license in the set method" { Set-TargetResource @testParams Assert-MockCalled Enable-ProjectServerLicense @@ -70,13 +70,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-ProjectServerLicense -MockWith { - return "Project Server 2016 : Active" + return @("Project Server 2016 : Active", "Enabled date : 1/1/2000") } It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } - + It "Should return true when the Test method is called" { Test-TargetResource @testParams | Should Be $true } @@ -88,17 +88,17 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-ProjectServerLicense -MockWith { - return "Project Server 2016 : Active" + return @("Project Server 2016 : Active", "Enabled date : 1/1/2000") } It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } - + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } - + It "Should enable the license in the set method" { Set-TargetResource @testParams Assert-MockCalled Disable-ProjectServerLicense @@ -111,13 +111,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-ProjectServerLicense -MockWith { - return "Project Server 2016 : Disabled" + return @("Project Server 2016 : Disabled", "Enabled date : 1/1/2000") } It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "absent" + (Get-TargetResource @testParams).Ensure | Should Be "absent" } - + It "Should return true when the Test method is called" { Test-TargetResource @testParams | Should Be $true } @@ -134,7 +134,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "absent" + (Get-TargetResource @testParams).Ensure | Should Be "absent" } } @@ -144,7 +144,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-ProjectServerLicense -MockWith { - return "Project Server 2016 : Disabled" + return @("Project Server 2016 : Disabled", "Enabled date : 1/1/2000") } It "Should throw an error in the set method" { diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 index 8e86ad82f..e63f0609c 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -33,19 +33,19 @@ namespace Microsoft.Office.Server.Search.Administration { Weekdays = 128, Weekends = 256, AllDays = 512 - } + } - public class DailySchedule { - public int RepeatDuration {get; set;} - public int RepeatInterval {get; set;} + public class DailySchedule { + public int RepeatDuration {get; set;} + public int RepeatInterval {get; set;} public int StartHour {get; set;} public int StartMinute {get; set;} public int DaysInterval {get; set;} } - public class WeeklySchedule { - public int RepeatDuration {get; set;} - public int RepeatInterval {get; set;} + public class WeeklySchedule { + public int RepeatDuration {get; set;} + public int RepeatInterval {get; set;} public int StartHour {get; set;} public int StartMinute {get; set;} public int WeeksInterval {get; set;} @@ -54,12 +54,196 @@ namespace Microsoft.Office.Server.Search.Administration { } "@ - # Mocks for all contexts + # Mocks for all contexts Mock -CommandName Start-Sleep -MockWith {} Mock -CommandName Set-SPEnterpriseSearchCrawlContentSource -MockWith {} Mock -CommandName Remove-SPEnterpriseSearchCrawlContentSource -MockWith {} # Test contexts + Context -Name "LimitPageDepth should not be used with Content Source Type SharePoint" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "SharePoint" + LimitPageDepth = 2 + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + } + } + + Context -Name "LimitServerHops should not be used with Content Source Type SharePoint" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "SharePoint" + LimitServerHops = 2 + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for SharePoint content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for SharePoint content sources" + } + } + + Context -Name "CrawlSetting=Custom should not be used with Content Source Type SharePoint" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "SharePoint" + Addresses = @("http://site.contoso.com") + CrawlSetting = "Custom" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + } + } + + Context -Name "LimitServerHops should not be used with Content Source Type Website" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "Website" + LimitServerHops = 2 + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for website content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for website content sources" + } + } + + Context -Name "ContinuousCrawl should not be used with Content Source Type SharePoint" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "Website" + ContinuousCrawl = $true + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter ContinuousCrawl is not valid for website content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter ContinuousCrawl is not valid for website content sources" + } + } + + Context -Name "ContinuousCrawl should not be used with Incremental Schedule" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "SharePoint" + ContinuousCrawl = $true + IncrementalSchedule = (New-CimInstance -ClassName MSFT_SPSearchCrawlSchedule -Property @{ + ScheduleType = "Weekly" + StartHour = "0" + StartMinute = "0" + CrawlScheduleDaysOfWeek = @("Monday", "Wednesday") + } -ClientOnly) + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "You can not specify an incremental crawl schedule on a content source that will use continous crawl" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "You can not specify an incremental crawl schedule on a content source that will use continous crawl" + } + } + + Context -Name "LimitPageDepth should not be used with Content Source Type FileShare" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "FileShare" + LimitPageDepth = 2 + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter LimitPageDepth is not valid for file share content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter LimitPageDepth is not valid for file share content sources" + } + } + + Context -Name "LimitServerHops should not be used with Content Source Type FileShare" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "FileShare" + LimitServerHops = 2 + Addresses = @("http://site.contoso.com") + CrawlSetting = "CrawlEverything" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for file share content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter LimitServerHops is not valid for file share content sources" + } + } + + Context -Name "CrawlSetting=Custom should not be used with Content Source Type FileShare" { + $testParams = @{ + Name = "Example content source" + ServiceAppName = "Search Service Application" + ContentSourceType = "FileShare" + Addresses = @("http://site.contoso.com") + CrawlSetting = "Custom" + Ensure = "Present" + } + + It "Should create the content source in the test method" { + { Test-TargetResource @testParams } | Should Throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + } + + It "Should create the content source in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter 'CrawlSetting' can only be set to custom for website content sources" + } + } + Context -Name "A SharePoint content source doesn't exist but should" { $testParams = @{ Name = "Example content source" @@ -90,24 +274,24 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should create the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName New-SPEnterpriseSearchCrawlContentSource Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A SharePoint content source does exist and should" { $testParams = @{ Name = "Example content source" @@ -133,17 +317,17 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return 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 "A SharePoint content source does exist and shouldn't" { $testParams = @{ Name = "Example content source" @@ -169,23 +353,23 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return present from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Present" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should remove the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName Remove-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A SharePoint content source doesn't exist and shouldn't" { $testParams = @{ Name = "Example content source" @@ -198,17 +382,17 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return $null } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } - + Context -Name "A SharePoint source that uses continuous crawl has incorrect settings applied" -Fixture { $testParams = @{ Name = "Example content source" @@ -235,23 +419,23 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should disable continuous crawl and then re-enable it when updating the content source" { Set-TargetResource @testParams - - Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { - $EnableContinuousCrawls -eq $false + + Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { + $EnableContinuousCrawls -eq $false } - Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { - $EnableContinuousCrawls -eq $true + Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { + $EnableContinuousCrawls -eq $true } } } - + Context -Name "A website content source doesn't exist but should" -Fixture { $testParams = @{ Name = "Example content source" @@ -280,24 +464,24 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should create the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName New-SPEnterpriseSearchCrawlContentSource Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A website content source does exist and should" -Fixture { $testParams = @{ Name = "Example content source" @@ -323,18 +507,18 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return 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 "A website content source does exist and shouldn't" -Fixture { + + Context -Name "A website content source does exist and shouldn't" -Fixture { $testParams = @{ Name = "Example content source" ServiceAppName = "Search Service Application" @@ -360,23 +544,23 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return present from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Present" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should remove the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName Remove-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A website content source doesn't exist and shouldn't" -Fixture { $testParams = @{ Name = "Example content source" @@ -390,17 +574,17 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return $null } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } - + Context -Name "A website content source has incorrect crawl depth settings applied" -Fixture { $testParams = @{ Name = "Example content source" @@ -427,18 +611,18 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should update the settings in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A file share content source doesn't exist but should" -Fixture { $testParams = @{ Name = "Example content source" @@ -466,24 +650,24 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should create the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName New-SPEnterpriseSearchCrawlContentSource Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A file share content source does exist and should" -Fixture { $testParams = @{ Name = "Example content source" @@ -509,17 +693,17 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return 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 "A file share content source does exist and shouldn't" -Fixture { $testParams = @{ Name = "Example content source" @@ -545,23 +729,23 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return present from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Present" } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should remove the content source in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName Remove-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A file share content source doesn't exist and shouldn't" -Fixture { $testParams = @{ Name = "Example content source" @@ -574,17 +758,17 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return $null } - + It "Should return absent from the get method" { $result = Get-TargetResource @testParams $result.Ensure | Should Be "Absent" } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } - + Context -Name "A file share content source has incorrect crawl depth settings applied" -Fixture { $testParams = @{ Name = "Example content source" @@ -609,18 +793,18 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should update the settings in the set method" { Set-TargetResource @testParams - + Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource } } - + Context -Name "A content source has a full schedule that does not match the desired schedule" -Fixture { $testParams = @{ Name = "Example content source" @@ -640,12 +824,21 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { $schedule = New-Object -TypeName Microsoft.Office.Server.Search.Administration.DailySchedule - $schedule.RepeatDuration = 1439 + $schedule.RepeatDuration = 1439 $schedule.RepeatInterval = 5 $schedule.StartHour = 0 $schedule.StartMinute = 0 $schedule.DaysInterval = 1 - return @{ + + if ($Global:SPDscContentSourceLoopCount -le 8) + { + $crawlStatus = "Running" + } + else + { + $crawlStatus = "Idle" + } + $returnval = @{ Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -657,20 +850,28 @@ namespace Microsoft.Office.Server.Search.Administration { IncrementalCrawlSchedule = $null FullCrawlSchedule = $schedule CrawlPriority = "Normal" - CrawlStatus = "Idle" + CrawlStatus = $crawlStatus } + $returnval = $returnval | Add-Member -MemberType ScriptMethod ` + -Name StopCrawl ` + -Value { + } -PassThru -Force + + $Global:SPDscContentSourceLoopCount++ + return $returnval } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + + $Global:SPDscContentSourceLoopCount = 0 It "Should update the schedule in the set method" { Set-TargetResource @testParams Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { $ScheduleType -eq "Full" } } } - + Context -Name "A content source has a full schedule that does match the desired schedule" -Fixture { $testParams = @{ Name = "Example content source" @@ -690,7 +891,7 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { $schedule = New-Object -TypeName Microsoft.Office.Server.Search.Administration.DailySchedule - $schedule.RepeatDuration = 1440 + $schedule.RepeatDuration = 1440 $schedule.RepeatInterval = 5 $schedule.StartHour = 0 $schedule.StartMinute = 0 @@ -710,12 +911,12 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } - + Context -Name "A content source has a incremental schedule that does not match the desired schedule" -Fixture { $testParams = @{ Name = "Example content source" @@ -752,17 +953,17 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should update the schedule in the set method" { Set-TargetResource @testParams Assert-MockCalled -CommandName Set-SPEnterpriseSearchCrawlContentSource -ParameterFilter { $ScheduleType -eq "Incremental" } } } - + Context -Name "A content source has a incremental schedule that does match the desired schedule" -Fixture { $testParams = @{ Name = "Example content source" @@ -799,7 +1000,7 @@ namespace Microsoft.Office.Server.Search.Administration { CrawlStatus = "Idle" } } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } diff --git a/appveyor.yml b/appveyor.yml index 1dd397448..112cc3c7d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.3.0.{build} +version: 2.4.0.{build} install: - git clone https://github.com/PowerShell/DscResource.Tests