diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d78752d..3dc0a5114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,54 @@ # Change log for SharePointDsc +## 1.7.0.0 + +* Update SPSearchIndexPartition made ServiceAppName as a Key +* New resouce: SPTrustedRootAuthority +* Update SPFarmSolution to eject from loop after 30m. +* New resource: SPMachineTranslationServiceApp +* New resource: SPPowerPointAutomationServiceApp +* Bugfix in SPSearchFileType made ServiceAppName a key property. +* New resource: SPWebApplicationExtension +* Added new resource SPAccessServices2010 +* Added MSFT_SPSearchCrawlMapping Resource to manage Crawl Mappings for + Search Service Application +* Added new resource SPSearchAuthoritativePage +* Bugfix in SPWebAppThrottlingSettings for setting large list window time. +* Fix typo in method Get-TargetResource of SPFeature +* Fix bug in SPManagedAccount not returning the correct account name value +* Fix typo in method Get-TargetResource of SPSearchIndexPartition +* Update documentation of SPInstallLanguagePack to add guidance on package + change in SP2016 +* Added returning the required RunCentralAdmin parameter to + Get-TargetResource in SPFarm +* Added web role check for SPBlobCacheSettings +* Improved error message when rule could not be found in + SPHealthAnalyzerRuleState +* Extended the documentation to specify that the default value of Ensure + is Present +* Added documentation about the user of Host Header Site Collections and + the HostHeader parameter in SPWebApplication +* Fixed missing brackets in SPWebAppPolicy module file +* Fixed issue with SPSecureStoreServiceApp not returning database information +* Fixed issue with SPManagedMetadataServiceApp not returning ContentTypeHubUrl + in SP2016 +* Updated SPTrustedIdentityTokenIssuer to allow to specify the signing + certificate from file path as an alternative to the certificate store +* New resource: SPSearchCrawlerImpactRule +* Fixed issue in SPSite where the used template wasn't returned properly +* Fixed issue in SPWebApplicationGeneralSettings which didn't return the + security validation timeout properly +* Fixed bug in SPCreateFarm and SPJoinFarm when a SharePoint Server is already + joined to a farm +* Bugfix in SPContentDatabase for setting WarningSiteCount as 0. +* Fixing verbose message that identifies SP2016 as 2013 in MSFT_SPFarm +* Fixed SPProductUpdate looking for OSearch15 in SP2016 when stopping services +* Added TermStoreAdministrators property to SPManagedMetadataServiceApp +* Fixed an issue in SPSearchTopology that would leave a corrupt topology in + place if a server was removed and re-added to a farm +* Fixed bug in SPFarm that caused issues with database names that have dashes + in the names + ## 1.6 * Updated SPWebApplication to allow Claims Authentication configuration diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServiceApp/readme.md index b86bf74ce..0cd04e512 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServiceApp/readme.md @@ -3,3 +3,6 @@ This resource is responsible for creating Access Services Application instances within the local SharePoint farm. The resource will provision and configure the Access Services Service Application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.psm1 new file mode 100644 index 000000000..286f9ddd7 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.psm1 @@ -0,0 +1,185 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting Access 2010 Service app '$Name'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $serviceApps = Get-SPServiceApplication -Name $params.Name ` + -ErrorAction SilentlyContinue + $nullReturn = @{ + Name = $params.Name + ApplicationPool = $params.ApplicationPool + Ensure = "Absent" + } + if($null -eq $serviceApps) + { + return $nullReturn + } + + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Access.Server.MossHost.AccessServerWebServiceApplication" + } + + if($null -eq $serviceApp) + { + return $nullReturn + } + else + { + return @{ + Name = $serviceApp.DisplayName + ApplicationPool = $serviceApp.ApplicationPool.Name + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting Access 2010 Services app '$Name'" + $result = Get-TargetResource @PSBoundParameters + + if($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + Write-Verbose "Creating Access 2010 Service Application '$Name'" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $accessApp = New-SPAccessServiceApplication -Name $params.Name ` + -ApplicationPool $params.ApplicationPool + } + } + if($result.Ensure -eq "Present" -and $Ensure -eq "Present") + { + Write-Verbose "Updating Access 2010 service application '$Name'" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $apps = Get-SPServiceApplication -Name $params.Name ` + -ErrorAction SilentlyContinue + if($null -ne $apps) + { + $app = $apps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Access.Server.MossHost.AccessServerWebServiceApplication" + } + if($null -ne $app) + { + $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool + if($null -ne $appPool) + { + $app.ApplicationPool = $appPool + $app.Update() + return; + } + } + } + + $accessApp = New-SPAccessServiceApplication -Name $params.Name ` + -ApplicationPool $params.ApplicationPool + } + } + if($Ensure -eq "Absent") + { + Write-Verbose "Removing Access 2010 service application '$Name'" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $apps = Get-SPServiceApplication -Name $params.Name ` + -ErrorAction SilentlyContinue + if($null -eq $apps) + { + return + } + + $app = $apps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Access.Server.MossHost.AccessServerWebServiceApplication" + } + + if($null -ne $app) + { + Remove-SPServiceApplication -Identity $app -Confirm:$false + } + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + Write-Verbose -Message "Testing Access 2010 service app '$Name'" + + $PSBoundParameters.Ensure = $Ensure + $CurrentValues = Get-TargetResource @PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Name", "ApplicationPool", "Ensure") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.schema.mof new file mode 100644 index 000000000..9d5e21e64 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAccessServices2010/MSFT_SPAccessServices2010.schema.mof @@ -0,0 +1,9 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("SPAccessServices2010")] +class MSFT_SPAccessServices2010 : OMI_BaseResource +{ + [Key, Description("The name of the service application")] String Name; + [Required, Description("The name of the application pool to run the service app in")] String ApplicationPool; + [Write, Description("Present ensures service app exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run thsi resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md index c23518a5e..636d2291c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md @@ -4,3 +4,6 @@ This resource is used to define an alternate access mapping URL for a specified web application. These can be assigned to specific zones for each web application. Alternatively a URL can be removed from a zone to ensure that it will remain empty and have no alternate URL. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the setting is configured. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAppManagementServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPAppManagementServiceApp/readme.md index f06b2704c..8ba228486 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPAppManagementServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAppManagementServiceApp/readme.md @@ -8,3 +8,6 @@ the application pool associated to the app if it does not match the configuration. Database names or server name will not be changed if the configuration does not match, these parameters are only used for the initial provisioning of the service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/readme.md index 5a1694fc7..4c286a5ed 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/readme.md @@ -8,3 +8,6 @@ account associated to the app if it does not match the configuration. Database names or server name will not be changed if the configuration does not match, these parameters are only used for the initial provisioning of the service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 index 2c2727e73..08f4fc804 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 @@ -45,6 +45,27 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] + $webappsi = Get-SPServiceInstance -Server $env:COMPUTERNAME ` + -ErrorAction SilentlyContinue ` + | Where-Object -FilterScript { + $_.TypeName -eq "Microsoft SharePoint Foundation Web Application" + } + + if ($null -eq $webappsi) + { + Write-Verbose -Message "Server isn't running the Web Application role" + return @{ + WebAppUrl = $null + Zone = $null + EnableCache = $false + Location = $null + MaxSizeInGB = $null + MaxAgeInSeconds = $null + FileTypes = $null + InstallAccount = $params.InstallAccount + } + } + $wa = Get-SPWebApplication -Identity $params.WebAppUrl ` -ErrorAction SilentlyContinue @@ -215,6 +236,17 @@ function Set-TargetResource $params = $args[0] $changes = $args[1] + $webappsi = Get-SPServiceInstance -Server $env:COMPUTERNAME ` + -ErrorAction SilentlyContinue ` + | Where-Object -FilterScript { + $_.TypeName -eq "Microsoft SharePoint Foundation Web Application" + } + + if ($null -eq $webappsi) + { + throw "Server isn't running the Web Application role" + } + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 index 6d68ce25f..cda6fa9a9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 @@ -257,7 +257,7 @@ function Set-TargetResource } # Check and change site count settings - if ($params.WarningSiteCount -and $params.WarningSiteCount -ne $cdb.WarningSiteCount) + if ($null -ne $params.WarningSiteCount -and $params.WarningSiteCount -ne $cdb.WarningSiteCount) { $cdb.WarningSiteCount = $params.WarningSiteCount } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md index abb4545d1..b41a0f47a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md @@ -5,3 +5,6 @@ and configure these databases. Note: The resource cannot be used to move the database to a different SQL instance. It will throw an error when it detects that the specified SQL instance is a different instance that is currently in use. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the content database is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 index 89c15a80d..f200ef86b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPCreateFarm/MSFT_SPCreateFarm.psm1 @@ -80,6 +80,20 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] + $getSPMajorVersion = (Get-SPDSCInstalledProductVersion).FileMajorPart + $cfgDbRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\$getSPMajorVersion.0\Secure\ConfigDB" + $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + $serverIsJoined = $true + + if ($null -eq $configDbDsn) + { + $serverIsJoined = $false + } + elseif (-NOT($configDbDsn.Contains($params.FarmConfigDatabaseName))) + { + $serverIsJoined = $false + } + try { $spFarm = Get-SPFarm @@ -89,7 +103,14 @@ function Get-TargetResource Write-Verbose -Message "Unable to detect local farm." } - if ($null -eq $spFarm) { return $null } + if ($null -eq $spFarm) + { + if ($serverIsJoined) + { + throw 'Server already joined to farm but SPFarm not reachable' + } + return $null + } $configDb = Get-SPDatabase | Where-Object -FilterScript { $_.Name -eq $spFarm.Name -and $_.Type -eq "Configuration Database" @@ -109,14 +130,14 @@ function Get-TargetResource } $returnValue = @{ - FarmConfigDatabaseName = $spFarm.Name - DatabaseServer = $configDb.Server.Name - FarmAccount = $farmAccount - InstallAccount = $params.InstallAccount - Passphrase = $params.Passphrase.password - AdminContentDatabaseName = $centralAdminSite.ContentDatabases[0].Name - CentralAdministrationPort = (New-Object -TypeName System.Uri $centralAdminSite.Url).Port - CentralAdministrationAuth = $params.CentralAdministrationAuth + FarmConfigDatabaseName = $spFarm.Name + DatabaseServer = $configDb.Server.Name + FarmAccount = $farmAccount + InstallAccount = $params.InstallAccount + Passphrase = $params.Passphrase.password + AdminContentDatabaseName = $centralAdminSite.ContentDatabases[0].Name + CentralAdministrationPort = (New-Object -TypeName System.Uri $centralAdminSite.Url).Port + CentralAdministrationAuth = $params.CentralAdministrationAuth } return $returnValue } @@ -217,10 +238,33 @@ function Set-TargetResource } Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -ScriptBlock { + $params = $args[0] + $scriptRoot = $args[1] + + $modulePath = "..\..\Modules\SharePointDsc.Farm\SPFarm.psm1" + Import-Module -Name (Join-Path -Path $scriptRoot -ChildPath $modulePath -Resolve) + $dbStatus = Get-SPDSCConfigDBStatus -SQLServer $params.DatabaseServer ` + -Database $params.FarmConfigDatabaseName + while ($dbStatus.Locked -eq $true) + { + Write-Verbose -Message ("[$([DateTime]::Now.ToShortTimeString())] The configuration " + ` + "database is currently being provisioned by a remote " + ` + "server, this server will wait for this to complete") + Start-Sleep -Seconds 30 + $dbStatus = Get-SPDSCConfigDBStatus -SQLServer $params.DatabaseServer ` + -Database $params.FarmConfigDatabaseName + } + + if ($dbStatus.ValidPermissions -eq $false) + { + throw "The current user does not have sufficient permissions to SQL Server" + return + } + $newFarmArgs = @{ DatabaseServer = $params.DatabaseServer DatabaseName = $params.FarmConfigDatabaseName diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/Readme.md index 9e3df22b0..6415f1198 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/Readme.md @@ -12,3 +12,6 @@ SP_Content* or *Content* Important: This resource requires the April 2014 CU to be installed. The required cmdlets have been added in this CU: http://support.microsoft.com/kb/2880551 + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the content database is added to the AAG. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/Readme.md index 2e6cadf4c..0c0d1e577 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/Readme.md @@ -19,3 +19,6 @@ By doing this you can ensure that you do not create conflicts with two or more servers provisioning a cache at the same time. Note, this approach only makes a server check the others for distributed cache, it does not provision the cache automatically on all servers. If a previous server in the sequence does + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the distributed cache is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/Readme.md index a804757c8..37f3cb872 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/Readme.md @@ -3,3 +3,6 @@ This resource is responsible for creating Excel Services Application instances within the local SharePoint farm. The resource will provision and configure the Excel Services Service Application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index e4fbe9eb4..98115073a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -75,7 +75,7 @@ function Get-TargetResource Write-Verbose -Message "Detected installation of SharePoint 2013" } 16 { - Write-Verbose -Message "Detected installation of SharePoint 2013" + Write-Verbose -Message "Detected installation of SharePoint 2016" } default { throw ("Detected an unsupported major version of SharePoint. SharePointDsc only " + ` @@ -148,6 +148,21 @@ function Get-TargetResource $farmAccount = $spFarm.DefaultServiceAccount.Name } + $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` + | Where-Object -FilterScript { + $_.IsAdministrationWebApplication -eq $true + } + + $centralAdminProvisioned = $false + $ca = Get-SPServiceInstance -Server $env:ComputerName ` + | Where-Object -Filterscript { + $_.TypeName -eq "Central Administration" -and $_.Status -eq "Online" + } + if ($null -ne $ca) + { + $centralAdminProvisioned = $true + } + $returnValue = @{ FarmConfigDatabaseName = $spFarm.Name DatabaseServer = $configDb.Server.Name @@ -155,6 +170,7 @@ function Get-TargetResource InstallAccount = $null Passphrase = $null AdminContentDatabaseName = $centralAdminSite.ContentDatabases[0].Name + RunCentralAdmin = $centralAdminProvisioned CentralAdministrationPort = (New-Object -TypeName System.Uri $centralAdminSite.Url).Port CentralAdministrationAuth = $params.CentralAdministrationAuth #TODO: Need to return this as the current value } @@ -177,6 +193,7 @@ function Get-TargetResource InstallAccount = $null Passphrase = $null AdminContentDatabaseName = $null + RunCentralAdmin = $null CentralAdministrationPort = $null CentralAdministrationAuth = $null Ensure = "Present" @@ -198,6 +215,7 @@ function Get-TargetResource InstallAccount = $null Passphrase = $null AdminContentDatabaseName = $null + RunCentralAdmin = $null CentralAdministrationPort = $null CentralAdministrationAuth = $null Ensure = "Absent" diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/readme.md index ff83612cb..864d6dfd8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/readme.md @@ -2,3 +2,6 @@ This resource is used to work with SharePoint Property Bags at the farm level. The account that runs this resource must be a farm administrator. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the property bag is configured. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/MSFT_SPFarmSolution.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/MSFT_SPFarmSolution.psm1 index 19aa44d30..8b10cb97e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/MSFT_SPFarmSolution.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/MSFT_SPFarmSolution.psm1 @@ -418,14 +418,19 @@ function Wait-SPDSCSolutionJob $solution = Get-SPSolution -Identity $params.Name -Verbose:$false -AssignmentCollection $gc - if ($solution.JobExists) + if ($solution.JobExists -eq $true) { Write-Verbose -Message "Waiting for solution '$($params.Name)'..." + $loopCount = 0 + while ($solution.JobExists -and $loopCount -lt 600) + { + $solution = Get-SPSolution -Identity $params.Name -Verbose:$false -AssignmentCollection $gc - while ($solution.JobExists){ Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting for a " + ` "job for solution '$($params.Name)' to complete") + $loopCount++ Start-Sleep -Seconds 5 + } Write-Verbose -Message "Result: $($solution.LastOperationResult)" diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/Readme.md index 4a763c88e..b917185b0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarmSolution/Readme.md @@ -6,3 +6,6 @@ application passing an array of URL's to the WebApplications property. If the solution contains resources scoped for web applications and no WebApplications are specified, the solution will be deployed to all web applications. If the solution does not contain resources scoped for web applications the property + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the solution is deployed. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/MSFT_SPFeature.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/MSFT_SPFeature.psm1 index 313e7191e..08af712c8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/MSFT_SPFeature.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/MSFT_SPFeature.psm1 @@ -64,7 +64,7 @@ function Get-TargetResource Name = $params.Name FeatureScope = $params.FeatureScope Url = $params.Url - InstalAccount = $params.InstallAccount + InstallAccount = $params.InstallAccount Ensure = $currentState Version = $featureAtScope.Version } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/Readme.md index 48032e0f5..4973dde53 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFeature/Readme.md @@ -4,3 +4,6 @@ This resource is used to make sure that a specific feature is either enabled or disabled at a given URL/scope. The Ensure property will dictate if the feature should be on or off. The name property is the name of the feature based on its folder name in the FEATURES folder in the SharePoint hive + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the feature is enabled. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 index 7060ebb40..a778f0c1b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 @@ -97,7 +97,8 @@ function Get-TargetResource } else { - Write-Verbose -Message "Unable to find specified Health Analyzer Rule" + Write-Verbose -Message ("Unable to find specified Health Analyzer Rule. Make " + ` + "sure any related service applications exists.") return $null } } @@ -209,7 +210,8 @@ function Set-TargetResource else { throw ("Could not find specified Health Analyzer Rule. Health Analyzer Rule " + ` - "settings will not be applied") + "settings will not be applied. Make sure any related service " + ` + "applications exists") return } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/Readme.md index 148d525f2..c9722b21b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/Readme.md @@ -2,5 +2,11 @@ This resource is used to install the SharePoint Language Pack binaries. The BinaryDir parameter should point to the path that setup.exe is located (not to -setup.exe itself). The BinaryInstallDays and BinaryInstallTime parameters -specify a window in which the update can be installed. This module depends on +setup.exe itself). + +The BinaryInstallDays and BinaryInstallTime parameters specify a window in which +the update can be installed. + +With SharePoint 2016, the Language Packs are offered as an EXE package. You have +to extract this package before installing, using the following command: +.\serverlanguagepack.exe /extract:[Extract Folder] diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPIrmSettings/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPIrmSettings/Readme.md index 704d9a21a..c137c4e29 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPIrmSettings/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPIrmSettings/Readme.md @@ -2,3 +2,6 @@ This resource is used to manipulate the IRM settings in SharePoint, integrating it with AD RMS + +The default value for the Ensure parameter is Present. When not specifying this +parameter, IRM is configured. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 index 8e9ea6f64..3dd0db88d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPJoinFarm/MSFT_SPJoinFarm.psm1 @@ -63,13 +63,31 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] + $getSPMajorVersion = (Get-SPDSCInstalledProductVersion).FileMajorPart + $cfgDbRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\$getSPMajorVersion.0\Secure\ConfigDB" + $configDbDsn = Get-SPDSCRegistryKey -Key $cfgDbRegKey -Value "dsn" + $serverIsJoined = $true + + if ($null -eq $configDbDsn) + { + $serverIsJoined = $false + } + elseif (-NOT($configDbDsn.Contains($params.FarmConfigDatabaseName))) + { + $serverIsJoined = $false + } + try { - $spFarm = Get-SPFarm -ErrorAction SilentlyContinue + $spFarm = Get-SPFarm } catch { Write-Verbose -Message "Unable to detect local farm." + if ($serverIsJoined) + { + throw 'Server already joined to farm but SPFarm not reachable' + } } if ($null -eq $spFarm) @@ -166,9 +184,32 @@ function Set-TargetResource } $result = Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -ScriptBlock { + $params = $args[0] + $scriptRoot = $args[1] + + $modulePath = "..\..\Modules\SharePointDsc.Farm\SPFarm.psm1" + Import-Module -Name (Join-Path -Path $scriptRoot -ChildPath $modulePath -Resolve) + $dbStatus = Get-SPDSCConfigDBStatus -SQLServer $params.DatabaseServer ` + -Database $params.FarmConfigDatabaseName + + while ($dbStatus.Locked -eq $true) + { + Write-Verbose -Message ("[$([DateTime]::Now.ToShortTimeString())] The configuration " + ` + "database is currently being provisioned by a remote " + ` + "server, this server will wait for this to complete") + Start-Sleep -Seconds 30 + $dbStatus = Get-SPDSCConfigDBStatus -SQLServer $params.DatabaseServer ` + -Database $params.FarmConfigDatabaseName + } + + if ($dbStatus.ValidPermissions -eq $false) + { + throw "The current user does not have sufficient permissions to SQL Server" + return + } try { $joinFarmArgs = @{ diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.psm1 new file mode 100644 index 000000000..a24ed5e93 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.psm1 @@ -0,0 +1,209 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseName, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseServer, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + Write-Verbose -Message "Getting Machine Translation Service Application '$Name'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue + + $nullReturn = @{ + Name = $params.Name + DatabaseName = $params.DatabaseName + DatabaseServer = $params.DatabaseServer + ApplicationPool = $params.ApplicationPool + Ensure = "Absent" + } + + if($null -eq $serviceApps) + { + return $nullReturn + } + + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.TranslationServices.TranslationServiceApplication" + } + + if($null -eq $serviceApp) + { + return $nullReturn + } + else { + return @{ + Name = $params.Name + DatabaseName = $($serviceApp.Database.Name) + DatabaseServer = $($serviceApp.Database.Server.Name) + ApplicationPool = $($serviceApp.ApplicationPool.Name) + Ensure = "Present" + } + } + + } + + return $result +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseName, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseServer, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose "Setting Machine Translation Service Application." + $CurrentValues = Get-TargetResource @PSBoundParameters + + if($CurrentValues.Ensure -eq "Present" -and $Ensure -eq "Present") + { + Write-Verbose "Resetting Machine Translation Service Application." + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $serviceApps = Get-SPServiceApplication -Identity $params.Name + + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.TranslationServices.TranslationServiceApplication" + } + + $serviceApp | Set-SPTranslationServiceApplication -ApplicationPool $params.ApplicationPool ` + -DatabaseName $params.DatabaseName ` + -DatabaseServer $params.DatabaseServer + } + } + if($CurrentValues.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + Write-Verbose "Creating Machine Translation Service Application." + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + New-SPTranslationServiceApplication -Name $params.Name ` + -DatabaseName $params.DatabaseName ` + -DatabaseServer $params.DatabaseServer ` + -ApplicationPool $params.ApplicationPool + } + } + if($Ensure -eq "Absent") + { + Write-Verbose "Removing Machine Translation Service Application." + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $serviceApps = Get-SPServiceApplication -Identity $params.Name + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.TranslationServices.TranslationServiceApplication" + } + $serviceApp | Remove-SPServiceApplication + + } + } +} + + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseName, + + [parameter(Mandatory = $true)] + [System.String] + $DatabaseServer, + + [parameter(Mandatory = $true)] + [System.String] + $ApplicationPool, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose "Test Machine Translation Service Application." + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + $params = $PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Name","ApplicationPool", + "DatabaseName","DatabaseServer", + "Ensure") + +} + + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.schema.mof new file mode 100644 index 000000000..35141dc8f --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPMachineTranslationServiceApp/MSFT_SPMachineTranslationServiceApp.schema.mof @@ -0,0 +1,12 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("SPMachineTranslationServiceApp")] +class MSFT_SPMachineTranslationServiceApp : OMI_BaseResource +{ + [Key, Description("Specifies the name of the service application.")] String Name; + [Required, Description("Specifies the name of the database for the service application.")] String DatabaseName; + [Required, Description("Specifies the name of the database server for the service application.")] String DatabaseServer; + [Required, Description("Specifies the application pool to use with the service application.")] String ApplicationPool; + [Write, Description("Present ensures service app exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 index fc14b09fc..8c23da600 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 @@ -41,7 +41,7 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] - $ma = Get-SPManagedAccount -Identity $params.Account.UserName ` + $ma = Get-SPManagedAccount -Identity $params.AccountName ` -ErrorAction SilentlyContinue if ($null -eq $ma) { diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/readme.md index 1d1fdee69..9e5a42233 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedAccount/readme.md @@ -6,3 +6,6 @@ and password) to set as the managed account. The settings for EmailNotification, PreExpireDays and Schedule all relate to enabling automatic password change for the managed account, leaving these option out of the resource will ensure that no automatic password changing from SharePoint occurs. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the managed account is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index 9ac2a6ef2..e9970d3a2 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -24,6 +24,10 @@ function Get-TargetResource [System.String] $DatabaseName, + [parameter(Mandatory = $false)] + [System.String[]] + $TermStoreAdministrators, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -48,9 +52,10 @@ function Get-TargetResource $serviceApps = Get-SPServiceApplication -Name $params.Name ` -ErrorAction SilentlyContinue $nullReturn = @{ - Name = $params.Name - Ensure = "Absent" - ApplicationPool = $params.ApplicationPool + Name = $params.Name + Ensure = "Absent" + ApplicationPool = $params.ApplicationPool + TermStoreAdministrators = @() } if ($null -eq $serviceApps) { @@ -84,13 +89,38 @@ function Get-TargetResource { $propertyFlags = [System.Reflection.BindingFlags]::Instance ` -bor [System.Reflection.BindingFlags]::NonPublic - - $propData = $serviceApp.GetType().GetMethods($propertyFlags) - $method = $propData | Where-Object -FilterScript { - $_.Name -eq "GetContentTypeSyndicationHubLocal" - } $defaultPartitionId = [Guid]::Parse("0C37852B-34D0-418e-91C6-2AC25AF4BE5B") - $hubUrl = $method.Invoke($serviceApp, $defaultPartitionId).AbsoluteUri + + $installedVersion = Get-SPDSCInstalledProductVersion + switch ($installedVersion.FileMajorPart) + { + 15 { + $propData = $serviceApp.GetType().GetMethods($propertyFlags) + $method = $propData | Where-Object -FilterScript { + $_.Name -eq "GetContentTypeSyndicationHubLocal" + } + $hubUrl = $method.Invoke($serviceApp, $defaultPartitionId).AbsoluteUri } + 16 { + $propData = $serviceApp.GetType().GetProperties($propertyFlags) + $dbMapperProp = $propData | Where-Object -FilterScript { + $_.Name -eq "DatabaseMapper" + } + + $dbMapper = $dbMapperProp.GetValue($serviceApp) + + $propData2 = $dbMapper.GetType().GetMethods($propertyFlags) + $cthubMethod = $propData2 | Where-Object -FilterScript { + $_.Name -eq "GetContentTypeSyndicationHubLocal" + } + + $hubUrl = $cthubMethod.Invoke($dbMapper, $defaultPartitionId).AbsoluteUri + } + default { + throw ("Detected an unsupported major version of SharePoint. " + ` + "SharePointDsc only supports SharePoint 2013 or 2016.") + } + } + if ($hubUrl) { $hubUrl = $hubUrl.TrimEnd('/') @@ -101,15 +131,41 @@ function Get-TargetResource $hubUrl = "" } + $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` + | Where-Object -FilterScript { + $_.IsAdministrationWebApplication -eq $true + } + $session = Get-SPTaxonomySession -Site $centralAdminSite.Url + + $currentAdmins = @() + + $session.TermStores[0].TermStoreAdministrators | ForEach-Object -Process { + $name = [string]::Empty + if ($_.IsWindowsAuthenticationMode -eq $true) + { + $name = $_.PrincipalName + } + else + { + $name = (New-SPClaimsPrincipal -Identity $_.PrincipalName -IdentityType EncodedClaim).Value + if ($name -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") + { + $name = Resolve-SPDscSecurityIdentifier -SID $name + } + } + $currentAdmins += $name + } + return @{ - Name = $serviceApp.DisplayName - ProxyName = $proxyName - Ensure = "Present" - ApplicationPool = $serviceApp.ApplicationPool.Name - DatabaseName = $serviceApp.Database.Name - DatabaseServer = $serviceApp.Database.Server.Name - ContentTypeHubUrl = $hubUrl - InstallAccount = $params.InstallAccount + Name = $serviceApp.DisplayName + ProxyName = $proxyName + Ensure = "Present" + ApplicationPool = $serviceApp.ApplicationPool.Name + DatabaseName = $serviceApp.Database.Name + DatabaseServer = $serviceApp.Database.Server.Name + TermStoreAdministrators = $currentAdmins + ContentTypeHubUrl = $hubUrl + InstallAccount = $params.InstallAccount } } } @@ -141,6 +197,10 @@ function Set-TargetResource [System.String] $DatabaseName, + [parameter(Mandatory = $false)] + [System.String[]] + $TermStoreAdministrators, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -175,6 +235,10 @@ function Set-TargetResource { $params.Remove("InstallAccount") | Out-Null } + if ($params.ContainsKey("TermStoreAdministrators")) + { + $params.Remove("TermStoreAdministrators") | Out-Null + } if ($params.ContainsKey("ContentTypeHubUrl")) { $params.Add("HubUri", $params.ContentTypeHubUrl) @@ -239,6 +303,58 @@ function Set-TargetResource } } } + + if ($Ensure -eq "Present" -and $PSBoundParameters.ContainsKey("TermStoreAdministrators") -eq $true) + { + # Update the term store administrators + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $result) ` + -ScriptBlock { + + Write-Verbose -Message "Setting term store administrators" + $params = $args[0] + $currentValues = $args[1] + + $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` + | Where-Object -FilterScript { + $_.IsAdministrationWebApplication -eq $true + } + $session = Get-SPTaxonomySession -Site $centralAdminSite.Url + $termStore = $session.TermStores[0] + + $changesToMake = Compare-Object -ReferenceObject $currentValues.TermStoreAdministrators ` + -DifferenceObject $params.TermStoreAdministrators + + $changesToMake | ForEach-Object -Process { + $change = $_ + switch($change.SideIndicator) + { + "<=" { + # remove an existing user + if ($termStore.TermStoreAdministrators.PrincipalName -contains $change.InputObject) + { + $termStore.DeleteTermStoreAdministrator($change.InputObject) + } + else + { + $claimsToken = New-SPClaimsPrincipal -Identity $change.InputObject ` + -IdentityType WindowsSamAccountName + $termStore.DeleteTermStoreAdministrator($claimsToken.ToEncodedString()) + } + } + "=>" { + # add a new user + $termStore.AddTermStoreAdministrator($change.InputObject) + } + default { + throw "An unknown side indicator was found." + } + } + } + + $termStore.CommitAll(); + } + } if ($Ensure -eq "Absent") { @@ -294,6 +410,10 @@ function Test-TargetResource [System.String] $DatabaseName, + [parameter(Mandatory = $false)] + [System.String[]] + $TermStoreAdministrators, + [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] @@ -322,6 +442,7 @@ function Test-TargetResource -DesiredValues $PSBoundParameters ` -ValuesToCheck @("ApplicationPool", "ContentTypeHubUrl", + "TermStoreAdministrators", "Ensure") } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof index d8e598f39..4bd75d903 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof @@ -6,6 +6,7 @@ class MSFT_SPManagedMetaDataServiceApp : OMI_BaseResource [Required, Description("The application pool that the service app will use")] string ApplicationPool; [Write, Description("The name of the database server which will host the application")] string DatabaseServer; [Write, Description("The name of the database for the service application")] string DatabaseName; + [Write, Description("A list of the users/groups who are administrators of the term store")] string TermStoreAdministrators[]; [Write, Description("Present ensures service app exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; [Write, Description("The URL of the content type hub for this app (only set when the app is provisioned)")] string ContentTypeHubUrl; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md index 3294798e4..be81d1353 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md @@ -5,3 +5,6 @@ specifies which application pool it should use, and will reset the application back to this pool if it is changed after its initial provisioning. The database server and database name properties are only used during provisioning, and will not be altered as part of the ongoing operation of the + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedPath/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedPath/readme.md index 860221094..6746d5522 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedPath/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedPath/readme.md @@ -7,3 +7,6 @@ set the URL. Explicit when set to true will create an explicit inclusion path, if set to false the path is created as wildcard inclusion. If you are using host named site collections set HostHeader to true and the path will be created as a host header path to be applied for host named site collections. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the managed path is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md index de18f2242..046459a2d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md @@ -8,3 +8,6 @@ NOTE: This resource is designed to be used where all WOPI bindings will be targeted to the same Office Online Server farm. If used on a clean environment, the new bindings will all point to the one DNS Name. If used on an existing configuration that does not follow this rule, it will match only + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the zone is configured. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPPerformancePointServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPPerformancePointServiceApp/readme.md index 42eb7f073..723aa7bf7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPPerformancePointServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPPerformancePointServiceApp/readme.md @@ -3,3 +3,6 @@ This resource is responsible for creating Performance Point Service Application instances within the local SharePoint farm. The resource will provision and configure the Performance Point Service Application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 new file mode 100644 index 000000000..ade4557eb --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 @@ -0,0 +1,390 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.String] + $ProxyName, + + [System.String] + $ApplicationPool, + + [System.UInt32] + $CacheExpirationPeriodInSeconds, + + [System.UInt32] + $MaximumConversionsPerWorker, + + [System.UInt32] + $WorkerKeepAliveTimeoutInSeconds, + + [System.UInt32] + $WorkerProcessCount, + + [System.UInt32] + $WorkerTimeoutInSeconds, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting PowerPoint Automation service app '$Name'" + + if(($ApplicationPool ` + -or $ProxyName ` + -or $CacheExpirationPeriodInSeconds ` + -or $MaximumConversionsPerWorker ` + -or $WorkerKeepAliveTimeoutInSeconds ` + -or $WorkerProcessCount ` + -or $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) + { + throw "You cannot use any of the parameters when Ensure is specified as Absent" + } + if (($Ensure -eq "Present") -and -not $ApplicationPool) + { + throw ("An Application Pool is required to configure the PowerPoint " + ` + "Automation Service Application") + } + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $serviceApps = Get-SPServiceApplication -Name $params.Name ` + -ErrorAction SilentlyContinue + $nullReturn = @{ + Name = $params.Name + Ensure = "Absent" + ApplicationPool = $params.ApplicationPool + } + + if ($null -eq $serviceApps) + { + return $nullReturn + } + + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Server.PowerPoint.Administration.PowerPointConversionServiceApplication" + } + + if ($null -eq $serviceApp) + { + return $nullReturn + } + + $proxyName = "" + $serviceAppProxies = Get-SPServiceApplicationProxy -ErrorAction SilentlyContinue + if ($null -ne $serviceAppProxies) + { + $serviceAppProxy = $serviceAppProxies | Where-Object -FilterScript { + $serviceApp.IsConnected($_) + } + if ($null -ne $serviceAppProxy) + { + $proxyName = $serviceAppProxy.Name + } + } + + $returnVal = @{ + Name = $serviceApp.DisplayName + ProxyName = $proxyName + ApplicationPool = $serviceApp.ApplicationPool.Name + CacheExpirationPeriodInSeconds = $serviceApp.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $serviceApp.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $serviceApp.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $serviceApp.WorkerProcessCount + WorkerTimeoutInSeconds = $serviceApp.WorkerTimeoutInSeconds + Ensure = "Present" + InstallAccount = $params.InstallAccount + + } + return $returnVal + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.String] + $ProxyName, + + [System.String] + $ApplicationPool, + + [System.UInt32] + $CacheExpirationPeriodInSeconds, + + [System.UInt32] + $MaximumConversionsPerWorker, + + [System.UInt32] + $WorkerKeepAliveTimeoutInSeconds, + + [System.UInt32] + $WorkerProcessCount, + + [System.UInt32] + $WorkerTimeoutInSeconds, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting PowerPoint Automation service app '$Name'" + + if(($ApplicationPool ` + -or $ProxyName ` + -or $CacheExpirationPeriodInSeconds ` + -or $MaximumConversionsPerWorker ` + -or $WorkerKeepAliveTimeoutInSeconds ` + -or $WorkerProcessCount ` + -or $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) + { + throw "You cannot use any of the parameters when Ensure is specified as Absent" + } + if (($Ensure -eq "Present") -and -not $ApplicationPool) + { + throw ("An Application Pool is required to configure the PowerPoint " + ` + "Automation Service Application") + } + + $result = Get-TargetResource @PSBoundParameters + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + Write-Verbose -Message "Creating PowerPoint Automation Service Application $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $proxyName = $params.ProxyName + if($null -eq $proxyName) + { + $proxyName = "$($params.Name) Proxy" + } + + $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool + if($appPool) + { + $serviceApp = New-SPPowerPointConversionServiceApplication -Name $params.Name -ApplicationPool $params.ApplicationPool + $serviceAppProxy = New-SPPowerPointConversionServiceApplicationProxy -name $proxyName -ServiceApplication $serviceApp + + if($null -ne $params.CacheExpirationPeriodInSeconds) + { + $serviceApp.CacheExpirationPeriodInSeconds = $params.CacheExpirationPeriodInSeconds + } + if($null -ne $params.MaximumConversionsPerWorker) + { + $serviceApp.MaximumConversionsPerWorker = $params.MaximumConversionsPerWorker + } + if($null -ne $params.WorkerKeepAliveTimeoutInSeconds) + { + $serviceApp.WorkerKeepAliveTimeoutInSeconds = $params.WorkerKeepAliveTimeoutInSeconds + } + if($null -ne $params.WorkerProcessCount) + { + $serviceApp.WorkerProcessCount = $params.WorkerProcessCount + } + if($null -ne $params.WorkerTimeoutInSeconds) + { + $serviceApp.WorkerTimeoutInSeconds = $params.WorkerTimeoutInSeconds + } + $serviceApp.Update(); + } + else + { + throw "Specified application pool does not exist" + } + } + } + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + { + Write-Verbose -Message "Updating PowerPoint Automation Service Application $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters, $result ` + -ScriptBlock { + $params = $args[0] + $result = $args[1] + + $serviceApps = Get-SPServiceApplication -Name $params.Name ` + -ErrorAction SilentlyContinue + if($null -eq $serviceApps) + { + throw "No Service applications are available in the farm." + } + $serviceApp = $serviceApps ` + | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Server.PowerPoint.Administration.PowerPointConversionServiceApplication" + } + if($null -eq $serviceApp) + { + throw "Unable to find specified service application." + } + if ([string]::IsNullOrEmpty($params.ApplicationPool) -eq $false ` + -and $params.ApplicationPool -ne $result.ApplicationPool) + { + $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool + if($null -eq $appPool) + { + throw "The specified App Pool does not exist" + } + $serviceApp.ApplicationPool = $appPool + } + if([string]::IsNullOrEmpty($params.ProxyName) -eq $false ` + -and $params.ProxyName -ne $result.ProxyName) + { + $proxies = Get-SPServiceApplicationProxy + foreach($proxyInstance in $proxies) + { + if($serviceApp.IsConnected($proxyInstance)) + { + $proxyInstance.Delete() + } + } + $serviceAppProxy = New-SPPowerPointConversionServiceApplicationProxy -Name $params.proxyName -ServiceApplication $serviceApp + } + if($null -ne $params.CacheExpirationPeriodInSeconds) + { + $serviceApp.CacheExpirationPeriodInSeconds = $params.CacheExpirationPeriodInSeconds + } + if($null -ne $params.MaximumConversionsPerWorker) + { + $serviceApp.MaximumConversionsPerWorker = $params.MaximumConversionsPerWorker + } + if($null -ne $params.WorkerKeepAliveTimeoutInSeconds) + { + $serviceApp.WorkerKeepAliveTimeoutInSeconds = $params.WorkerKeepAliveTimeoutInSeconds + } + if($null -ne $params.WorkerProcessCount) + { + $serviceApp.WorkerProcessCount = $params.WorkerProcessCount + } + if($null -ne $params.WorkerTimeoutInSeconds) + { + $serviceApp.WorkerTimeoutInSeconds = $params.WorkerTimeoutInSeconds + } + $serviceApp.Update(); + } + } + if($Ensure -eq "Absent") + { + Write-Verbose -Message "Removing PowerPoint Automation Service Application $Name" + Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { + $params = $args[0] + + $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue + if($null -eq $serviceApps) + { + return; + } + $serviceApp = $serviceApps | Where-Object -FilterScript { + $_.GetType().FullName -eq "Microsoft.Office.Server.PowerPoint.Administration.PowerPointConversionServiceApplication" + } + if ($null -ne $serviceApp) + { + $proxies = Get-SPServiceApplicationProxy + foreach($proxyInstance in $proxies) + { + if($serviceApp.IsConnected($proxyInstance)) + { + $proxyInstance.Delete() + } + } + Remove-SPServiceApplication -Identity $serviceApp -Confirm:$false + } + } + } +} + + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.String] + $ProxyName, + + [System.String] + $ApplicationPool, + + [System.UInt32] + $CacheExpirationPeriodInSeconds, + + [System.UInt32] + $MaximumConversionsPerWorker, + + [System.UInt32] + $WorkerKeepAliveTimeoutInSeconds, + + [System.UInt32] + $WorkerProcessCount, + + [System.UInt32] + $WorkerTimeoutInSeconds, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing PowerPoint Automation service app '$Name'" + if(($ApplicationPool ` + -or $ProxyName ` + -or $CacheExpirationPeriodInSeconds ` + -or $MaximumConversionsPerWorker ` + -or $WorkerKeepAliveTimeoutInSeconds ` + -or $WorkerProcessCount ` + -or $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) + { + throw "You cannot use any of the parameters when Ensure is specified as Absent" + } + if (($Ensure -eq "Present") -and -not $ApplicationPool) + { + throw ("An Application Pool is required to configure the PowerPoint " + ` + "Automation Service Application") + } + $CurrentValues = Get-TargetResource @PSBoundParameters + + if($Ensure -eq "Absent") + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters + } +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.schema.mof new file mode 100644 index 000000000..275d6d545 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.schema.mof @@ -0,0 +1,14 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPPowerPointAutomationServiceApp")] +class MSFT_SPPowerPointAutomationServiceApp : OMI_BaseResource +{ + [Key, Description("The name of the service application")] String Name; + [Write, Description("The name of the service application proxy")] String ProxyName; + [Write, Description("The name of the application pool to run the service app in")] String ApplicationPool; + [Write, Description("Specifies the maximum time, in seconds, that items remain in the back-end server cache. The default value is 600 seconds (10 minutes).")] Uint32 CacheExpirationPeriodInSeconds; + [Write, Description("Specifies the maximum number of presentations that a conversion worker process can convert before recycling. The default value is 5.")] Uint32 MaximumConversionsPerWorker; + [Write, Description("Specifies the maximum time, in seconds, that a conversion worker process can be unresponsive before being terminated. The default value is 120 seconds.")] Uint32 WorkerKeepAliveTimeoutInSeconds; + [Write, Description("Specifies the number of active instances of the conversion worker process on each back-end. This value must be less than the Windows Communication Foundation (WCF) connection limit for this computer. The default value is 3.")] Uint32 WorkerProcessCount; + [Write, Description("Specifies the maximum time, in seconds, that a conversion worker process is given for any single conversion. The default is 300 seconds (5 minutes).")] Uint32 WorkerTimeoutInSeconds; + [Write, Description("Ensure the crawl rule is Present or Absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run thsi resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index b3f969e6a..223542d47 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -338,7 +338,16 @@ function Set-TargetResource $osearchStopped = $false $hostControllerStopped = $false - $osearchSvc = Get-Service -Name "OSearch15" + if ((Get-SPDSCInstalledProductVersion) -eq 15) + { + $searchServiceName = "OSearch15" + } + else + { + $searchServiceName = "OSearch16" + } + + $osearchSvc = Get-Service -Name $searchServiceName $hostControllerSvc = Get-Service -Name "SPSearchHostController" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -354,7 +363,7 @@ function Set-TargetResource if($osearchSvc.Status -eq "Running") { $osearchStopped = $true - Set-Service -Name "OSearch15" -StartupType Disabled + Set-Service -Name $searchServiceName -StartupType Disabled $osearchSvc.Stop() } @@ -432,13 +441,13 @@ function Set-TargetResource -Wait ` -PassThru - $osearchSvc = Get-Service -Name "OSearch15" + $osearchSvc = Get-Service -Name $searchServiceName $hostControllerSvc = Get-Service -Name "SPSearchHostController" # Ensuring Search Services were stopped by script before Starting" if($osearchStopped -eq $true) { - Set-Service -Name "OSearch15" -StartupType Manual + Set-Service -Name $searchServiceName -StartupType Manual $osearchSvc.Start() } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/readme.md index 7194ebb42..a2b7e7508 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/readme.md @@ -14,3 +14,6 @@ You can publish the following service applications in a SharePoint Server * User Profile * Search * Secure Store + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/readme.md index d1c759731..890978ff7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/readme.md @@ -3,3 +3,6 @@ This resource is used to configure quota templates in the farm. These settings will be used to make sure a certain quota template exists or not. When it exists, it will also make sure the settings are configured as specified. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the quota template is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/readme.md index 1072c0e10..74bc5ce13 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPRemoteFarmTrust/readme.md @@ -3,3 +3,6 @@ This resource is used to trust a remote SharePoint farm. This is used when federating search results between two different SharePoint farms. The technique is described at + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the remote farm trust is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 new file mode 100644 index 000000000..bb81bb92d --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 @@ -0,0 +1,297 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Path, + + [ValidateRange(0.0, 2.0)] + [System.Single] + $Level, + + [ValidateSet("Authoratative","Demoted")] + [System.String] + $Action, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting Authoratative Page Setting for '$Path'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $nullReturn = @{ + ServiceAppName = $params.ServiceAppName + Path = "" + Level = $params.Level + Action = $params.Action + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $serviceApp) + { + return $nullReturn + } + + $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa + $searchOwner = New-Object -TypeName "Microsoft.Office.Server.Search.Administration.SearchObjectOwner" -ArgumentList $searchObjectLevel + + if($params.Action -eq "Authoratative") + { + + $queryAuthority = Get-SPEnterpriseSearchQueryAuthority -Identity $params.Path ` + -Owner $searchOwner ` + -SearchApplication $serviceApp ` + -ErrorAction SilentlyContinue + if($null -eq $queryAuthority) + { + return $nullReturn + } + else + { + + return @{ + ServiceAppName = $params.ServiceAppName + Path = $params.Path + Level = $queryAuthority.Level + Action = $params.Action + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + } + else + { + $queryDemoted = $serviceApp | Get-SPEnterpriseSearchQueryDemoted -Identity $params.Path ` + -Owner $searchOwner ` + -SearchApplication $serviceApp ` + -ErrorAction SilentlyContinue + if($null -eq $queryDemoted) + { + return $nullReturn + } + else + { + return @{ + ServiceAppName = $params.ServiceAppName + Path = $params.Path + Action = $params.Action + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + } + + } + return $result + +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Path, + + [ValidateRange(0.0, 2.0)] + [System.Single] + $Level, + + [ValidateSet("Authoratative","Demoted")] + [System.String] + $Action, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting Authoratative Page Settings for '$Path'" + + $CurrentResults = Get-TargetResource @PSBoundParameters + + if($CurrentResults.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa + $searchOwner = New-Object -TypeName "Microsoft.Office.Server.Search.Administration.SearchObjectOwner" -ArgumentList $searchObjectLevel + + if($null -eq $serviceApp) + { + throw "Search Service App was not available." + } + if($params.Action -eq "Authoratative") + { + New-SPEnterpriseSearchQueryAuthority -Url $params.Path ` + -SearchApplication $serviceApp ` + -Owner $searchOwner ` + -Level $params.Level + } + else + { + New-SPEnterpriseSearchQueryDemoted -Url $params.Path -SearchApplication $serviceApp -Owner $searchOwner + } + } + } + if($CurrentResults.Ensure -eq "Present" -and $Ensure -eq "Present") + { + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa + $searchOwner = New-Object -TypeName "Microsoft.Office.Server.Search.Administration.SearchObjectOwner" -ArgumentList $searchObjectLevel + + if($null -eq $serviceApp) + { + throw "Search Service App was not available." + } + + if($params.Action -eq "Authoratative") + { + Set-SPEnterpriseSearchQueryAuthority -Identity $params.ServiceAppName ` + -SearchApplication $ssa ` + -Owner $searchOwner ` + -Level $params.Level + } + } + } + if($Ensure -eq "Absent") + { + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa + $searchOwner = New-Object -TypeName "Microsoft.Office.Server.Search.Administration.SearchObjectOwner" -ArgumentList $searchObjectLevel + + if($null -eq $serviceApp) + { + throw "Search Service App was not available." + } + if($params.Action -eq "Authoratative") + { + Remove-SPEnterpriseSearchQueryAuthority -Identity $params.ServiceAppName ` + -SearchApplication $ssa ` + -Owner $searchOwner ` + -ErrorAction SilentlyContinue + } + else + { + Remove-SPEnterpriseSearchQueryDemoted -Identity $params.ServiceAppName ` + -SearchApplication $ssa ` + -Owner $searchOwner ` + -ErrorAction SilentlyContinue + } + } + } +} + + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Path, + + [ValidateRange(0.0, 2.0)] + [System.Single] + $Level, + + [ValidateSet("Authoratative","Demoted")] + [System.String] + $Action, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing Authoratative Page Settings '$Path'" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + if($Ensure -eq "Present") + { + if($Action -eq "Authoratative") + { + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName", + "Path", + "Level", + "Action", + "Ensure") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName", + "Path", + "Action", + "Ensure") + } + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName", + "Action", + "Ensure") + } +} + +Export-ModuleMember -Function *-TargetResource + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.schema.mof new file mode 100644 index 000000000..894d1f50f --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.schema.mof @@ -0,0 +1,10 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPSearchAuthoritativePage")] +class MSFT_SPSearchAuthoritativePage : OMI_BaseResource +{ + [Key, Description("Search Service Application Name")] String ServiceAppName; + [Key, Description("Source URI for the authoritative page")] String Path; + [Write, Description("Level of Authoratitive Page, values between 0.0 and 2.0")] Real32 Level; + [Write, Description("The resource will either make the page authoritative or demoted based on this value"), ValueMap{"Authoratative","Demoted"}, Values{"Authoratative","Demoted"}] String Action; + [Write, Description("Ensure the Authoritative is Present or Absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/readme.md index 49d6e2521..2f6f4060a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/readme.md @@ -2,3 +2,6 @@ This resource will deploy and configure a content source in a specified search service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the content source is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 new file mode 100644 index 000000000..4a32d344b --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 @@ -0,0 +1,225 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [System.String] + $Target, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting Search Crawl Mapping for '$Url'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + + $params = $args[0] + $searchApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $searchApp) + { + Write-Verbose -Message "Search Service Application $($params.ServiceAppName) not found" + $returnVal = @{ + ServiceAppName = "" + Url = $params.Url + Target = "" + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + return $returnVal + } + + $mappings = $searchApp | Get-SPEnterpriseSearchCrawlMapping + + if($null -eq $mappings) + { + Write-Verbose -Message "Search Service Application $($params.ServiceAppName) has no mappings" + $returnVal = @{ + ServiceAppName = $params.ServiceAppName + Url = $params.Url + Target = "" + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + return $returnVal + } + + $mapping = $mappings | Where-Object -FilterScript { $_.Source -eq "$($params.Url)" } | Select-Object -First 1 + + if($null -eq $mapping) + { + Write-Verbose "Search Service Application $($params.ServiceAppName) has no matching mapping" + $returnVal = @{ + ServiceAppName = $params.ServiceAppName + Url = $params.Url + Target = "" + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + return $returnVal + } + else + { + Write-Verbose "Search Service Application $($params.ServiceAppName) has a matching mapping" + $returnVal = @{ + ServiceAppName = $params.ServiceAppName + Url = $mapping.Source + Target = $mapping.Target + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + return $returnVal + + } + + } + + return $result + +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [System.String] + $Target, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + Write-Verbose -Message "Setting Search Crawl Mapping Rule '$Url'" + $result = Get-TargetResource @PSBoundParameters + + if($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + Write-Verbose "Adding the Crawl Mapping '$Url'" + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $searchApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $searchApp) + { + throw [Exception] "The Search Service Application does not exist" + } + else + { + New-SPEnterpriseSearchCrawlMapping -SearchApplication $searchApp -Url $params.Url -Target $params.Target + } + } + } + if($result.Ensure -eq "Present" -and $Ensure -eq "Present") + { + Write-Verbose "Updating the Crawl Mapping '$Url'" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $searchApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + $mappings = $searchApp | Get-SPEnterpriseSearchCrawlMapping + $mapping = $mappings | Where-Object -FilterScript { $_.Source -eq $params.Url } | Select-Object -First 1 + $mapping | Remove-SPEnterpriseSearchCrawlMapping + + New-SPEnterpriseSearchCrawlMapping -SearchApplication $searchApp -Url $params.Url -Target $params.Target + } + } + if($result.Ensure -eq "Present" -and $Ensure -eq "Absent") + { + + Write-Verbose "Removing the Crawl Mapping '$Url'" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $searchapp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + $mappings = $searchApp | Get-SPEnterpriseSearchCrawlMapping + $mapping = $mappings | Where-Object -FilterScript { $_.Source -eq $params.Url } | Select-Object -First 1 + $mapping | Remove-SPEnterpriseSearchCrawlMapping + } + } +} + + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [System.String] + $Target, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + Write-Verbose -Message "Testing Search Crawl Mapping for '$Url'" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + if($Ensure -eq "Present") + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName","Url","Target","Ensure") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure") + } +} + +Export-ModuleMember -Function *-TargetResource + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.schema.mof new file mode 100644 index 000000000..d62f23d89 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.schema.mof @@ -0,0 +1,10 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("SPSearchCrawlMapping")] +class MSFT_SPSearchCrawlMapping : OMI_BaseResource +{ + [Key, Description("Search Service Application Name")] String ServiceAppName; + [Key, Description("Source URI for the crawl mapping")] String Url; + [Required, Description("Target URI for the crawl mapping")] String Target; + [Write, Description("Ensure the crawl mapping is Present or Absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.schema.mof index baf679de7..0df36c22b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.schema.mof @@ -8,7 +8,7 @@ class MSFT_SPSearchCrawlRule : OMI_BaseResource [Write, Description("The configuration options for this rule"), ValueMap{"FollowLinksNoPageCrawl","CrawlComplexUrls","CrawlAsHTTP"}, Values{"FollowLinksNoPageCrawl","CrawlComplexUrls","CrawlAsHTTP"}] string CrawlConfigurationRules[]; [Write, Description("The credentials used for this crawl rule (used for types BasicAccountRuleAccess and NTLMAccountRuleAccess)"), EmbeddedInstance("MSFT_Credential")] String AuthenticationCredentials; [Write, Description("The certificate used for this crawl rule (used for type CertificateRuleAccess)")] string CertificateName; - [Write, Description("Present if the service app should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("Present if the crawl rule should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/readme.md index 96779a209..b38cd59d5 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/readme.md @@ -3,3 +3,6 @@ This resource is responsible for managing the search crawl rules in the search service application. You can create new rules, change existing rules and remove existing rules. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the crawl rule is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 new file mode 100644 index 000000000..22b5586f3 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 @@ -0,0 +1,288 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.UInt32] + $RequestLimit = 0, + + [System.UInt32] + $WaitTime = 0, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting Crawler Impact Rule Setting for '$Name'" + + if(($RequestLimit -gt 0) -and ($WaitTime -gt 0)) + { + throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + } + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $nullReturn = @{ + + ServiceAppName = $params.ServiceAppName + Name = $params.Name + RequestLimit = $null + WaitTime = $null + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $serviceApp) + { + $nullReturn.ServiceAppName = $null + return $nullReturn + } + else + { + $crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -Identity $params.Name -SearchService $serviceApp + if($null -eq $crawlerImpactRule) + { + return $nullReturn + } + else + { + if($crawlerImpactRule.Behavior -eq "0") + { + return @{ + ServiceAppName = $params.ServiceAppName + Name = $params.Name + RequestLimit = $crawlerImpactRule.HitRate + WaitTime = 0 + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + else + { + return @{ + ServiceAppName = $params.ServiceAppName + Name = $params.Name + RequestLimit = 0 + WaitTime = $crawlerImpactRule.HitRate + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + } + } + + + } + + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.UInt32] + $RequestLimit = 0, + + [System.UInt32] + $WaitTime = 0, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + + Write-Verbose -Message "Setting Crawler Impact Rule Setting for '$Name'" + + if(($RequestLimit -gt 0) -and ($WaitTime -gt 0)) + { + throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + } + + $result = Get-TargetResource @PSBoundParameters + + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + { + Write-Verbose -Message "Creating Crawler Impact Rule $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $behavior = "0" + $hitRate = 0 + if($null -eq $params.RequestLimit) + { + $behavior = "1" + $hitRate = $params.WaitTime + } + else + { + $behavior = "0" + $hitRate = $params.RequestLimit + } + + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $serviceApp) + { + throw "The Search Service Application does not exist." + } + New-SPEnterpriseSearchSiteHitRule -Name $params.Name ` + -Behavior $behavior ` + -HitRate $hitRate ` + -SearchService $serviceApp + } + } + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + { + Write-Verbose -Message "Updating Crawler Impact Rule $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $behavior = "0" + $hitRate = 0 + if($null -eq $params.RequestLimit) + { + $behavior = "1" + $hitRate = $params.WaitTime + } + else + { + $behavior = "0" + $hitRate = $params.RequestLimit + } + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $serviceApp) + { + throw "The Search Service Application does not exist." + } + + Remove-SPEnterpriseSearchSiteHitRule -Identity $params.Name ` + -SearchService $serviceApp ` + -ErrorAction SilentlyContinue + + New-SPEnterpriseSearchSiteHitRule -Name $params.Name ` + -Behavior $behavior ` + -HitRate $hitRate ` + -SearchService $serviceApp + + } + } + if($Ensure -eq "Absent") + { + Write-Verbose -Message "Removing Crawler Impact Rule $Name" + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if($null -eq $serviceApp) + { + throw "The Search Service Application does not exist." + } + Remove-SPEnterpriseSearchSiteHitRule -Identity $params.Name ` + -SearchService $serviceApp ` + -ErrorAction SilentlyContinue + } + } + + +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [System.UInt32] + $RequestLimit = 0, + + [System.UInt32] + $WaitTime = 0, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + Write-Verbose -Message "Testing Crawler Impact Rule Setting for '$Name'" + + if(($RequestLimit -gt 0) -and ($WaitTime -gt 0)) + { + throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + } + + $behavior = "" + if($RequestLimit -ne 0) + { + $behavior = "RequestLimit" + } + else + { + $behavior = "WaitTime" + } + + $CurrentValues = Get-TargetResource @PSBoundParameters + + if($Ensure -eq "Present") + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName", + "Name", + $behavior) + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("ServiceAppName", + "Name", + "Ensure") + } +} + +Export-ModuleMember -Function *-TargetResource + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.schema.mof new file mode 100644 index 000000000..5b1062a49 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.schema.mof @@ -0,0 +1,13 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("SPSearchCrawlerImpactRule")] +class MSFT_SPSearchCrawlerImpactRule : OMI_BaseResource +{ + [Key, Description("Search Service Application Name")] String ServiceAppName; + [Key, Description("The Site for the crawl impact rule")] String Name; + [Read, Description("The Behavior (RequestLimit or WaitTime) for this crawl impact rule")] String Behavior; + [Write, Description("The RequestLimit setting for the crawl impact rule")] UInt32 RequestLimit; + [Write, Description("The WaitTime setting for the crawl impact rule")] UInt32 WaitTime; + [Write, Description("Ensure the crawl rule is Present or Absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.schema.mof index a10f7c9c0..06d07da6a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.schema.mof @@ -2,11 +2,11 @@ class MSFT_SPSearchFileType : OMI_BaseResource { [Key, Description("The name of the file type")] string FileType; - [Required, Description("The name of the search service application")] string ServiceAppName; + [Key, Description("The name of the search service application")] string ServiceAppName; [Write, Description("The description of the file type")] string Description; [Write, Description("The mime type of the file type")] string MimeType; [Write, Description("The state of the file type")] boolean Enabled; - [Write, Description("Present if the service app should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("Present if the file type should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/readme.md index 42a74337b..ac43ccdcd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchFileType/readme.md @@ -3,3 +3,6 @@ This resource is responsible for managing the search file types in the search service application. You can create new file types, change existing types and remove existing file types. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the file type is added. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.psm1 index f8afd8b5a..1cceafbc7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.psm1 @@ -46,7 +46,7 @@ function Get-TargetResource Index = $params.Index Servers = $IndexComponents RootDirectory = $params.RootDirectory - ServiceAPpName = $params.ServiceAppName + ServiceAppName = $params.ServiceAppName InstallAccount = $params.InstallAccount } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.schema.mof index e0c884e7f..3ba702ed7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchIndexPartition/MSFT_SPSearchIndexPartition.schema.mof @@ -4,6 +4,6 @@ class MSFT_SPSearchIndexPartition : OMI_BaseResource [Key, Description("The number of the partition in this farm")] Uint32 Index; [Required, Description("A list of the servers that this partition should exist on")] String Servers[]; [Write, Description("The directory that the index should use locally on each server to store data")] String RootDirectory; - [Required, Description("The name of the search service application")] String ServiceAppName; + [Key, Description("The name of the search service application")] String ServiceAppName; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/readme.md index 79e1c92ca..bca3e5e59 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/readme.md @@ -10,3 +10,6 @@ following provider types: * OpenSearch Provider * Remote People Provider * Remote SharePoint Provider + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the result source is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/readme.md index 1981f6db3..759122c71 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/readme.md @@ -7,3 +7,6 @@ set it back as per what is set in the resource. The database name parameter is used as the prefix for all search databases (so you will end up with one for the admin database which matches the name, and then "_analyticsreportingstore", "_crawlstore" and "_linkstore" databases as well). + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 index 059fe9ff0..46f182490 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 @@ -397,6 +397,21 @@ function Set-TargetResource } } + # Look for components that have no server name and remove them + $idsWithNoName = (Get-SPEnterpriseSearchComponent -SearchTopology $newTopology | ` + Where-Object -FilterScript { + $null -eq $_.ServerName + }).ComponentId + $idsWithNoName | ForEach-Object -Process { + $id = $_ + Get-SPEnterpriseSearchComponent -SearchTopology $newTopology | ` + Where-Object -FilterScript { + $_.ComponentId -eq $id + } | ` + Remove-SPEnterpriseSearchComponent -SearchTopology $newTopology ` + -confirm:$false + } + # Apply the new topology to the farm Set-SPEnterpriseSearchTopology -Identity $newTopology } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 index 353cb31f4..df431dfa3 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 @@ -103,12 +103,25 @@ function Get-TargetResource $proxyName = $serviceAppProxy.Name } } + + $propertyFlags = [System.Reflection.BindingFlags]::Instance ` + -bor [System.Reflection.BindingFlags]::NonPublic + + $propData = $serviceApp.GetType().GetProperties($propertyFlags) + + $dbProp = $propData | Where-Object -FilterScript { + $_.Name -eq "Database" + } + + $db = $dbProp.GetValue($serviceApp) + return @{ Name = $serviceApp.DisplayName ProxyName = $proxyName ApplicationPool = $serviceApp.ApplicationPool.Name - DatabaseName = $serviceApp.Database.Name - DatabaseServer = $serviceApp.Database.Server.Name + DatabaseName = $db.Name + DatabaseServer = $db.Server.Name + FailoverDatabaseServer = $db.FailoverServer InstallAccount = $params.InstallAccount Ensure = "Present" } @@ -186,11 +199,11 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters $params = $PSBoundParameters - if((($params.ContainsKey("DatabaseAuthenticationType") -eq $true) -and ` - ($params.ContainsKey("DatabaseCredentials") -eq $false)) -or ` - (($params.ContainsKey("DatabaseCredentials") -eq $true) -and ` - ($params.ContainsKey("DatabaseAuthenticationType") -eq $false))) - { + if ((($params.ContainsKey("DatabaseAuthenticationType") -eq $true) -and ` + ($params.ContainsKey("DatabaseCredentials") -eq $false)) -or ` + (($params.ContainsKey("DatabaseCredentials") -eq $true) -and ` + ($params.ContainsKey("DatabaseAuthenticationType") -eq $false))) + { throw ("Where DatabaseCredentials are specified you must also specify " + ` "DatabaseAuthenticationType to identify the type of credentials being passed") return @@ -238,6 +251,21 @@ function Set-TargetResource if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { + if ($PSBoundParameters.ContainsKey("DatabaseServer") -and ` + ($result.DatabaseServer -ne $DatabaseServer)) + { + throw ("Specified database server does not match the actual " + ` + "database server. This resource cannot move the database " + ` + "to a different SQL instance.") + } + + if ($PSBoundParameters.ContainsKey("DatabaseName") -and ` + ($result.DatabaseName -ne $DatabaseName)) + { + throw ("Specified database name does not match the actual " + ` + "database name. This resource cannot rename the database.") + } + if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false ` -and $ApplicationPool -ne $result.ApplicationPool) { @@ -355,6 +383,23 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters + if ($PSBoundParameters.ContainsKey("DatabaseServer") -and ` + ($CurrentValues.DatabaseServer -ne $DatabaseServer)) + { + Write-Verbose -Message ("Specified database server does not match the actual " + ` + "database server. This resource cannot move the database " + ` + "to a different SQL instance.") + return $false + } + + if ($PSBoundParameters.ContainsKey("DatabaseName") -and ` + ($CurrentValues.DatabaseName -ne $DatabaseName)) + { + Write-Verbose -Message ("Specified database name does not match the actual " + ` + "database name. This resource cannot rename the database.") + return $false + } + return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("ApplicationPool", "Ensure") diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/readme.md index 2c4acd0b6..94c781e4d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/readme.md @@ -4,3 +4,6 @@ This resource is responsible for provisioning and configuring the secure store service application. The parameters passed in (except those related to database specifics) are validated and set when the resource is run, the database values are only used in provisioning of the service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppPool/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppPool/readme.md index 1c3fbcc35..22d2455ad 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppPool/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppPool/readme.md @@ -3,3 +3,6 @@ This resource is used for provisioning an application pool that can be used for service applications. The account used for the service account must already be registered as a managed account (which can be provisioned through + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application pool is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/readme.md index 4f50b2fd5..715de216a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/readme.md @@ -16,3 +16,6 @@ Requirements: At least one of the ServiceAppProxies, ServiceAppProxiesToInclude or ServiceAppProxiesToExclude properties needs to be specified. Do not combine the ServiceAppProxies property with the ServiceAppProxiesToInclude and + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the proxy group is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceInstance/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceInstance/readme.md index ee46352df..c98ba5a9d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceInstance/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceInstance/readme.md @@ -3,3 +3,6 @@ This resource is used to specify if a specific service should be running (Ensure = "Present") or not running (Ensure = "Absent") on the current server. The name is the display name of the service as shown in the Central Admin + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service instance is started. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/readme.md index d5df2d2ba..7c26ec9ca 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSessionStateService/readme.md @@ -3,3 +3,6 @@ This resource will provision a state service app to the local farm. Specify the name of the database server and database name to provision the app with, and optionally include the session timeout value. If session timeout is not + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 33a709672..50a49483e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -135,7 +135,7 @@ function Get-TargetResource QuotaTemplate = $quota SecondaryEmail = $site.SecondaryContact.Email SecondaryOwnerAlias = $secondaryOwner - Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.WebTemplateId)" + Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.Configuration)" InstallAccount = $params.InstallAccount } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md index 6f4ab0332..46dc1886c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md @@ -7,3 +7,10 @@ cmdlet and accept the same values and types. The current version of SharePointDsc is only able to check for the existence of a site collection, the additional parameters are not checked for yet, but will be in a later release + +Note: When creating Host Header Site Collections, do not use the HostHeader +parameter in SPWebApplication. This will set the specified host header on your +IIS site and prevent the site from listening for the URL of the Host Header +Site Collection. +If you want to change the IIS website binding settings, please use the xWebsite +resource in the xWebAdministration module. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPStateServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPStateServiceApp/readme.md index b9b1b4b83..6ccf3b3a8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPStateServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPStateServiceApp/readme.md @@ -3,3 +3,6 @@ This resource provisions an instance of the state service in to the local farm. The database specific parameters are only used during initial provisioning of the app, and will not change database settings beyond the initial deployment. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/readme.md index 22afd70e3..c8ef54115 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSubscriptionSettingsServiceApp/readme.md @@ -8,3 +8,6 @@ service account associated to the app if it does not match the configuration. Database names or server name will not be changed if the configuration does not match, these parameters are only used for the initial provisioning of the service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 index c74bc10d3..78855ee12 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 @@ -28,9 +28,13 @@ [Microsoft.Management.Infrastructure.CimInstance[]] $ClaimsMappings, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $false)] + [String] + $SigningCertificateThumbprint, + + [parameter(Mandatory = $false)] [String] - $SigningCertificateThumbPrint, + $SigningCertificateFilePath, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] @@ -66,7 +70,7 @@ $realm = $spTrust.DefaultProviderRealm $signInUrl = $spTrust.ProviderUri.OriginalString $identifierClaim = $spTrust.IdentityClaimTypeInformation.MappedClaimType - $signingCertificateThumbPrint = $spTrust.SigningCertificate.Thumbprint + $SigningCertificateThumbprint = $spTrust.SigningCertificate.Thumbprint $currentState = "Present" $claimProviderName = $sptrust.ClaimProviderName $providerSignOutUri = $sptrust.ProviderSignOutUri.OriginalString @@ -84,7 +88,7 @@ $realm = "" $signInUrl = "" $identifierClaim = "" - $signingCertificateThumbPrint = "" + $SigningCertificateThumbprint = "" $currentState = "Absent" $claimProviderName = "" $providerSignOutUri = "" @@ -97,7 +101,8 @@ SignInUrl = $signInUrl IdentifierClaim = $identifierClaim ClaimsMappings = $claimsMappings - SigningCertificateThumbPrint = $signingCertificateThumbPrint + SigningCertificateThumbprint = $SigningCertificateThumbprint + SigningCertificateFilePath = "" Ensure = $currentState ClaimProviderName = $claimProviderName ProviderSignOutUri = $providerSignOutUri @@ -135,9 +140,13 @@ function Set-TargetResource [Microsoft.Management.Infrastructure.CimInstance[]] $ClaimsMappings, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $false)] + [String] + $SigningCertificateThumbprint, + + [parameter(Mandatory = $false)] [String] - $SigningCertificateThumbPrint, + $SigningCertificateFilePath, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] @@ -165,27 +174,68 @@ function Set-TargetResource { if ($CurrentValues.Ensure -eq "Absent") { + if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` + $PSBoundParameters.ContainsKey("SigningCertificateFilePath")) + { + throw ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") + return + } + + if (!$PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` + !$PSBoundParameters.ContainsKey("SigningCertificateFilePath")) + { + throw ("At least one of the following parameters must be specified: " + ` + "SigningCertificateThumbprint, SigningCertificateFilePath.") + return + } + Write-Verbose -Message "Creating SPTrustedIdentityTokenIssuer '$Name'" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] + if ($params.SigningCertificateThumbprint) + { + Write-Verbose -Message ("Getting signing certificate with thumbprint " + ` + "$($params.SigningCertificateThumbprint) from the certificate store 'LocalMachine\My'") - $cert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object -FilterScript { - $_.Thumbprint -match $params.SigningCertificateThumbPrint - } + if ($params.SigningCertificateThumbprint -notmatch "^[A-Fa-f0-9]{40}$") + { + throw ("Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'.") + return + } - if (!$cert) - { - throw ("The certificate thumbprint does not match a certificate in " + ` - "certificate store LocalMachine\My.") - return - } + $cert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object -FilterScript { + $_.Thumbprint -match $params.SigningCertificateThumbprint + } - if ($cert.HasPrivateKey) + if (!$cert) + { + throw ("Signing certificate with thumbprint $($params.SigningCertificateThumbprint) " + ` + "was not found in certificate store 'LocalMachine\My'.") + return + } + + if ($cert.HasPrivateKey) + { + throw ("SharePoint requires that the private key of the signing certificate" + ` + " is not installed in the certificate store.") + return + } + } + else { - throw ("SharePoint requires that the private key of the signing " + ` - "certificate is not installed in the certificate store.") + Write-Verbose -Message "Getting signing certificate from file system path '$($params.SigningCertificateFilePath)'" + try + { + $cert = New-Object -TypeName "System.Security.Cryptography.X509Certificates.X509Certificate2" ` + -ArgumentList @($params.SigningCertificateFilePath) + } + catch + { + throw ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + return + } } $claimsMappingsArray = @() @@ -210,8 +260,7 @@ function Set-TargetResource $_.MappedClaimType -like $params.IdentifierClaim })) { - throw ("IdentifierClaim does not match any claim type specified in " + ` - "ClaimsMappings.") + throw ("IdentifierClaim does not match any claim type specified in ClaimsMappings.") return } @@ -327,9 +376,13 @@ function Test-TargetResource [Microsoft.Management.Infrastructure.CimInstance[]] $ClaimsMappings, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $false)] + [String] + $SigningCertificateThumbprint, + + [parameter(Mandatory = $false)] [String] - $SigningCertificateThumbPrint, + $SigningCertificateFilePath, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] @@ -351,6 +404,21 @@ function Test-TargetResource Write-Verbose -Message "Testing SPTrustedIdentityTokenIssuer '$Name' settings" + if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` + $PSBoundParameters.ContainsKey("SigningCertificateFilePath")) + { + throw ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") + return + } + + if (!$PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` + !$PSBoundParameters.ContainsKey("SigningCertificateFilePath")) + { + throw ("At least one of the following parameters must be specified: " + ` + "SigningCertificateThumbprint, SigningCertificateFilePath.") + return + } + $CurrentValues = Get-TargetResource @PSBoundParameters return Test-SPDscParameterState -CurrentValues $CurrentValues ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof index 89a7c8250..f0056d898 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof @@ -8,7 +8,7 @@ class MSFT_SPClaimTypeMapping }; -[ClassVersion("1.0.0.0"), FriendlyName("SPTrustedIdentityTokenIssuer")] +[ClassVersion("1.1.0.0"), FriendlyName("SPTrustedIdentityTokenIssuer")] class MSFT_SPTrustedIdentityTokenIssuer : OMI_BaseResource { [Key, Description("Name of the SPTrustedIdentityTokenIssuer")] String Name; @@ -17,10 +17,10 @@ class MSFT_SPTrustedIdentityTokenIssuer : OMI_BaseResource [Required, Description("URL of the identity provider where user is redirected to for authentication")] String SignInUrl; [Required, Description("Identity claim type that uniquely identifies the user")] String IdentifierClaim; [Required, Description("Array of MSFT_SPClaimTypeMapping to use with cmdlet New-SPClaimTypeMapping"), EmbeddedInstance("MSFT_SPClaimTypeMapping")] String ClaimsMappings[]; - [Required, Description("Thumbprint of the signing certificate to use with this SPTrustedIdentityTokenIssuer. It must match the thumbprint of a certificate located in store LocalMachine\\My")] String SigningCertificateThumbPrint; + [Write, Description("Specify the thumbprint of the signing certificate, which must be located in certificate store LocalMachine\\My")] String SigningCertificateThumbprint; + [Write, Description("Specify the file path to the signing certificate if it is not stored in the local certificate store already")] String SigningCertificateFilePath; [Write, Description("Name of a claims provider to set with this SPTrustedIdentityTokenIssuer")] String ClaimProviderName; [Write, Description("Sign-out URL")] String ProviderSignOutUri; [Write, Description("Present if the SPTrustedIdentityTokenIssuer should be created, or Absent if it should be removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; - diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/readme.md index 7c4f13e31..9fa77e9b4 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/readme.md @@ -3,21 +3,28 @@ This resource is used to create or remove SPTrustedIdentityTokenIssuer in a SharePoint farm. -The SigningCertificateThumbPrint must match the thumbprint of a certificate in -the store LocalMachine\My of the server that will run this resource. +Either parameter SigningCertificateThumbPrint or SigningCertificateFilePath +must be set, but not both. + +The SigningCertificateThumbPrint must be the thumbprint of the signing +certificate stored in the certificate store LocalMachine\My of the server + Note that the private key of the certificate must not be available in the certiificate store because SharePoint does not accept it. -Once the SPTrustedIdentityTokenIssuer is successfully created, the certificate -can be safely deleted from the certificate store as it won't be needed by -SharePoint. -ClaimsMappings is an array of MSFT_SPClaimTypeMapping to use with cmdlet -New-SPClaimTypeMapping. Each MSFT_SPClaimTypeMapping requires properties Name -and IncomingClaimType. Property LocalClaimType is not required if its value is -identical to IncomingClaimType. +The SigningCertificateFilePath must be the file path to the public key of +the signing certificate. + +The ClaimsMappings property is an array of MSFT_SPClaimTypeMapping to use +with cmdlet New-SPClaimTypeMapping. Each MSFT_SPClaimTypeMapping requires +properties Name and IncomingClaimType. Property LocalClaimType is not +required if its value is identical to IncomingClaimType. The IdentifierClaim property must match an IncomingClaimType element in ClaimsMappings array. The ClaimProviderName property can be set to specify a custom claims provider. It must be already installed in the SharePoint farm and returned by cmdlet + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the token issuer is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 new file mode 100644 index 000000000..318f6d3d7 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 @@ -0,0 +1,169 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $CertificateThumbprint, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose "Getting Trusted Root Authority with name '$Name'" + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $rootCert = Get-SPTrustedRootAuthority -Identity $params.Name -ErrorAction SilentlyContinue + + $ensure = "Absent" + + if($null -eq $rootCert) + { + return @{ + Name = $params.Name + CertificateThumbprint = [string]::Empty + Ensure = $ensure + } + } + else + { + $ensure = "Present" + + return @{ + Name = $params.Name + CertificateThumbprint = $rootCert.Certificate.Thumbprint + Ensure = $ensure + } + } + } + + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $CertificateThumbprint, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting SPTrustedRootAuthority '$Name'" + + $CurrentValues = Get-TargetResource @PSBoundParameters + if ($Ensure -eq "Present" -and $CurrentValues.Ensure -eq "Present") + { + Write-Verbose -Message "Updating SPTrustedRootAuthority '$Name'" + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $cert = Get-Item -Path "CERT:\LocalMachine\My\$($params.CertificateThumbprint)" ` + -ErrorAction SilentlyContinue + + if($null -eq $cert) + { + throw "Certificate not found in the local Certificate Store" + } + + Set-SPTrustedRootAuthority -Identity $params.Name -Certificate $cert + } + } + if ($Ensure -eq "Present" -and $CurrentValues.Ensure -eq "Absent") + { + Write-Verbose -Message "Adding SPTrustedRootAuthority '$Name'" + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $cert = Get-Item -Path "CERT:\LocalMachine\My\$($params.CertificateThumbprint)" ` + -ErrorAction SilentlyContinue + + if($null -eq $cert) + { + throw "Certificate not found in the local Certificate Store" + } + + New-SPTrustedRootAuthority -Name $params.Name -Certificate $cert + } + } + if ($Ensure -eq "Absent") + { + Write-Verbose -Message "Removing SPTrustedRootAuthority '$Name'" + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + Remove-SPTrustedRootAuthority -Identity $params.Name ` + -ErrorAction SilentlyContinue + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $CertificateThumbprint, + + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing SPTrustedRootAuthority '$Name'" + + $CurrentValues = Get-TargetResource @PSBoundParameters + if($Ensure -eq "Present") + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Name","CertificateThumbprint","Ensure") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Name","Ensure") + } +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.schema.mof new file mode 100644 index 000000000..d71573d2c --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.schema.mof @@ -0,0 +1,9 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("SPTrustedRootAuthority")] +class MSFT_SPTrustedRootAuthority : OMI_BaseResource +{ + [Key, Description("Specifies the name of the trusted root authority to create.")] String Name; + [Required, Description("Specifies the X.509 certificate of the trusted root authority, as a certificate thumbprint.")] String CertificateThumbprint; + [Write, Description("Present ensures service app exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUsageApplication/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPUsageApplication/readme.md index 8d2d16194..d1f9dd3ef 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUsageApplication/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUsageApplication/readme.md @@ -3,3 +3,6 @@ This resource provisions an instance of the usage and health monitoring service application. The database settings are only used for initial provisioning, but the usage settings can be changed and will be enforced as the resource is + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/readme.md index d8b4ef3be..547c901fd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/readme.md @@ -12,3 +12,6 @@ adds it as the last property of section X. Length is only relevant if Field type is "String". This Resource doesn't currently support removing existing user profile + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the user profile property is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/readme.md index cd4413de4..83a9c2468 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/readme.md @@ -5,3 +5,6 @@ creates, update or delete a section using the parameters that are passed in to it. If no DisplayOrder is added then SharePoint will automatically assigned an ID + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the user profile section is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/readme.md index 9e8a66045..20751b91a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/readme.md @@ -7,3 +7,6 @@ farm account is used during the provisioning of the service only (in the set method), and the install account is used in the get and test methods. This is done to ensure that the databases are created with the correct schema owners and allow the user profile sync service to operate correctly. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/readme.md index 529869961..d32cf46e7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/readme.md @@ -10,3 +10,6 @@ server. To allow successful provisioning the farm account must be in the local administrators group, however it is not best practice to leave this account in the Administrators group. Therefore this resource will add the FarmAccount credential to the local administrators group at the beginning of the set + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the user profile sync service is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPVisioServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPVisioServiceApp/readme.md index b7593758b..359642836 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPVisioServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPVisioServiceApp/readme.md @@ -3,3 +3,6 @@ This resource is responsible for creating Visio Graphics Service Application instances within the local SharePoint farm. The resource will provision and configure the Visio Graphics Service Application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWeb/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWeb/readme.md index 53e18f86e..dc8e08ffa 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWeb/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWeb/readme.md @@ -2,3 +2,6 @@ This resource will provision a SPWeb based on the settings that are passed through. These settings map to the New-SPWeb cmdlet and accept the same values + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the web is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppProxyGroup/MSFT_SPWebAppProxyGroup.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppProxyGroup/MSFT_SPWebAppProxyGroup.schema.mof index 9c7e8508a..e57811698 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppProxyGroup/MSFT_SPWebAppProxyGroup.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppProxyGroup/MSFT_SPWebAppProxyGroup.schema.mof @@ -2,6 +2,6 @@ class MSFT_SPWebAppProxyGroup : OMI_BaseResource { [Key, Description("URL of the web application")] String WebAppUrl; - [Required, Description("Name of the Service Applicaiton Proxy Group")] string ServiceAppProxyGroup; + [Required, Description("Name of the Service Application Proxy Group")] string ServiceAppProxyGroup; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 index bfcd8103c..216828d20 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 @@ -165,6 +165,7 @@ function Set-TargetResource # Happy hour settins use separate update method so use a fresh web app to update these $wa2 = Get-SPWebApplication -Identity $params.Url Set-SPDSCWebApplicationHappyHourConfig -WebApplication $wa2 -Settings $params.HappyHour + $wa2.Update() } } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md index 0da0ae97c..b5a4b9d8d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md @@ -4,3 +4,13 @@ This resource is responsible for creating a web application within the local SharePoint farm. The resource will provision the web application with all of the current settings, and then ensure that it stays part of the correct application pool beyond that (additional checking and setting of properties + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the web application is provisioned. + +Note: When using Host Header Site Collections, do not use the HostHeader +parameter in SPWebApplication. This will set the specified host header on your +IIS site and prevent the site from listening for the URL of the Host Header +Site Collection. +If you want to change the IIS website binding settings, please use the xWebsite +resource in the xWebAdministration module. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 new file mode 100644 index 000000000..9666fd600 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 @@ -0,0 +1,423 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] + [System.String] + $Zone, + + [parameter(Mandatory = $false)] + [System.Boolean] + $AllowAnonymous, + + [parameter(Mandatory = $false)] + [System.String] + $HostHeader, + + [parameter(Mandatory = $false)] + [System.String] + $Path, + + [parameter(Mandatory = $false)] + [System.String] + $Port, + + [parameter(Mandatory = $false)] + [System.Boolean] + $UseSSL, + + [parameter(Mandatory = $false)] + [ValidateSet("NTLM","Kerberos","Claims")] + [System.String] + $AuthenticationMethod, + + [parameter(Mandatory = $false)] + [System.String] + $AuthenticationProvider, + + [parameter(Mandatory = $false)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting web application extension '$Name' config" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -ScriptBlock { + $params = $args[0] + $ScriptRoot = $args[1] + + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue + + if ($null -eq $wa) + { + Write-Verbose -Message "WebApplication $($params.WebAppUrl) does not exist" + return @{ + WebAppUrl = $params.WebAppUrl + Name = $params.Name + Url = $null + Zone = $null + Ensure = "Absent" + } + } + + $zone = [Microsoft.SharePoint.Administration.SPUrlZone]::$($params.Zone) + $waExt = $wa.IisSettings[$zone] + + if ($null -eq $waExt) + { + return @{ + WebAppUrl = $params.WebAppUrl + Name = $params.Name + Url = $params.Url + Zone = $params.zone + Ensure = "Absent" + } + } + + $publicUrl = (Get-SPAlternateURL -WebApplication $params.WebAppUrl -Zone $params.zone).PublicUrl + + if ($null -ne $waExt.SecureBindings.HostHeader) #default to SSL bindings if present + { + $HostHeader = $waExt.SecureBindings.HostHeader + $Port = $waExt.SecureBindings.Port + $UseSSL = $true + } + else + { + $HostHeader = $waExt.ServerBindings.HostHeader + $Port = $waExt.ServerBindings.Port + $UseSSL = $false + } + + $authProvider = Get-SPAuthenticationProvider -WebApplication $wa.Url -Zone $params.zone + if($authProvider.DisplayName -eq "Windows Authentication") + { + if ($authProvider.DisableKerberos -eq $true) + { + $localAuthMode = "NTLM" + } + else + { + $localAuthMode = "Kerberos" + } + } + else + { + $localAuthMode = "Claims" + $authenticationProvider = $authProvider.DisplayName + } + + return @{ + WebAppUrl = $params.WebAppUrl + Name = $waExt.ServerComment + Url = $PublicURL + AllowAnonymous = $authProvider.AllowAnonymous + HostHeader = $HostHeader + Path = $waExt.Path + Port = $Port + Zone = $params.zone + AuthenticationMethod = $localAuthMode + AuthenticationProvider = $authenticationProvider + UseSSL = $UseSSL + InstallAccount = $params.InstallAccount + Ensure = "Present" + } + } + return $result +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] + [System.String] + $Zone, + + [parameter(Mandatory = $false)] + [System.Boolean] + $AllowAnonymous, + + [parameter(Mandatory = $false)] + [System.String] + $HostHeader, + + [parameter(Mandatory = $false)] + [System.String] + $Path, + + [parameter(Mandatory = $false)] + [System.String] + $Port, + + [parameter(Mandatory = $false)] + [System.Boolean] + $UseSSL, + + [parameter(Mandatory = $false)] + [ValidateSet("NTLM","Kerberos","Claims")] + [System.String] + $AuthenticationMethod, + + [parameter(Mandatory = $false)] + [System.String] + $AuthenticationProvider, + + [parameter(Mandatory = $false)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting web application extension '$Name' config" + + if ($Ensure -eq "Present") + { + if ($AuthenticationMethod -eq "Claims" -and [string]::IsNullOrEmpty($AuthenticationProvider)) + { + throw [Exception] "When configuring SPWebApplication to use Claims the AuthenticationProvider value must be specified." + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -ScriptBlock { + $params = $args[0] + $ScriptRoot = $args[1] + + + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue + if ($null -eq $wa) + { + throw "Web Application with URL $($params.WebAppUrl) does not exist" + } + + + $zone = [Microsoft.SharePoint.Administration.SPUrlZone]::$($params.Zone) + $waExt = $wa.IisSettings[$zone] + + if ($null -eq $waExt) + { + $newWebAppExtParams = @{ + Name = $params.Name + Url = $params.Url + Zone = $params.zone + } + + + if ($params.ContainsKey("AuthenticationMethod") -eq $true) + { + if($params.AuthenticationMethod -eq "Claims") + { + try + { + $ap = Get-SPTrustedIdentityTokenIssuer -Identity $params.AuthenticationProvider -ErrorAction Stop + } + catch + { + throw [Exception] "Cannot find Authentication Provider $($params.AuthenticationProvider)" + } + } + else + { + $disableKerberos = ($params.AuthenticationMethod -eq "NTLM") + $ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication ` + -DisableKerberos:$disableKerberos + } + + $newWebAppExtParams.Add("AuthenticationProvider", $ap) + } + + if ($params.ContainsKey("AllowAnonymous") -eq $true) + { + $newWebAppExtParams.Add("AllowAnonymousAccess", $params.AllowAnonymous) + } + if ($params.ContainsKey("HostHeader") -eq $true) + { + $newWebAppExtParams.Add("HostHeader", $params.HostHeader) + } + if ($params.ContainsKey("Path") -eq $true) + { + $newWebAppExtParams.Add("Path", $params.Path) + } + if ($params.ContainsKey("Port") -eq $true) + { + $newWebAppExtParams.Add("Port", $params.Port) + } + if ($params.ContainsKey("UseSSL") -eq $true) + { + $newWebAppExtParams.Add("SecureSocketsLayer", $params.UseSSL) + } + + $wa | New-SPWebApplicationExtension @newWebAppExtParams | Out-Null + } + else + { + if ($params.ContainsKey("AllowAnonymous") -eq $true) + { + $waExt.AllowAnonymous = $params.AllowAnonymous + $wa.update() + } + + if ($params.ContainsKey("AuthenticationMethod") -eq $true) + { + if($params.AuthenticationMethod -eq "Claims") + { + try + { + $ap = Get-SPTrustedIdentityTokenIssuer -Identity $params.AuthenticationProvider -ErrorAction Stop + } + catch + { + throw [Exception] "Cannot find Authentication Provider $($params.AuthenticationProvider)" + } + } + else + { + $disableKerberos = ($params.AuthenticationMethod -eq "NTLM") + $ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication ` + -DisableKerberos:$disableKerberos + } + + Set-SPWebApplication -Identity $params.WebAppUrl -Zone $params.zone -AuthenticationProvider $ap + } + } + } + } + + if ($Ensure -eq "Absent") + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters,$PSScriptRoot) ` + -ScriptBlock { + $params = $args[0] + $ScriptRoot = $args[1] + + $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue + if ($null -eq $wa) + { + throw "Web Application with URL $($params.WebAppUrl) does not exist" + } + if ($null -ne $wa) + { + $wa | Remove-SPWebApplication -Zone $params.zone -Confirm:$false -DeleteIISSite + } + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [parameter(Mandatory = $true)] + [System.String] + $Name, + + [parameter(Mandatory = $true)] + [System.String] + $Url, + + [parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] + [System.String] + $Zone, + + [parameter(Mandatory = $false)] + [System.Boolean] + $AllowAnonymous, + + [parameter(Mandatory = $false)] + [System.String] + $HostHeader, + + [parameter(Mandatory = $false)] + [System.String] + $Path, + + [parameter(Mandatory = $false)] + [System.String] + $Port, + + [parameter(Mandatory = $false)] + [System.Boolean] + $UseSSL, + + [parameter(Mandatory = $false)] + [ValidateSet("NTLM","Kerberos","Claims")] + [System.String] + $AuthenticationMethod, + + [parameter(Mandatory = $false)] + [System.String] + $AuthenticationProvider, + + [parameter(Mandatory = $false)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [parameter(Mandatory = $false)] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing for web application extension '$Name'config" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + $testReturn = Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure","AuthenticationMethod","AllowAnonymous") + return $testReturn +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.schema.mof new file mode 100644 index 000000000..aff259f8e --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.schema.mof @@ -0,0 +1,18 @@ +[ClassVersion("1.1.0.0"), FriendlyName("SPWebApplicationExtension")] +class MSFT_SPWebApplicationExtension : OMI_BaseResource +{ + [Key, Description("The URL of the parent web application")] string WebAppUrl; + [Required, Description("The name of the web application extension")] string Name; + [Required, Description("The URL of the web application extension")] string Url; + [Key, Description("Specifies one of the five zones with which the internal URL of this new extension is to be associated."),ValueMap{"Default","Intranet","Internet","Extranet","Custom"}, Values{"Default","Intranet","Internet","Extranet","Custom"}] string Zone; + [Write, Description("Should anonymous access be enabled for this web app extension")] boolean AllowAnonymous; + [Write, Description("What authentication mode should be used for the web app extension"), ValueMap{"NTLM","Kerberos","Claims"}, Values{"NTLM","Kerberos","Claims"}] string AuthenticationMethod; + [Write, Description("What authentication provider should be used for the web app. This value is required when AuthenticationMethod is set to Claims")] string AuthenticationProvider; + [Write, Description("The host header to use for the web app extension")] string HostHeader; + [Write, Description("The path on the local servers to host the IIS web site from")] string Path; + [Write, Description("The port to run the site on")] string Port; + [Write, Description("Should this web app extension use SSL")] boolean UseSSL; + [Write, Description("Present if the web app should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] string InstallAccount; +}; + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/readme.md new file mode 100644 index 000000000..f3ecb1f7c --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/readme.md @@ -0,0 +1,8 @@ +# Description + +This resource is responsible for extending an existing web application into a new +zone. The resource will provision the web application extension with all of +the current settings, and then ensure that it stays present and will ensure the +AllowAnonymous and Authentication methods remain consistent. Please note that this +currently does not support changing the claims provider on an existing claims +enabled web application externsion. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/readme.md index ec8421466..0777929b3 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/readme.md @@ -9,3 +9,6 @@ When you specify Ensure=Present, the Application Pool and DatabaseName parameters are required. When you specify Ensure=Absent, no other parameters are allowed (with the exception of Name, InstallAccount or PsDscRunAsCredential). + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md index c2334d108..85f52449a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md @@ -12,3 +12,6 @@ Remarks - Parameters MinimumTimeBetweenEwsSyncSubscriptionSearches, MinimumTimeBetweenProviderRefreshes, MinimumTimeBetweenSearchQueries are in minutes. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the service application is provisioned. diff --git a/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/1-CreateServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/1-CreateServiceApp.ps1 new file mode 100644 index 000000000..2cb7c5019 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/1-CreateServiceApp.ps1 @@ -0,0 +1,23 @@ +<# +.EXAMPLE + This example shows how to deploy Access Services 2010 to the local SharePoint farm. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPAccessServices2010 Access2010Services + { + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/2-RemoveServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/2-RemoveServiceApp.ps1 new file mode 100644 index 000000000..be1613400 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPAccess2010ServiceApp/2-RemoveServiceApp.ps1 @@ -0,0 +1,28 @@ +<# +.EXAMPLE + + This example shows how to remove a specific Access Services 2010 from the local + SharePoint farm. Because Application pool is a required parameters, but is not + acutally needed to remove the app, any text value can be supplied for these as + they will be ignored. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPAccessServices2010 Access2010Services + { + Name = "Access 2010 Services Service Application" + ApplicationPool = "n/a" + Ensure = "Absent" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/1-CreateServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/1-CreateServiceApp.ps1 new file mode 100644 index 000000000..95ab02703 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/1-CreateServiceApp.ps1 @@ -0,0 +1,26 @@ +<# +.EXAMPLE + This example shows how to deploy the SP Machine Translation Service App to the local SharePoint farm. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPMachineTranslationServiceApp MachineTranslationServiceApp + { + Name = "Translation Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "Translation" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } +} diff --git a/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/2-RemoveServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/2-RemoveServiceApp.ps1 new file mode 100644 index 000000000..76ed91252 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPMachineTranslationServiceApp/2-RemoveServiceApp.ps1 @@ -0,0 +1,27 @@ +<# +.EXAMPLE + This example shows how to remove the SP Machine Translation Service App to the local SharePoint farm. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPMachineTranslationServiceApp MachineTranslationServiceApp + { + Name = "Translation Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "Translation" + Ensure = "Absent" + PsDscRunAsCredential = $SetupAccount + + } + } +} diff --git a/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/3-SetTermStoreAdmins.ps1 b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/3-SetTermStoreAdmins.ps1 new file mode 100644 index 000000000..092a03896 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/3-SetTermStoreAdmins.ps1 @@ -0,0 +1,30 @@ +<# +.EXAMPLE + This example shows how to deploy the Managed Metadata service app to the local SharePoint farm + and also include a specific list of users to be the term store administrators. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPManagedMetaDataServiceApp ManagedMetadataServiceApp + { + Name = "Managed Metadata Service Application" + InstallAccount = $SetupAccount + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "SP_ManagedMetadata" + TermStoreAdministrators = @( + "CONTOSO\user1", + "CONTOSO\user2" + ) + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/1-NewServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/1-NewServiceApp.ps1 new file mode 100644 index 000000000..1d8c4c5a7 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/1-NewServiceApp.ps1 @@ -0,0 +1,30 @@ +<# +.EXAMPLE + This example makes sure the service application exists and has a specific configuration +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPPowerPointAutomationServiceApp PowerPointAutomation + { + Name = "PowerPoint Automation Service Application" + ProxyName = "PowerPoint Automation Service Application Proxy" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + ApplicationPool = "SharePoint Web Services" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/2-RemoveServiceApp.ps1 b/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/2-RemoveServiceApp.ps1 new file mode 100644 index 000000000..d57d8afed --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPPowerPointAutomationServiceApp/2-RemoveServiceApp.ps1 @@ -0,0 +1,23 @@ +<# +.EXAMPLE + This example removes a word automation service app +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPPowerPointAutomationServiceApp WordAutomation + { + Name = "PowerPoint Automation Service Application" + Ensure = "Absent" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/1 - AuthoritativePage.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/1 - AuthoritativePage.ps1 new file mode 100644 index 000000000..b318a7eba --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/1 - AuthoritativePage.ps1 @@ -0,0 +1,26 @@ +<# +.EXAMPLE + This example shows how to create a Search Authoritative Page +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchAuthoritativePage AuthoratativePage + { + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/Pages/authoritative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/2 - DemotedPage.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/2 - DemotedPage.ps1 new file mode 100644 index 000000000..1a5768224 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchAuthoritativePage/2 - DemotedPage.ps1 @@ -0,0 +1,25 @@ +<# +.EXAMPLE + This example shows how to create a Search Demoted Page +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchAuthoritativePage AuthoratativePage + { + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/Pages/demoted.aspx" + Action = "Demoted" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlMapping/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlMapping/1-Example.ps1 new file mode 100644 index 000000000..254eff6a3 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlMapping/1-Example.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to apply a Search Crawl Mapping rule to a search application. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + + SPSearchCrawlMapping IntranetCrawlMapping + { + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + PsDScRunAsCredential = $SetupAccount + } + + } + } + + diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/1 - RequestLimit b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/1 - RequestLimit new file mode 100644 index 000000000..5cbb0e6a2 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/1 - RequestLimit @@ -0,0 +1,25 @@ +<# +.EXAMPLE + This example shows how to create a Crawler Impact Rule with a Request Limit +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchCrawlerImpactRule IntranetCrawlerImpactRequestLimitRule + { + ServiceAppName = "Search Service Application" + Name = "https://intranet.sharepoint.contoso.com" + RequestLimit = 8 + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/2 - WaitTime b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/2 - WaitTime new file mode 100644 index 000000000..2f93edb2d --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchCrawlerImpactRule/2 - WaitTime @@ -0,0 +1,25 @@ +<# +.EXAMPLE + This example shows how to create a Crawler Impact Rule with a Wait Time +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchCrawlerImpactRule IntranetCrawlerImpactWaitTimeRule + { + ServiceAppName = "Search Service Application" + Name = "https://intranet.sharepoint.contoso.com" + WaitTime = 60 + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-SigningCertInFileCertificateStore.ps1 b/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-SigningCertInFileCertificateStore.ps1 new file mode 100644 index 000000000..33192cb01 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-SigningCertInFileCertificateStore.ps1 @@ -0,0 +1,41 @@ +<# +.EXAMPLE + This example deploys a trusted token issuer to the local farm. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPTrustedIdentityTokenIssuer SampleSPTrust + { + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + MSFT_SPClaimTypeMapping{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } + MSFT_SPClaimTypeMapping{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } + ) + SigningCertificateThumbPrint = "F0D3D9D8E38C1D55A3CEF3AAD1C18AD6A90D5628" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/2-SigningCertInFilePath.ps1 similarity index 91% rename from Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-Example.ps1 rename to Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/2-SigningCertInFilePath.ps1 index 473cb0e33..e2cee2309 100644 --- a/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/1-Example.ps1 +++ b/Modules/SharePointDsc/Examples/Resources/SPTrustedIdentityTokenIssuer/2-SigningCertInFilePath.ps1 @@ -20,7 +20,7 @@ Realm = "https://sharepoint.contoso.com" SignInUrl = "https://adfs.contoso.com/adfs/ls/" IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" - ClaimsMappings = @( + ClaimsMappings = @( MSFT_SPClaimTypeMapping{ Name = "Email" IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" @@ -31,7 +31,7 @@ LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } ) - SigningCertificateThumbPrint = "F3229E7CCA1DA812E29284B0ED75A9A019A83B08" + SigningCertificateFilePath = "F:\Data\DSC\FakeSigning.cer" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" diff --git a/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/1-Example.ps1 new file mode 100644 index 000000000..1556c7225 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/1-Example.ps1 @@ -0,0 +1,24 @@ +<# +.EXAMPLE + This example deploys a SP Trusted Root Authority to the local farm. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPTrustedRootAuthority SampleRootAuthority + { + Name = "Contoso" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/2-RemoveExample.ps1 b/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/2-RemoveExample.ps1 new file mode 100644 index 000000000..e253034a3 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPTrustedRootAuthority/2-RemoveExample.ps1 @@ -0,0 +1,24 @@ +<# +.EXAMPLE + This example removes a SP Trusted Root Authority from the local farm. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPTrustedRootAuthority SampleRootAuthority + { + Name = "Contoso" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Absent" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebApplicationExtension/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebApplicationExtension/1-Example.ps1 new file mode 100644 index 000000000..cace2d05e --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebApplicationExtension/1-Example.ps1 @@ -0,0 +1,32 @@ +<# +.EXAMPLE + This example shows how to create a new web application extension in the local farm +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPWebApplicationExtension IntranetZone + { + WebAppUrl = "http://example.contoso.local" + Name = "Contoso Intranet Zone" + AllowAnonymous = $false + AuthenticationMethod = "NTLM" + Url = "http://intranet.contoso.local" + Zone = "Intranet" + HostHeader = "intranet.contoso.local" + Path = "c:\inetpub\wwwroot\wss\VirtualDirectories\intranet" + UseSSL = $false + Port = 80 + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 index 58f2be63f..c0016716d 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.Farm/SPFarm.psm1 @@ -130,7 +130,7 @@ function Add-SPDSCConfigDBLock $connection.Open() $command.Connection = $connection - $command.CommandText = "CREATE DATABASE $($Database)_Lock" + $command.CommandText = "CREATE DATABASE [$($Database)_Lock]" $command.ExecuteNonQuery() } finally @@ -191,7 +191,7 @@ function Remove-SPDSCConfigDBLock $connection.Open() $command.Connection = $connection - $command.CommandText = "DROP DATABASE $($Database)_Lock" + $command.CommandText = "DROP DATABASE [$($Database)_Lock]" $command.ExecuteNonQuery() } finally diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 index a0896a7a1..3543fd010 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.WebAppPolicy/SPWebAppPolicy.psm1 @@ -62,8 +62,8 @@ function Compare-SPDSCWebAppPolicy() if ($null -ne $polbinddiff) { - Write-Verbose -Message "Permission level different for " + ` - "$($policy.IdentityType) user '$($policy.Username)'" + Write-Verbose -Message ("Permission level different for " + ` + "$($policy.IdentityType) user '$($policy.Username)'") if (-not (Assert-SPDSCPolicyUser -CurrentDifferences $diff ` -UsernameToCheck $policy.Username.ToLower())) @@ -136,8 +136,8 @@ function Compare-SPDSCWebAppPolicy() -DifferenceObject $setting.PermissionLevel.ToLower() if ($null -ne $polbinddiff) { - Write-Verbose -Message "Permission level different for " + ` - "$($policy.IdentityType) user '$($policy.Username)'" + Write-Verbose -Message ("Permission level different for " + ` + "$($policy.IdentityType) user '$($policy.Username)'") if (-not (Assert-SPDSCPolicyUser -CurrentDifferences $diff ` -UsernameToCheck $policy.Username.ToLower())) diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 index 1bcd8d752..ba617c18b 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.GeneralSettings.psm1 @@ -17,7 +17,7 @@ function Get-SPDSCWebApplicationGeneralConfig BrowserFileHandling = $WebApplication.BrowserFileHandling SecurityValidation = $WebApplication.FormDigestSettings.Enabled SecurityValidationExpires = $WebApplication.FormDigestSettings.Expires - SecurityValidationTimeoutMinutes = $WebApplication.FormDigestSettings.timeout.minutes + SecurityValidationTimeoutMinutes = $WebApplication.FormDigestSettings.Timeout.TotalMinutes RecycleBinEnabled = $WebApplication.RecycleBinEnabled RecycleBinCleanupEnabled = $WebApplication.RecycleBinCleanupEnabled RecycleBinRetentionPeriod = $WebApplication.RecycleBinRetentionPeriod diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 index 27786e51a..921d85ec9 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 @@ -100,9 +100,9 @@ function Set-SPDSCWebApplicationHappyHourConfig { throw "Happy hour setting 'hour' must be between 0 and 23" } - $h = $happyHour.Hour - $m = $happyHour.Minute - $d = $happyHour.Duration + $h = $Settings.Hour + $m = $Settings.Minute + $d = $Settings.Duration $WebApplication.SetDailyUnthrottledPrivilegedOperationWindow($h, $m, $d) } } @@ -137,10 +137,34 @@ function Test-SPDSCWebApplicationThrottlingConfig ) if ($testReturn -eq $true) { - if ((Test-SPDSCObjectHasProperty $DesiredSettings "HappyHour") -eq $true) - { + if ($null -ne $DesiredSettings.HappyHour) + { + $DesiredHappyHour = @{} + if ($null -ne $DesiredSettings.HappyHour.Hour) + { + $DesiredHappyHour.Add("Hour",[int32]$DesiredSettings.HappyHour.Hour) + } + else + { + $DesiredHappyHour.Add("Hour",$null) + } + if ($null -ne $DesiredSettings.HappyHour.Minute) + { + $DesiredHappyHour.Add("Minute",[int32]$DesiredSettings.HappyHour.Minute) + } else + { + $DesiredHappyHour.Add("Minute",$null) + } + if ($null -ne $DesiredSettings.HappyHour.Duration) + { + $DesiredHappyHour.Add("Duration",[int32]$DesiredSettings.HappyHour.Duration) + } else + { + $DesiredHappyHour.Add("Duration",$null) + } + $testReturn = Test-SPDscParameterState -CurrentValues $CurrentSettings.HappyHour ` - -DesiredValues $DesiredSettings.HappyHour ` + -DesiredValues $DesiredHappyHour ` -ValuesToCheck @("Hour", "Minute", "Duration") } } diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index 44bf7c16d..8e4ece0d4 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '1.6.0.0' +ModuleVersion = '1.7.0.0' # ID used to uniquely identify this module GUID = '6c1176a0-4fac-4134-8ca2-3fa8a21a7b90' @@ -24,7 +24,7 @@ Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' # Copyright statement for this module -Copyright = '(c) 2015-2016 Microsoft Corporation. All rights reserved.' +Copyright = '(c) 2015-2017 Microsoft Corporation. All rights reserved.' # Description of the functionality provided by this module Description = 'This DSC module is used to deploy and configure SharePoint Server 2013 and 2016, and covers a wide range of areas including web apps, service apps and farm configuration.' @@ -125,32 +125,54 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = ' -* Updated SPWebApplication to allow Claims Authentication configuration -* Updated documentation in regards to guidance on installing binaries from - network locations instead of locally -* New resources: SPFarmPropertyBag -* Bugfix in SPSite, which wasnt returing the quota template name in a correct way -* Bugfix in SPAppManagementServiceApp which wasnt returning the correct database - name -* Bugfix in SPAccessServiceApp which did not return the database server -* Bugfix in SPDesignerSettings which filtered site collections with an incorrect - parameter -* Updated the parameters in SPFarmSolution to use the full namespace -* Bugfix in SPFarmsolution where it returned non declared parameters -* Corrected typo in parameter name in Get method of SPFeature -* Added check in SPHealAnalyzerRuleState for incorrect default rule schedule of - one rule -* Improved check for CloudSSA in SPSearchServiceApp -* Bugfix in SPSearchServiceApp in which the database and dbserver were not - returned correctly -* Improved runtime of SPSearchTopology by streamlining wait processes -* Fixed bug with SPSearchServiceApp that would throw an error about SDDL string -* Improved output of test results for AppVeyor and VS Code based test runs -* Fixed issue with SPWebAppPolicy if OS language is not En-Us -* Added SPFarm resource, set SPCreateFarm and SPJoinFarm as deprecated to be - removed in version 2.0 -' + ReleaseNotes = " +* Update SPSearchIndexPartition made ServiceAppName as a Key +* New resouce: SPTrustedRootAuthority +* Update SPFarmSolution to eject from loop after 30m. +* New resource: SPMachineTranslationServiceApp +* New resource: SPPowerPointAutomationServiceApp +* Bugfix in SPSearchFileType made ServiceAppName a key property. +* New resource: SPWebApplicationExtension +* Added new resource SPAccessServices2010 +* Added MSFT_SPSearchCrawlMapping Resource to manage Crawl Mappings for + Search Service Application +* Added new resource SPSearchAuthoritativePage +* Bugfix in SPWebAppThrottlingSettings for setting large list window time. +* Fix typo in method Get-TargetResource of SPFeature +* Fix bug in SPManagedAccount not returning the correct account name value +* Fix typo in method Get-TargetResource of SPSearchIndexPartition +* Update documentation of SPInstallLanguagePack to add guidance on package + change in SP2016 +* Added returning the required RunCentralAdmin parameter to + Get-TargetResource in SPFarm +* Added web role check for SPBlobCacheSettings +* Improved error message when rule could not be found in + SPHealthAnalyzerRuleState +* Extended the documentation to specify that the default value of Ensure + is Present +* Added documentation about the user of Host Header Site Collections and + the HostHeader parameter in SPWebApplication +* Fixed missing brackets in SPWebAppPolicy module file +* Fixed issue with SPSecureStoreServiceApp not returning database information +* Fixed issue with SPManagedMetadataServiceApp not returning ContentTypeHubUrl + in SP2016 +* Updated SPTrustedIdentityTokenIssuer to allow to specify the signing + certificate from file path as an alternative to the certificate store +* New resource: SPSearchCrawlerImpactRule +* Fixed issue in SPSite where the used template wasn't returned properly +* Fixed issue in SPWebApplicationGeneralSettings which didn't return the + security validation timeout properly +* Fixed bug in SPCreateFarm and SPJoinFarm when a SharePoint Server is already + joined to a farm +* Bugfix in SPContentDatabase for setting WarningSiteCount as 0. +* Fixing verbose message that identifies SP2016 as 2013 in MSFT_SPFarm +* Fixed SPProductUpdate looking for OSearch15 in SP2016 when stopping services +* Added TermStoreAdministrators property to SPManagedMetadataServiceApp +* Fixed an issue in SPSearchTopology that would leave a corrupt topology in + place if a server was removed and re-added to a farm +* Fixed bug in SPFarm that caused issues with database names that have dashes + in the names +" } # End of PSData hashtable diff --git a/Modules/SharePointDsc/en-US/about_SPFarmPropertyBag.help.txt b/Modules/SharePointDsc/en-US/about_SPFarmPropertyBag.help.txt index a00b751a4..0644d0bb4 100644 --- a/Modules/SharePointDsc/en-US/about_SPFarmPropertyBag.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPFarmPropertyBag.help.txt @@ -6,6 +6,9 @@ This resource is used to work with SharePoint Property Bags at the farm level. The account that runs this resource must be a farm administrator. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the property bag is configured. + .PARAMETER Key Key - string The key of the SPFarm property bag diff --git a/Modules/SharePointDsc/en-us/about_SPAccessServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPAccessServiceApp.help.txt index 97a87c451..af0142a8a 100644 --- a/Modules/SharePointDsc/en-us/about_SPAccessServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPAccessServiceApp.help.txt @@ -7,6 +7,9 @@ within the local SharePoint farm. The resource will provision and configure the Access Services Service Application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPAlternateUrl.help.txt b/Modules/SharePointDsc/en-us/about_SPAlternateUrl.help.txt index 7b760f0c1..c19dcabd8 100644 --- a/Modules/SharePointDsc/en-us/about_SPAlternateUrl.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPAlternateUrl.help.txt @@ -8,6 +8,9 @@ application. Alternatively a URL can be removed from a zone to ensure that it will remain empty and have no alternate URL. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the setting is configured. + .PARAMETER WebAppUrl Key - String The URL of the web application to apply the alternate URL to diff --git a/Modules/SharePointDsc/en-us/about_SPAppManagementServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPAppManagementServiceApp.help.txt index 19a8de71d..db0141d21 100644 --- a/Modules/SharePointDsc/en-us/about_SPAppManagementServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPAppManagementServiceApp.help.txt @@ -12,6 +12,9 @@ configuration does not match, these parameters are only used for the initial provisioning of the service application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the app management service application diff --git a/Modules/SharePointDsc/en-us/about_SPBCSServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPBCSServiceApp.help.txt index ce665a340..32597f9e7 100644 --- a/Modules/SharePointDsc/en-us/about_SPBCSServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPBCSServiceApp.help.txt @@ -12,6 +12,9 @@ these parameters are only used for the initial provisioning of the service application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the BCS service app diff --git a/Modules/SharePointDsc/en-us/about_SPContentDatabase.help.txt b/Modules/SharePointDsc/en-us/about_SPContentDatabase.help.txt index 3d4e5a760..1ef44784b 100644 --- a/Modules/SharePointDsc/en-us/about_SPContentDatabase.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPContentDatabase.help.txt @@ -9,6 +9,9 @@ that the specified SQL instance is a different instance that is currently in use. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the content database is provisioned. + .PARAMETER Name Key - String Specifies the name of the content database diff --git a/Modules/SharePointDsc/en-us/about_SPDatabaseAAG.help.txt b/Modules/SharePointDsc/en-us/about_SPDatabaseAAG.help.txt index 88c8d3578..834c30c21 100644 --- a/Modules/SharePointDsc/en-us/about_SPDatabaseAAG.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPDatabaseAAG.help.txt @@ -16,6 +16,9 @@ This resource requires the April 2014 CU to be installed. The required cmdlets have been added in this CU: http://support.microsoft.com/kb/2880551 + The default value for the Ensure parameter is Present. When not specifying this + parameter, the content database is added to the AAG. + .PARAMETER DatabaseName Key - string The name of the database to put in the AlwaysOn group diff --git a/Modules/SharePointDsc/en-us/about_SPDistributedCacheService.help.txt b/Modules/SharePointDsc/en-us/about_SPDistributedCacheService.help.txt index 0801e300f..f68a80185 100644 --- a/Modules/SharePointDsc/en-us/about_SPDistributedCacheService.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPDistributedCacheService.help.txt @@ -23,6 +23,9 @@ a server check the others for distributed cache, it does not provision the cache automatically on all servers. If a previous server in the sequence does + The default value for the Ensure parameter is Present. When not specifying this + parameter, the distributed cache is provisioned. + .PARAMETER Name Key - String A name to assign to this resource - not really used. For example - AppFabricCachingService diff --git a/Modules/SharePointDsc/en-us/about_SPExcelServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPExcelServiceApp.help.txt index c030f81a1..45dea7a37 100644 --- a/Modules/SharePointDsc/en-us/about_SPExcelServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPExcelServiceApp.help.txt @@ -7,6 +7,9 @@ within the local SharePoint farm. The resource will provision and configure the Excel Services Service Application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPFarmSolution.help.txt b/Modules/SharePointDsc/en-us/about_SPFarmSolution.help.txt index 9815b9600..89c6517d3 100644 --- a/Modules/SharePointDsc/en-us/about_SPFarmSolution.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPFarmSolution.help.txt @@ -10,6 +10,9 @@ are specified, the solution will be deployed to all web applications. If the solution does not contain resources scoped for web applications the property + The default value for the Ensure parameter is Present. When not specifying this + parameter, the solution is deployed. + .PARAMETER Name Key - string The filename of the WSP package diff --git a/Modules/SharePointDsc/en-us/about_SPFeature.help.txt b/Modules/SharePointDsc/en-us/about_SPFeature.help.txt index 5098c5c39..11006c2ee 100644 --- a/Modules/SharePointDsc/en-us/about_SPFeature.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPFeature.help.txt @@ -8,6 +8,9 @@ feature should be on or off. The name property is the name of the feature based on its folder name in the FEATURES folder in the SharePoint hive + The default value for the Ensure parameter is Present. When not specifying this + parameter, the feature is enabled. + .PARAMETER Name Key - string The name of the feature diff --git a/Modules/SharePointDsc/en-us/about_SPInstallLanguagePack.help.txt b/Modules/SharePointDsc/en-us/about_SPInstallLanguagePack.help.txt index 3d194324d..359d97f42 100644 --- a/Modules/SharePointDsc/en-us/about_SPInstallLanguagePack.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPInstallLanguagePack.help.txt @@ -5,8 +5,14 @@ This resource is used to install the SharePoint Language Pack binaries. The BinaryDir parameter should point to the path that setup.exe is located (not to - setup.exe itself). The BinaryInstallDays and BinaryInstallTime parameters - specify a window in which the update can be installed. This module depends on + setup.exe itself). + + The BinaryInstallDays and BinaryInstallTime parameters specify a window in which + the update can be installed. + + With SharePoint 2016, the Language Packs are offered as an EXE package. You have + to extract this package before installing, using the following command: + .\serverlanguagepack.exe /extract:[Extract Folder] .PARAMETER BinaryDir Key - String diff --git a/Modules/SharePointDsc/en-us/about_SPIrmSettings.help.txt b/Modules/SharePointDsc/en-us/about_SPIrmSettings.help.txt index e76d4df35..bb52a8c22 100644 --- a/Modules/SharePointDsc/en-us/about_SPIrmSettings.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPIrmSettings.help.txt @@ -6,6 +6,9 @@ This resource is used to manipulate the IRM settings in SharePoint, integrating it with AD RMS + The default value for the Ensure parameter is Present. When not specifying this + parameter, IRM is configured. + .PARAMETER Ensure Key - String Allowed values: Present, Absent diff --git a/Modules/SharePointDsc/en-us/about_SPManagedAccount.help.txt b/Modules/SharePointDsc/en-us/about_SPManagedAccount.help.txt index 5a2c06a0a..2db706949 100644 --- a/Modules/SharePointDsc/en-us/about_SPManagedAccount.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPManagedAccount.help.txt @@ -10,6 +10,9 @@ password change for the managed account, leaving these option out of the resource will ensure that no automatic password changing from SharePoint occurs. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the managed account is created. + .PARAMETER AccountName Key - string The username of the account diff --git a/Modules/SharePointDsc/en-us/about_SPManagedMetaDataServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPManagedMetaDataServiceApp.help.txt index be5f54070..de3fc3233 100644 --- a/Modules/SharePointDsc/en-us/about_SPManagedMetaDataServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPManagedMetaDataServiceApp.help.txt @@ -9,6 +9,9 @@ database server and database name properties are only used during provisioning, and will not be altered as part of the ongoing operation of the + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the managed metadata service application @@ -29,6 +32,10 @@ Write - string The name of the database for the service application +.PARAMETER TermStoreAdministrators + Write - string + A list of the users/groups who are administrators of the term store + .PARAMETER Ensure Write - string Allowed values: Present, Absent @@ -98,3 +105,34 @@ } +.EXAMPLE + This example shows how to deploy the Managed Metadata service app to the local SharePoint farm + and also include a specific list of users to be the term store administrators. + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPManagedMetaDataServiceApp ManagedMetadataServiceApp + { + Name = "Managed Metadata Service Application" + InstallAccount = $SetupAccount + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "SP_ManagedMetadata" + TermStoreAdministrators = @( + "CONTOSO\user1", + "CONTOSO\user2" + ) + } + } + } + + diff --git a/Modules/SharePointDsc/en-us/about_SPManagedPath.help.txt b/Modules/SharePointDsc/en-us/about_SPManagedPath.help.txt index 801447909..387889cd9 100644 --- a/Modules/SharePointDsc/en-us/about_SPManagedPath.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPManagedPath.help.txt @@ -11,6 +11,9 @@ host named site collections set HostHeader to true and the path will be created as a host header path to be applied for host named site collections. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the managed path is created. + .PARAMETER WebAppUrl Key - string The URL of the web application to apply the managed path to - this is ignored for host header web applications diff --git a/Modules/SharePointDsc/en-us/about_SPOfficeOnlineServerBinding.help.txt b/Modules/SharePointDsc/en-us/about_SPOfficeOnlineServerBinding.help.txt index aadeb9d63..ef9deab6c 100644 --- a/Modules/SharePointDsc/en-us/about_SPOfficeOnlineServerBinding.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPOfficeOnlineServerBinding.help.txt @@ -12,6 +12,9 @@ environment, the new bindings will all point to the one DNS Name. If used on an existing configuration that does not follow this rule, it will match only + The default value for the Ensure parameter is Present. When not specifying this + parameter, the zone is configured. + .PARAMETER Zone Key - string Allowed values: Internal-HTTP, Internal-HTTPS, External-HTTP, External-HTTPS diff --git a/Modules/SharePointDsc/en-us/about_SPPerformancePointServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPPerformancePointServiceApp.help.txt index bdaa14871..f3eb083f8 100644 --- a/Modules/SharePointDsc/en-us/about_SPPerformancePointServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPPerformancePointServiceApp.help.txt @@ -7,6 +7,9 @@ instances within the local SharePoint farm. The resource will provision and configure the Performance Point Service Application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPPublishServiceApplication.help.txt b/Modules/SharePointDsc/en-us/about_SPPublishServiceApplication.help.txt index d8058bdae..8ec9b8521 100644 --- a/Modules/SharePointDsc/en-us/about_SPPublishServiceApplication.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPPublishServiceApplication.help.txt @@ -18,6 +18,9 @@ * Search * Secure Store + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application to publish diff --git a/Modules/SharePointDsc/en-us/about_SPQuotaTemplate.help.txt b/Modules/SharePointDsc/en-us/about_SPQuotaTemplate.help.txt index d4c7475b8..e5c9a3473 100644 --- a/Modules/SharePointDsc/en-us/about_SPQuotaTemplate.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPQuotaTemplate.help.txt @@ -7,6 +7,9 @@ will be used to make sure a certain quota template exists or not. When it exists, it will also make sure the settings are configured as specified. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the quota template is created. + .PARAMETER Name Key - string The name of the quota template diff --git a/Modules/SharePointDsc/en-us/about_SPRemoteFarmTrust.help.txt b/Modules/SharePointDsc/en-us/about_SPRemoteFarmTrust.help.txt index 6f722fab2..18b12dcf4 100644 --- a/Modules/SharePointDsc/en-us/about_SPRemoteFarmTrust.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPRemoteFarmTrust.help.txt @@ -7,6 +7,9 @@ federating search results between two different SharePoint farms. The technique is described at + The default value for the Ensure parameter is Present. When not specifying this + parameter, the remote farm trust is created. + .PARAMETER Name Key - string A name of the remote farm, used to create token issuer and root authority diff --git a/Modules/SharePointDsc/en-us/about_SPSearchContentSource.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchContentSource.help.txt index 86807fd28..da63318da 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchContentSource.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchContentSource.help.txt @@ -6,6 +6,9 @@ This resource will deploy and configure a content source in a specified search service application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the content source is created. + .PARAMETER Name Key - String The name of the content source diff --git a/Modules/SharePointDsc/en-us/about_SPSearchCrawlRule.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchCrawlRule.help.txt index a958ee022..b8ad9d357 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchCrawlRule.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchCrawlRule.help.txt @@ -7,6 +7,9 @@ service application. You can create new rules, change existing rules and remove existing rules. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the crawl rule is created. + .PARAMETER Path Key - string The name of the search service application @@ -41,7 +44,7 @@ .PARAMETER Ensure Write - string Allowed values: Present, Absent - Present if the service app should exist, absent if it should not + Present if the crawl rule should exist, absent if it should not .PARAMETER InstallAccount Write - String diff --git a/Modules/SharePointDsc/en-us/about_SPSearchFileType.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchFileType.help.txt index 1fe356853..e90e7fa9b 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchFileType.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchFileType.help.txt @@ -7,12 +7,15 @@ service application. You can create new file types, change existing types and remove existing file types. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the file type is added. + .PARAMETER FileType Key - string The name of the file type .PARAMETER ServiceAppName - Required - string + Key - string The name of the search service application .PARAMETER Description @@ -30,7 +33,7 @@ .PARAMETER Ensure Write - string Allowed values: Present, Absent - Present if the service app should exist, absent if it should not + Present if the file type should exist, absent if it should not .PARAMETER InstallAccount Write - String diff --git a/Modules/SharePointDsc/en-us/about_SPSearchIndexPartition.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchIndexPartition.help.txt index bfe0c8333..e6b3f15e0 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchIndexPartition.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchIndexPartition.help.txt @@ -32,7 +32,7 @@ The directory that the index should use locally on each server to store data .PARAMETER ServiceAppName - Required - String + Key - String The name of the search service application .PARAMETER InstallAccount diff --git a/Modules/SharePointDsc/en-us/about_SPSearchResultSource.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchResultSource.help.txt index ff1a64d70..87ce4c00a 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchResultSource.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchResultSource.help.txt @@ -14,6 +14,9 @@ * Remote People Provider * Remote SharePoint Provider + The default value for the Ensure parameter is Present. When not specifying this + parameter, the result source is created. + .PARAMETER Name Key - String The name of the result source diff --git a/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt index 3cc2c55a8..fe9cf0f94 100644 --- a/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSearchServiceApp.help.txt @@ -11,6 +11,9 @@ the admin database which matches the name, and then "_analyticsreportingstore", "_crawlstore" and "_linkstore" databases as well). + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the search service application diff --git a/Modules/SharePointDsc/en-us/about_SPSecureStoreServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPSecureStoreServiceApp.help.txt index 578cb763b..dcd0d8d78 100644 --- a/Modules/SharePointDsc/en-us/about_SPSecureStoreServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSecureStoreServiceApp.help.txt @@ -8,6 +8,9 @@ specifics) are validated and set when the resource is run, the database values are only used in provisioning of the service application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the secure store service app diff --git a/Modules/SharePointDsc/en-us/about_SPServiceAppPool.help.txt b/Modules/SharePointDsc/en-us/about_SPServiceAppPool.help.txt index 2e03efde4..9f03c2ae0 100644 --- a/Modules/SharePointDsc/en-us/about_SPServiceAppPool.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPServiceAppPool.help.txt @@ -7,6 +7,9 @@ service applications. The account used for the service account must already be registered as a managed account (which can be provisioned through + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application pool is provisioned. + .PARAMETER Name Key - string The name of application pool diff --git a/Modules/SharePointDsc/en-us/about_SPServiceAppProxyGroup.help.txt b/Modules/SharePointDsc/en-us/about_SPServiceAppProxyGroup.help.txt index e8d98cc8a..c1e52446c 100644 --- a/Modules/SharePointDsc/en-us/about_SPServiceAppProxyGroup.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPServiceAppProxyGroup.help.txt @@ -20,6 +20,9 @@ ServiceAppProxiesToExclude properties needs to be specified. Do not combine the ServiceAppProxies property with the ServiceAppProxiesToInclude and + The default value for the Ensure parameter is Present. When not specifying this + parameter, the proxy group is created. + .PARAMETER Name Key - String Name of the Proxy Group to create diff --git a/Modules/SharePointDsc/en-us/about_SPServiceInstance.help.txt b/Modules/SharePointDsc/en-us/about_SPServiceInstance.help.txt index d060d6587..0b2342092 100644 --- a/Modules/SharePointDsc/en-us/about_SPServiceInstance.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPServiceInstance.help.txt @@ -7,6 +7,9 @@ (Ensure = "Present") or not running (Ensure = "Absent") on the current server. The name is the display name of the service as shown in the Central Admin + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service instance is started. + .PARAMETER Name Key - string The name of the service instance to manage diff --git a/Modules/SharePointDsc/en-us/about_SPSessionStateService.help.txt b/Modules/SharePointDsc/en-us/about_SPSessionStateService.help.txt index 3a4475ba3..8949c9c96 100644 --- a/Modules/SharePointDsc/en-us/about_SPSessionStateService.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSessionStateService.help.txt @@ -7,6 +7,9 @@ the name of the database server and database name to provision the app with, and optionally include the session timeout value. If session timeout is not + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER DatabaseName Key - string The name of the database for the service diff --git a/Modules/SharePointDsc/en-us/about_SPSite.help.txt b/Modules/SharePointDsc/en-us/about_SPSite.help.txt index 5200bcc96..fe3bb4a3b 100644 --- a/Modules/SharePointDsc/en-us/about_SPSite.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSite.help.txt @@ -11,6 +11,13 @@ of a site collection, the additional parameters are not checked for yet, but will be in a later release + Note: When creating Host Header Site Collections, do not use the HostHeader + parameter in SPWebApplication. This will set the specified host header on your + IIS site and prevent the site from listening for the URL of the Host Header + Site Collection. + If you want to change the IIS website binding settings, please use the xWebsite + resource in the xWebAdministration module. + .PARAMETER Url Key - string The URL of the site collection diff --git a/Modules/SharePointDsc/en-us/about_SPStateServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPStateServiceApp.help.txt index 353665277..98947110b 100644 --- a/Modules/SharePointDsc/en-us/about_SPStateServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPStateServiceApp.help.txt @@ -7,6 +7,9 @@ The database specific parameters are only used during initial provisioning of the app, and will not change database settings beyond the initial deployment. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the state service app diff --git a/Modules/SharePointDsc/en-us/about_SPSubscriptionSettingsServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPSubscriptionSettingsServiceApp.help.txt index 8928a38f9..5cfe78035 100644 --- a/Modules/SharePointDsc/en-us/about_SPSubscriptionSettingsServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPSubscriptionSettingsServiceApp.help.txt @@ -12,6 +12,9 @@ not match, these parameters are only used for the initial provisioning of the service application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the subscription settings service app diff --git a/Modules/SharePointDsc/en-us/about_SPTrustedIdentityTokenIssuer.help.txt b/Modules/SharePointDsc/en-us/about_SPTrustedIdentityTokenIssuer.help.txt index 0b0259d25..d184884a5 100644 --- a/Modules/SharePointDsc/en-us/about_SPTrustedIdentityTokenIssuer.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPTrustedIdentityTokenIssuer.help.txt @@ -6,18 +6,22 @@ This resource is used to create or remove SPTrustedIdentityTokenIssuer in a SharePoint farm. - The SigningCertificateThumbPrint must match the thumbprint of a certificate in - the store LocalMachine\My of the server that will run this resource. + Either parameter SigningCertificateThumbPrint or SigningCertificateFilePath + must be set, but not both. + + The SigningCertificateThumbPrint must be the thumbprint of the signing + certificate stored in the certificate store LocalMachine\My of the server + Note that the private key of the certificate must not be available in the certiificate store because SharePoint does not accept it. - Once the SPTrustedIdentityTokenIssuer is successfully created, the certificate - can be safely deleted from the certificate store as it won't be needed by - SharePoint. - ClaimsMappings is an array of MSFT_SPClaimTypeMapping to use with cmdlet - New-SPClaimTypeMapping. Each MSFT_SPClaimTypeMapping requires properties Name - and IncomingClaimType. Property LocalClaimType is not required if its value is - identical to IncomingClaimType. + The SigningCertificateFilePath must be the file path to the public key of + the signing certificate. + + The ClaimsMappings property is an array of MSFT_SPClaimTypeMapping to use + with cmdlet New-SPClaimTypeMapping. Each MSFT_SPClaimTypeMapping requires + properties Name and IncomingClaimType. Property LocalClaimType is not + required if its value is identical to IncomingClaimType. The IdentifierClaim property must match an IncomingClaimType element in ClaimsMappings array. @@ -25,6 +29,9 @@ The ClaimProviderName property can be set to specify a custom claims provider. It must be already installed in the SharePoint farm and returned by cmdlet + The default value for the Ensure parameter is Present. When not specifying this + parameter, the token issuer is created. + .PARAMETER Name Key - String Name of the SPTrustedIdentityTokenIssuer @@ -49,9 +56,13 @@ Required - String Array of MSFT_SPClaimTypeMapping to use with cmdlet New-SPClaimTypeMapping -.PARAMETER SigningCertificateThumbPrint - Required - String - Thumbprint of the signing certificate to use with this SPTrustedIdentityTokenIssuer. It must match the thumbprint of a certificate located in store LocalMachine\\My +.PARAMETER SigningCertificateThumbprint + Write - String + Specify the thumbprint of the signing certificate, which must be located in certificate store LocalMachine\\My + +.PARAMETER SigningCertificateFilePath + Write - String + Specify the file path to the signing certificate if it is not stored in the local certificate store already .PARAMETER ClaimProviderName Write - String @@ -92,7 +103,49 @@ Realm = "https://sharepoint.contoso.com" SignInUrl = "https://adfs.contoso.com/adfs/ls/" IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" - ClaimsMappings = @( + ClaimsMappings = @( + MSFT_SPClaimTypeMapping{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } + MSFT_SPClaimTypeMapping{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } + ) + SigningCertificateThumbPrint = "F0D3D9D8E38C1D55A3CEF3AAD1C18AD6A90D5628" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } + + +.EXAMPLE + This example deploys a trusted token issuer to the local farm. + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPTrustedIdentityTokenIssuer SampleSPTrust + { + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( MSFT_SPClaimTypeMapping{ Name = "Email" IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" @@ -103,7 +156,7 @@ LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } ) - SigningCertificateThumbPrint = "F3229E7CCA1DA812E29284B0ED75A9A019A83B08" + SigningCertificateFilePath = "F:\Data\DSC\FakeSigning.cer" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" diff --git a/Modules/SharePointDsc/en-us/about_SPUsageApplication.help.txt b/Modules/SharePointDsc/en-us/about_SPUsageApplication.help.txt index 792833626..f072a5703 100644 --- a/Modules/SharePointDsc/en-us/about_SPUsageApplication.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUsageApplication.help.txt @@ -7,6 +7,9 @@ application. The database settings are only used for initial provisioning, but the usage settings can be changed and will be enforced as the resource is + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileProperty.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileProperty.help.txt index 5cbadf212..6b170b01b 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileProperty.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileProperty.help.txt @@ -16,6 +16,9 @@ This Resource doesn't currently support removing existing user profile + The default value for the Ensure parameter is Present. When not specifying this + parameter, the user profile property is created. + .PARAMETER Name Key - string The internal name of the user profile property diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileSection.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileSection.help.txt index c0c703eb9..062bde77c 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileSection.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileSection.help.txt @@ -9,6 +9,9 @@ If no DisplayOrder is added then SharePoint will automatically assigned an ID + The default value for the Ensure parameter is Present. When not specifying this + parameter, the user profile section is created. + .PARAMETER Name Key - string The internal name of the user profile section diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt index c480c99db..d112b75f9 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileServiceApp.help.txt @@ -11,6 +11,9 @@ done to ensure that the databases are created with the correct schema owners and allow the user profile sync service to operate correctly. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the user profile service diff --git a/Modules/SharePointDsc/en-us/about_SPUserProfileSyncService.help.txt b/Modules/SharePointDsc/en-us/about_SPUserProfileSyncService.help.txt index ece5ed05f..209cf882b 100644 --- a/Modules/SharePointDsc/en-us/about_SPUserProfileSyncService.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPUserProfileSyncService.help.txt @@ -14,6 +14,9 @@ the Administrators group. Therefore this resource will add the FarmAccount credential to the local administrators group at the beginning of the set + The default value for the Ensure parameter is Present. When not specifying this + parameter, the user profile sync service is provisioned. + .PARAMETER UserProfileServiceAppName Key - string The name of the user profile service for this sync instance diff --git a/Modules/SharePointDsc/en-us/about_SPVisioServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPVisioServiceApp.help.txt index 056f4a873..fe74ec48b 100644 --- a/Modules/SharePointDsc/en-us/about_SPVisioServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPVisioServiceApp.help.txt @@ -7,6 +7,9 @@ instances within the local SharePoint farm. The resource will provision and configure the Visio Graphics Service Application. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPWeb.help.txt b/Modules/SharePointDsc/en-us/about_SPWeb.help.txt index 22e37e5ee..79e332fab 100644 --- a/Modules/SharePointDsc/en-us/about_SPWeb.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWeb.help.txt @@ -6,6 +6,9 @@ This resource will provision a SPWeb based on the settings that are passed through. These settings map to the New-SPWeb cmdlet and accept the same values + The default value for the Ensure parameter is Present. When not specifying this + parameter, the web is created. + .PARAMETER Url Key - string The URL of the web diff --git a/Modules/SharePointDsc/en-us/about_SPWebAppProxyGroup.help.txt b/Modules/SharePointDsc/en-us/about_SPWebAppProxyGroup.help.txt index aa99691ff..12151f76f 100644 --- a/Modules/SharePointDsc/en-us/about_SPWebAppProxyGroup.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWebAppProxyGroup.help.txt @@ -19,7 +19,7 @@ .PARAMETER ServiceAppProxyGroup Required - string - Name of the Service Applicaiton Proxy Group + Name of the Service Application Proxy Group .PARAMETER InstallAccount Write - String diff --git a/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt b/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt index fee145788..a37cb4587 100644 --- a/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWebApplication.help.txt @@ -8,6 +8,16 @@ the current settings, and then ensure that it stays part of the correct application pool beyond that (additional checking and setting of properties + The default value for the Ensure parameter is Present. When not specifying this + parameter, the web application is provisioned. + + Note: When using Host Header Site Collections, do not use the HostHeader + parameter in SPWebApplication. This will set the specified host header on your + IIS site and prevent the site from listening for the URL of the Host Header + Site Collection. + If you want to change the IIS website binding settings, please use the xWebsite + resource in the xWebAdministration module. + .PARAMETER Name Key - string The name of the web application diff --git a/Modules/SharePointDsc/en-us/about_SPWebApplicationExtension.help.txt b/Modules/SharePointDsc/en-us/about_SPWebApplicationExtension.help.txt new file mode 100644 index 000000000..461b6a58c --- /dev/null +++ b/Modules/SharePointDsc/en-us/about_SPWebApplicationExtension.help.txt @@ -0,0 +1,101 @@ +.NAME + SPWebApplicationExtension + +# Description + + This resource is responsible for extending an existing web application into a new + zone. The resource will provision the web application extension with all of + the current settings, and then ensure that it stays present and will ensure the + AllowAnonymous and Authentication methods remain consistent. Please note that this + currently does not support changing the claims provider on an existing claims + enabled web application externsion. + +.PARAMETER WebAppUrl + Key - string + The URL of the parent web application + +.PARAMETER Name + Required - string + The name of the web application extension + +.PARAMETER Url + Required - string + The URL of the web application extension + +.PARAMETER Zone + Key - string + Allowed values: Default, Intranet, Internet, Extranet, Custom + Specifies one of the five zones with which the internal URL of this new extension is to be associated. + +.PARAMETER AllowAnonymous + Write - boolean + Should anonymous access be enabled for this web app extension + +.PARAMETER AuthenticationMethod + Write - string + Allowed values: NTLM, Kerberos, Claims + What authentication mode should be used for the web app extension + +.PARAMETER AuthenticationProvider + Write - string + What authentication provider should be used for the web app. This value is required when AuthenticationMethod is set to Claims + +.PARAMETER HostHeader + Write - string + The host header to use for the web app extension + +.PARAMETER Path + Write - string + The path on the local servers to host the IIS web site from + +.PARAMETER Port + Write - string + The port to run the site on + +.PARAMETER UseSSL + Write - boolean + Should this web app extension use SSL + +.PARAMETER Ensure + Write - string + Allowed values: Present, Absent + Present if the web app should exist, absent if it should not + +.PARAMETER InstallAccount + Write - string + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + +.EXAMPLE + This example shows how to create a new web application extension in the local farm + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPWebApplicationExtension IntranetZone + { + WebAppUrl = "http://example.contoso.local" + Name = "Contoso Intranet Zone" + AllowAnonymous = $false + AuthenticationMethod = "NTLM" + Url = "http://intranet.contoso.local" + Zone = "Intranet" + HostHeader = "intranet.contoso.local" + Path = "c:\inetpub\wwwroot\wss\VirtualDirectories\intranet" + UseSSL = $false + Port = 80 + Ensure = "Present" + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-us/about_SPWordAutomationServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPWordAutomationServiceApp.help.txt index d45fe3fc8..4f031c8e7 100644 --- a/Modules/SharePointDsc/en-us/about_SPWordAutomationServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWordAutomationServiceApp.help.txt @@ -13,6 +13,9 @@ are allowed (with the exception of Name, InstallAccount or PsDscRunAsCredential). + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string THe name of the service application diff --git a/Modules/SharePointDsc/en-us/about_SPWorkManagementServiceApp.help.txt b/Modules/SharePointDsc/en-us/about_SPWorkManagementServiceApp.help.txt index 4232f7cb6..979c2cf81 100644 --- a/Modules/SharePointDsc/en-us/about_SPWorkManagementServiceApp.help.txt +++ b/Modules/SharePointDsc/en-us/about_SPWorkManagementServiceApp.help.txt @@ -16,6 +16,9 @@ MinimumTimeBetweenProviderRefreshes, MinimumTimeBetweenSearchQueries are in minutes. + The default value for the Ensure parameter is Present. When not specifying this + parameter, the service application is provisioned. + .PARAMETER Name Key - string The name of the work management service application diff --git a/Tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 new file mode 100644 index 000000000..30ac90ec7 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 @@ -0,0 +1,525 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPPowerPointAutomationServiceApp" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + $getTypeFullName = "Microsoft.Office.Server.PowerPoint.Administration.PowerPointConversionServiceApplication" + + # Mocks for all + Mock -CommandName Get-SPServiceApplication -MockWith { } + Mock -CommandName Get-SPServiceApplicationPool -MockWith { } + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { } + + Mock -CommandName New-SPPowerPointConversionServiceApplication -MockWith { } + Mock -CommandName New-SPPowerPointConversionServiceApplicationProxy -MockWith { } + Mock -CommandName Remove-SPServiceApplication -MockWith { } + + # Test contexts + Context -Name "When Ensure is Absent and we specify additional paramters" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Absent" + } + + It "Should throw an exception as additional parameters are not allowed when Ensure = 'Absent'" { + { Get-TargetResource @testParams } | Should throw "You cannot use any of the parameters when Ensure is specified as Absent" + { Test-TargetResource @testParams } | Should throw "You cannot use any of the parameters when Ensure is specified as Absent" + { Set-TargetResource @testParams } | Should throw "You cannot use any of the parameters when Ensure is specified as Absent" + } + } + + Context -Name "When Ensure is Present but we don't specify an ApplicationPool" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return $null + } + + It "Should throw an exception as additional parameters are not allowed when Ensure = 'Absent'" { + { Get-TargetResource @testParams } | Should throw "An Application Pool is required to configure the PowerPoint Automation Service Application" + { Test-TargetResource @testParams } | Should throw "An Application Pool is required to configure the PowerPoint Automation Service Application" + { Set-TargetResource @testParams } | Should throw "An Application Pool is required to configure the PowerPoint Automation Service Application" + } + } + + + + Context -Name "When no service applications exist in the current farm" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + Mock -CommandName New-SPPowerPointConversionServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = 0 + MaximumConversionsPerWorker = 0 + WorkerKeepAliveTimeoutInSeconds = 0 + WorkerProcessCount = 0 + WorkerTimeoutInSeconds = 0 + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + return @{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = $testParams.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $testParams.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $testParams.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $testParams.WorkerProcessCount + WorkerTimeoutInSeconds = $testParams.WorkerTimeoutInSeconds + } + } -PassThru -Force + return $($spServiceApp) + + } + Mock -CommandName New-SPPowerPointConversionServiceApplicationProxy -MockWith { } + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (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 create a new PowerPoint Automation Service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplicationPool -Times 1 + Assert-MockCalled New-SPPowerPointConversionServiceApplication -Times 1 + Assert-MockCalled New-SPPowerPointConversionServiceApplicationProxy -Times 1 + } + + } + + Context -Name "When service applications exist in the current farm but the specific PowerPoint Automation Services app does not" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + Mock -CommandName New-SPPowerPointConversionServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = 0 + MaximumConversionsPerWorker = 0 + WorkerKeepAliveTimeoutInSeconds = 0 + WorkerProcessCount = 0 + WorkerTimeoutInSeconds = 0 + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + return @{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = $testParams.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $testParams.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $testParams.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $testParams.WorkerProcessCount + WorkerTimeoutInSeconds = $testParams.WorkerTimeoutInSeconds + } + } -PassThru -Force + return $($spServiceApp) + + } + + Mock -CommandName New-SPPowerPointConversionServiceApplicationProxy -MockWith { } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.Office.UnKnownWebServiceApplication" + } + } -PassThru -Force + return $($spServiceApp) + } + + It "Should return 'Absent' from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + It "Should return 'false' from the Test method" { + Test-TargetResource @testParams | Should Be $false + } + It "Should create a new Power Point Automation Service Application from the Set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplicationPool + Assert-MockCalled New-SPPowerPointConversionServiceApplication + Assert-MockCalled New-SPPowerPointConversionServiceApplicationProxy + } + } + + Context -Name "When service applications should exist but the application pool doesn't exist" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.Office.UnKnownWebServiceApplication" + } + } -PassThru -Force + return $($spServiceApp) + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return $null + } + + It "Should return 'Absent' from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + It "Should return 'false' from the Test method" { + Test-TargetResource @testParams | Should Be $false + } + It "Should create a new Power Point Automation Service Application from the Set method" { + { Set-TargetResource @testParams } | Should throw "Specified application pool does not exist" + } + } + + Context -Name "When a service application exists and is configured correctly" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = $testParams.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $testParams.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $testParams.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $testParams.WorkerProcessCount + WorkerTimeoutInSeconds = $testParams.WorkerTimeoutInSeconds + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = $getTypeFullName + } + } -PassThru -Force + + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + return $true + } -PassThru -Force + + return $($spServiceApp) + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @{ + Name = $testParams.ProxyName + } + } + + It "Should return Present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "When a service application exists but has a new Proxy Assignment" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = $testParams.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $testParams.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $testParams.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $testParams.WorkerProcessCount + WorkerTimeoutInSeconds = $testParams.WorkerTimeoutInSeconds + + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = $getTypeFullName + } + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType SCriptMethod ` + -Name IsConnected ` + -Value { + return $true + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + return @{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + CacheExpirationPeriodInSeconds = $testParams.CacheExpirationPeriodInSeconds + MaximumConversionsPerWorker = $testParams.MaximumConversionsPerWorker + WorkerKeepAliveTimeoutInSeconds = $testParams.WorkerKeepAliveTimeoutInSeconds + WorkerProcessCount = $testParams.WorkerProcessCount + WorkerTimeoutInSeconds = $testParams.WorkerTimeoutInSeconds + } + } -PassThru -Force + + return $($spServiceApp) + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + $spServiceAppProxy = [PSCustomObject]@{ + Name = "$($testParams.ProxyName) other" + } + $spServiceAppProxy | Add-Member -MemberType SCriptMethod ` + -Name Delete ` + -Value { + return $null + } -PassThru -Force + + return $spServiceAppProxy + } + + It "Should return Present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + It "Should call Get-SPServiceApplicationProxy when Set method is called." { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplicationProxy + } + } + + Context -Name "When a service application exists but has a new Application Pool Assignment" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = "Other SharePoint Services App Pool" } + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = $getTypeFullName + } + } -PassThru -Force + return $spServiceApp + } + + It "Should return Present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When the service application exists but it shouldn't" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = $getTypeFullName + } + } -PassThru -Force + return $spServiceApp + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the remove service application cmdlet in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + } + } + + Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "When a service application doesn't exists but it should" -Fixture { + $testParams = @{ + Name = "Power Point Automation Service Application" + ProxyName = "Power Point Automation Service Application Proxy" + ApplicationPool = "SharePoint Services App Pool" + CacheExpirationPeriodInSeconds = 600 + MaximumConversionsPerWorker = 5 + WorkerKeepAliveTimeoutInSeconds = 120 + WorkerProcessCount = 3 + WorkerTimeoutInSeconds = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $nulls + } + + It "Should return Absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPAccessServices2010.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPAccessServices2010.Tests.ps1 new file mode 100644 index 000000000..e946372ec --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPAccessServices2010.Tests.ps1 @@ -0,0 +1,197 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPAccessServices2010" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + $getTypeFullName = "Microsoft.Office.Access.Server.MossHost.AccessServerWebServiceApplication" + + # Mocks for all contexts + Mock -CommandName Get-SPServiceApplication -MockWith { } + Mock -CommandName New-SPAccessServiceApplication -MockWith { } + Mock -CommandName Remove-SPServiceApplication -MockWith { } + + # Test contexts + Context -Name "When Access 2010 Services doesn't exists and should exist" -Fixture { + $testParams = @{ + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + Ensure = "Present" + } + + Mock -CommandName Remove-SPServiceApplication -MockWith {} + Mock -CommandName New-SPAccessServiceApplication -MockWith {} + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "$($getTypeFullName).other" + } + } -PassThru -Force + return @($spServiceApp) + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + It "Should call Methods on Set-TargetResource" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplication + Assert-MockCalled New-SPAccessServiceApplication -Times 1 + Assert-MockCalled Remove-SPServiceApplication -Times 0 + } + } + Context -Name "When Access 2010 Services exists and should exist" -Fixture { + $testParams = @{ + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + Ensure = "Present" + } + + Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName New-SPAccessServiceApplication -MockWith { } + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = [PSCustomObject]@{ + Name = $testParams.ApplicationPool + } + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "$($getTypeFullName)" + } + } -PassThru -Force + return @($spServiceApp) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + It "Should call Remove - Get - New on Set-TargetResource" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplication + + } + } + + Context -Name "When Access 2010 Services exists and shouldn't exist" -Fixture { + $testParams = @{ + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + Ensure = "Absent" + } + + Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName New-SPAccessServiceApplication -MockWith { } + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + ApplicationPool = [PSCustomObject]@{ + Name = $testParams.ApplicationPool + } + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "$($getTypeFullName)" + } + } -PassThru -Force + return @($spServiceApp) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + It "Should call Remove - Get - New on Set-TargetResource" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + Assert-MockCalled Get-SPServiceApplication + } + } + + Context -Name "When Access 2010 Services doesn't exists and should exist" -Fixture { + $testParams = @{ + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + Ensure = "Present" + } + + Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName New-SPAccessServiceApplication -MockWith { } + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the get method" { + (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 call New on Set-TargetResource" { + Set-TargetResource @testParams + Assert-MockCalled New-SPAccessServiceApplication + } + } + + Context -Name "When Access 2010 Services doesn't exists and shouldn't exist" -Fixture { + $testParams = @{ + Name = "Access 2010 Services Service Application" + ApplicationPool = "SharePoint Service Applications" + Ensure = "Absent" + } + + Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName New-SPAccessServiceApplication -MockWith { } + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + It "Should call New on Set-TargetResource" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPServiceApplication + } + } + } +} + + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 index 353476c97..871df7caa 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 @@ -47,6 +47,12 @@ namespace Microsoft.SharePoint.Administration { } } + Mock -CommandName Get-SPServiceInstance -MockWith { + return @(@{ + TypeName = "Microsoft SharePoint Foundation Web Application" + }) + } + function Update-SPDscTestConfigFile { [CmdletBinding()] @@ -303,6 +309,39 @@ namespace Microsoft.SharePoint.Administration { $webcfg.configuration.SharePoint.BlobCache.enabled | Should Be "False" } } + + Context -Name "The server doesn't have the web application role running" { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Zone = "Default" + EnableCache = $true + Location = "c:\BlobCache" + MaxSizeInGB = 30 + FileTypes = "\.(gif|jpg|jpeg)$" + } + + Update-SPDscTestConfigFile -Content ' + + + + +' + + Mock -CommandName Test-Path -MockWith { return $true } + Mock -CommandName Get-SPServiceInstance -MockWith { return $null } + + It "Should return values from the get method" { + (Get-TargetResource @testParams).WebAppUrl | Should BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw exception in the set method" { + { Set-TargetResource @testParams } | Should throw "Server isn't running the Web Application role" + } + } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPCreateFarm.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPCreateFarm.Tests.ps1 index 9253a7b45..c66073dcd 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPCreateFarm.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPCreateFarm.Tests.ps1 @@ -26,15 +26,25 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $mockPassphrase = New-Object -TypeName "System.Management.Automation.PSCredential" ` -ArgumentList @("PASSPHRASEUSER", $mockPassword) + $modulePath = "Modules\SharePointDsc\Modules\SharePointDsc.Farm\SPFarm.psm1" + Import-Module -Name (Join-Path -Path $Global:SPDscHelper.RepoRoot -ChildPath $modulePath -Resolve) + # Mocks for all contexts Mock -CommandName New-SPConfigurationDatabase -MockWith {} Mock -CommandName Install-SPHelpCollection -MockWith {} - Mock Initialize-SPResourceSecurity -MockWith {} + Mock -CommandName Initialize-SPResourceSecurity -MockWith {} Mock -CommandName Install-SPService -MockWith {} Mock -CommandName Install-SPFeature -MockWith {} Mock -CommandName New-SPCentralAdministration -MockWith {} Mock -CommandName Install-SPApplicationContent -MockWith {} - + Mock -CommandName Get-SPDSCConfigDBStatus -MockWith { + return @{ + Locked = $false + ValidPermissions = $true + DatabaseExists = $false + } + } -Verifiable + # Test contexts Context -Name "no farm is configured locally and a supported version of SharePoint is installed" -Fixture { $testParams = @{ @@ -45,6 +55,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { AdminContentDatabaseName = "Admin_Content" CentralAdministrationAuth = "Kerberos" CentralAdministrationPort = 1234 + } + + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } } Mock -CommandName Get-SPFarm -MockWith { throw "Unable to detect local farm" } @@ -158,6 +175,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ServerRole = "ApplicationWithSearch" } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } + } + Mock -CommandName Get-SPDSCInstalledProductVersion -MockWith { return @{ FileMajorPart = 16 @@ -208,6 +232,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { CentralAdministrationPort = 1234 } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $testParams.FarmConfigDatabaseName + } + } + Mock -CommandName Get-SPFarm -MockWith { return @{ DefaultServiceAccount = @{ @@ -246,6 +277,63 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "a farm exists locally, is the correct farm but SPFarm is not reachable" -Fixture { + $testParams = @{ + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "DatabaseServer\Instance" + FarmAccount = $mockFarmAccount + Passphrase = $mockPassphrase + AdminContentDatabaseName = "Admin_Content" + CentralAdministrationAuth = "Kerberos" + CentralAdministrationPort = 1234 + } + + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $testParams.FarmConfigDatabaseName + } + } + + Mock -CommandName Get-SPFarm -MockWith { return $null } + + Mock -CommandName Get-SPDatabase -MockWith { + return @(@{ + Name = $testParams.FarmConfigDatabaseName + Type = "Configuration Database" + Server = @{ + Name = $testParams.DatabaseServer + } + }) + } + + Mock -CommandName Get-SPWebApplication -MockWith { + return @(@{ + IsAdministrationWebApplication = $true + ContentDatabases = @(@{ + Name = $testParams.AdminContentDatabaseName + }) + Url = "http://$($env:ComputerName):$($testParams.CentralAdministrationPort)" + }) + } + + Mock -CommandName Get-SPDSCConfigDBStatus -MockWith { + return @{ + Locked = $true + ValidPermissions = $false + DatabaseExists = $true + } + } + + It "Should throw when server already joined to farm but SPFarm not reachable" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw when the current user does not have sufficient permissions to SQL Server" { + { Set-TargetResource @testParams } | Should Throw + } + } + Context -Name "a farm exists locally and is not the correct farm" -Fixture { $testParams = @{ FarmConfigDatabaseName = "SP_Config" @@ -257,6 +345,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { CentralAdministrationPort = 1234 } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return "WrongDBName" + } + } + Mock -CommandName Get-SPFarm -MockWith { return @{ DefaultServiceAccount = @{ Name = $testParams.FarmAccount.UserName } @@ -300,6 +395,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { CentralAdministrationPort = 1234 } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $testParams.FarmConfigDatabaseName + } + } + Mock -CommandName Get-SPFarm -MockWith { return @{ DefaultServiceAccount = @{ Name = "WRONG\account" } @@ -344,6 +446,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { CentralAdministrationAuth = "Kerberos" } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } + } + It "uses a default value for the central admin port" { Set-TargetResource @testParams Assert-MockCalled New-SPCentralAdministration -ParameterFilter { $Port -eq 9999 } @@ -359,6 +468,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { AdminContentDatabaseName = "Admin_Content" } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } + } + It "uses NTLM for the Central Admin web application authentication" { Set-TargetResource @testParams Assert-MockCalled New-SPCentralAdministration -ParameterFilter { $WindowsAuthProvider -eq "NTLM" } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarmSolution.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarmSolution.Tests.ps1 index 3c6e5c002..52a854bbd 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarmSolution.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarmSolution.Tests.ps1 @@ -19,14 +19,14 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope # Initialize tests - + # Mocks for all contexts Mock -CommandName Update-SPSolution -MockWith { } - Mock -CommandName Wait-SPDSCSolutionJob -MockWith { } Mock -CommandName Install-SPFeature -MockWith { } Mock -CommandName Install-SPSolution -MockWith { } Mock -CommandName Uninstall-SPSolution -MockWith { } Mock -CommandName Remove-SPSolution -MockWith { } + Mock -CommandName Start-Sleep -MockWith { } # Test contexts Context -Name "The solution isn't installed, but should be" -Fixture { @@ -73,10 +73,76 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "uploads and installes the solution to the farm" { Set-TargetResource @testParams + Assert-MockCalled Add-SPSolution + Assert-MockCalled Install-SPSolution + + } + } + + Context -Name "The solution isn't installed, but should be with loop testing" -Fixture { + $testParams = @{ + Name = "SomeSolution" + LiteralPath = "\\server\share\file.wsp" + Deployed = $true + Ensure = "Present" + Version = "1.0.0.0" + WebApplications = @("http://app1", "http://app2") + } + + $global:SPDscSolutionAdded = $false + $global:SPDscLoopCount = 0 + + Mock -CommandName Get-SPSolution -MockWith { + $global:SPDscLoopCount = $global:SPDscLoopCount + 1 + $index = $global:SPDscLoopCount + if($global:SPDscSolutionAdded) + { + if($index -gt 2) + { + return @{ + JobExists = $false + } + } + else + { + return @{ + JobExists = $true + } + } + } + else + { + return $null + } + } + Mock -CommandName Add-SPSolution -MockWith { + $solution = [pscustomobject] @{ Properties = @{ Version = "" }} + $solution | Add-Member -Name Update -MemberType ScriptMethod -Value { } + $global:SPDscSolutionAdded = $true + return $solution + } + + + It "Should return the expected empty values from the get method" { + $global:SPDscLoopCount = 0 + $getResults = Get-TargetResource @testParams + $getResults.Ensure | Should Be "Absent" + $getResults.Version | Should Be "0.0.0.0" + $getResults.Deployed | Should Be $false + } + + It "Should return false from the test method" { + $global:SPDscLoopCount = 0 + Test-TargetResource @testParams | Should Be $false + } + + It "uploads and installes the solution to the farm" { + $global:SPDscLoopCount = 0 + Set-TargetResource @testParams Assert-MockCalled Add-SPSolution Assert-MockCalled Install-SPSolution - Assert-MockCalled Wait-SPDSCSolutionJob + } } @@ -113,9 +179,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "uninstalles and removes the solution from the web apps and the farm" { Set-TargetResource @testParams - Assert-MockCalled Uninstall-SPSolution - Assert-MockCalled Wait-SPDSCSolutionJob Assert-MockCalled Remove-SPSolution } } @@ -180,10 +244,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should update the solution in the set method" { Set-TargetResource @testParams - Assert-MockCalled Update-SPSolution Assert-MockCalled Install-SPFeature - Assert-MockCalled Wait-SPDSCSolutionJob } } @@ -258,7 +320,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Remove-SPSolution Assert-MockCalled Add-SPSolution Assert-MockCalled Install-SPSolution - Assert-MockCalled Wait-SPDSCSolutionJob } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPJoinFarm.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPJoinFarm.Tests.ps1 index 049b82b94..7fac28993 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPJoinFarm.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPJoinFarm.Tests.ps1 @@ -24,16 +24,26 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $mockPassphraseCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList @("passphrase", $mockPassphrase) + $modulePath = "Modules\SharePointDsc\Modules\SharePointDsc.Farm\SPFarm.psm1" + Import-Module -Name (Join-Path -Path $Global:SPDscHelper.RepoRoot -ChildPath $modulePath -Resolve) + # Mocks for all contexts Mock Connect-SPConfigurationDatabase -MockWith {} Mock -CommandName Install-SPHelpCollection -MockWith {} - Mock Initialize-SPResourceSecurity -MockWith {} + Mock -CommandName Initialize-SPResourceSecurity -MockWith {} Mock -CommandName Install-SPService -MockWith {} Mock -CommandName Install-SPFeature -MockWith {} Mock -CommandName New-SPCentralAdministration -MockWith {} Mock -CommandName Install-SPApplicationContent -MockWith {} Mock -CommandName Start-Service -MockWith {} Mock -CommandName Start-Sleep -MockWith {} + Mock -CommandName Get-SPDSCConfigDBStatus -MockWith { + return @{ + Locked = $false + ValidPermissions = $true + DatabaseExists = $false + } + } -Verifiable # Test contexts Context -Name "no farm is configured locally and a supported version of SharePoint is installed" { @@ -43,6 +53,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Passphrase = $mockPassphraseCredential } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } + } + Mock -CommandName Get-SPFarm -MockWith { throw "Unable to detect local farm" } @@ -134,6 +151,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ServerRole = "ApplicationWithSearch" } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $null + } + } + Mock -CommandName Get-SPDSCInstalledProductVersion -MockWith { return @{ FileMajorPart = 16 @@ -178,6 +202,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Passphrase = $mockPassphraseCredential } + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $testParams.FarmConfigDatabaseName + } + } + Mock -CommandName Get-SPFarm -MockWith { return @{ DefaultServiceAccount = @{ @@ -206,6 +237,63 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + Context -Name "a farm exists locally, is the correct farm but SPFarm is not reachable" -Fixture { + $testParams = @{ + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "DatabaseServer\Instance" + FarmAccount = $mockFarmAccount + Passphrase = $mockPassphrase + AdminContentDatabaseName = "Admin_Content" + CentralAdministrationAuth = "Kerberos" + CentralAdministrationPort = 1234 + } + + Mock -CommandName Get-SPDSCRegistryKey -MockWith { + if ($Value -eq "dsn") + { + return $testParams.FarmConfigDatabaseName + } + } + + Mock -CommandName Get-SPFarm -MockWith { return $null } + + Mock -CommandName Get-SPDatabase -MockWith { + return @(@{ + Name = $testParams.FarmConfigDatabaseName + Type = "Configuration Database" + Server = @{ + Name = $testParams.DatabaseServer + } + }) + } + + Mock -CommandName Get-SPWebApplication -MockWith { + return @(@{ + IsAdministrationWebApplication = $true + ContentDatabases = @(@{ + Name = $testParams.AdminContentDatabaseName + }) + Url = "http://$($env:ComputerName):$($testParams.CentralAdministrationPort)" + }) + } + + Mock -CommandName Get-SPDSCConfigDBStatus -MockWith { + return @{ + Locked = $true + ValidPermissions = $false + DatabaseExists = $true + } + } + + It "Should throw when server already joined to farm but SPFarm not reachable" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw when the current user does not have sufficient permissions to SQL Server" { + { Set-TargetResource @testParams } | Should Throw + } + } + Context -Name "a farm exists locally and is not the correct farm" { $testParams = @{ FarmConfigDatabaseName = "SP_Config" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPMachineTranslationServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPMachineTranslationServiceApp.Tests.ps1 new file mode 100644 index 000000000..1b5135a4b --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPMachineTranslationServiceApp.Tests.ps1 @@ -0,0 +1,255 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPMachineTranslationServiceApp" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + #Initialize Tests + $getTypeFullName = "Microsoft.Office.TranslationServices.TranslationServiceApplication" + + # Mocks for all contexts + Mock -CommandName New-SPTranslationServiceApplication -MockWith { return @{} } + Mock -CommandName Get-SPServiceApplication -MockWith { } + Mock -CommandName Remove-SPServiceApplication -MockWith { } + + # Test contexts + Context -Name "When no service applications exist in the current farm" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + + It "Should return absent from the Get method" { + (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 create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPTranslationServiceApplication + } + } + + Context -Name "When service applications exist in the current farm but the specific Translation app does not" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.Office.UnKnownWebServiceApplication" + } + } -PassThru -Force + return $spServiceApp + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When a service application exists and is configured correctly" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Machine Translation Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force + + return $spServiceApp + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Machine Translation Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ + Name = $testParams.DatabaseServer + } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force + return $spServiceApp + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + Mock -CommandName Set-SPTranslationServiceApplication -MockWith { + + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the set service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Get-SPServiceApplication + Assert-MockCalled Set-SPTranslationServiceApplication + } + } + + Context -Name "When the service application exists but it shouldn't" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Machine Translation Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ + Name = $testParams.DatabaseServer + } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force + + return $spServiceApp + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the remove service application cmdlet in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Get-SPServiceApplication + Assert-MockCalled Remove-SPServiceApplication + } + } + + Context -Name "When the serivce application doesn't exist and it shouldn't" -Fixture { + $testParams = @{ + Name = "Translation Service" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SPDB" + DatabaseName = "Translation" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index cfd2f78b1..eb1f5530d 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -26,6 +26,53 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName New-SPMetadataServiceApplicationProxy -MockWith { return @{} } Mock -CommandName Set-SPMetadataServiceApplication -MockWith { } Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName Get-SPWebApplication -MockWith { + return @( + @{ + Url = "http://FakeCentralAdmin.Url" + IsAdministrationWebApplication = $true + } + ) + } + Mock -CommandName Get-SPTaxonomySession -MockWith { + return @{ + TermStores = @( + @{ + TermStoreAdministrators = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true + } + ) + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + ) + } + } + Mock -CommandName New-SPClaimsPrincipal -MockWith { + return @{ + Value = $Identity -replace "i:0#.w\|" + } + } -ParameterFilter { $IdentityType -eq "EncodedClaim" } + + Mock -CommandName New-SPClaimsPrincipal -MockWith { + $Global:SPDscClaimsPrincipalUser = $Identity + return ( + New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ToEncodedString { + return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" + } -PassThru + ) + } -ParameterFilter { $IdentityType -eq "WindowsSamAccountName" } # Test contexts Context -Name "When no service applications exist in the current farm" -Fixture { @@ -94,36 +141,100 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Ensure = "Present" } - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - return $spServiceApp } It "Should return present from the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + $results = Get-TargetResource @testParams + $results.Ensure | Should Be "Present" + $results.ContentTypeHubUrl | Should Not BeNullOrEmpty } It "Should return true when the Test method is called" { @@ -141,34 +252,96 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Ensure = "Present" } - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ + Name = $testParams.DatabaseServer + } + } } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } } } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - return $spServiceApp } Mock -CommandName Get-SPServiceApplicationPool -MockWith { @@ -177,6 +350,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } + It "Should return Wrong App Pool Name from the Get method" { + (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + } + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } @@ -201,18 +378,274 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Ensure = "Present" } + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.AookucationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ + Name = $testParams.DatabaseServer + } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + It "Should return wrong content type url from the Get method" { + (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Set-SPMetadataServiceApplication + } + } + + Context -Name "When the service application exists but it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ + Name = $testParams.DatabaseServer + } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp + } + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the remove service application cmdlet in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + } + } + + Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ TypeName = "Managed Metadata Service" DisplayName = $testParams.Name ApplicationPool = @{ - Name = $testParams.AookucationPool + Name = $testParams.ApplicationPool } Database = @{ Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer - } + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -231,28 +664,26 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $spServiceApp } - Mock -CommandName Get-SPServiceApplicationPool -MockWith { - return @{ - Name = $testParams.ApplicationPool - } - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty } - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams - - Assert-MockCalled set-SPMetadataServiceApplication + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $true } } - - Context -Name "When the service application exists but it shouldn't" -Fixture { + + Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1", + "CONTOSO\User2" + ) } Mock -CommandName Get-SPServiceApplication -MockWith { @@ -260,13 +691,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { TypeName = "Managed Metadata Service" DisplayName = $testParams.Name ApplicationPool = @{ - Name = "Wrong App Pool Name" + Name = $testParams.ApplicationPool } Database = @{ Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer - } + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -284,38 +713,109 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } -PassThru -Force return $spServiceApp } - - It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $false } - - It "Should call the remove service application cmdlet in the set method" { + + It "Should call the add method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false Set-TargetResource @testParams - Assert-MockCalled Remove-SPServiceApplication + + $Global:SPDscAddUserCalled | Should Be $true } } - - Context -Name "When the serivce application doesn't exist and it shouldn't" -Fixture { + + Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) } Mock -CommandName Get-SPServiceApplication -MockWith { - return $null + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + return $spServiceApp } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + + Mock -CommandName Get-SPTaxonomySession -MockWith { + $users = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true + } + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User2" + IsWindowsAuthenticationMode = $true + } + ) + return @{ + TermStores = @( + @{ + TermStoreAdministrators = $users + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + ) + } } - - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $true + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscDeleteUserCalled | Should Be $true } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 new file mode 100644 index 000000000..46ee739d3 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 @@ -0,0 +1,408 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSearchAuthoritativePage" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope +try +{ + Add-Type -TypeDefinition @" +namespace Microsoft.Office.Server.Search.Administration { + public enum SearchObjectLevel + { + SPWeb, + SPSite, + SPSiteSubscription, + Ssa + } + + + public class SearchObjectOwner { + public SearchObjectOwner(Microsoft.Office.Server.Search.Administration.SearchObjectLevel level) { } + } +} +"@ -ErrorAction SilentlyContinue +} +catch +{ + +} + # Mocks for all contexts + + Mock -CommandName Get-SPEnterpriseSearchQueryAuthority -MockWith { } + Mock -CommandName New-SPEnterpriseSearchQueryAuthority -MockWith { } + Mock -CommandName Set-SPEnterpriseSearchQueryAuthority -MockWith { } + Mock -CommandName Remove-SPEnterpriseSearchQueryAuthority -MockWith { } + + Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -MockWith { } + Mock -CommandName New-SPEnterpriseSearchQueryDemoted -MockWith { } + Mock -CommandName Remove-SPEnterpriseSearchQueryDemoted -MockWith { } + + # Test contexts + Context -Name "A SharePoint Search Service doesn't exists" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return $null + } + + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an exception in the set method" { + {Set-TargetResource @testParams} | Should Throw "Search Service App was not available." + + } + } + + Context -Name "A search query authoratative page does exist and should" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryAuthority -MockWith { + return @{ + Identity = $testParams.Path + Level = $testParams.Level + } + } + + Mock -CommandName Set-SPEnterpriseSearchQueryAuthority -MockWith { + return @{ + Identity = $testParams.Path + Level = $testParams.Level + } + } + + + 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 + } + + It "Should call Set functions from the Set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled Set-SPEnterpriseSearchQueryAuthority -Times 1 + } + + } + + Context -Name "A search query authoratative page does exist and shouldn't" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryAuthority -MockWith { + return @{ + Identity = $testParams.Path + Level = $testParams.Level + } + } + + Mock -CommandName Remove-SPEnterpriseSearchQueryAuthority -MockWith { + return $null + } + + + 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 call Set functions from the Set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled Remove-SPEnterpriseSearchQueryAuthority -Times 1 + } + } + + Context -Name "A search query authoratative page doesn't exist and shouldn't" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryAuthority -MockWith { + return $null + } + + Mock -CommandName Remove-SPEnterpriseSearchQueryAuthority -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 + } + + It "Should call Set functions from the Set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled Remove-SPEnterpriseSearchQueryAuthority -Times 1 + } + } + + Context -Name "A search query authoratative page doesn't exist but should" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Authoratative" + Level = 0.0 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryAuthority -MockWith { + return $null + } + + Mock -CommandName New-SPEnterpriseSearchQueryAuthority -MockWith { + return @{ + Identity = $testParams.Path + Level = $testParams.Level + } + } + + + 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 Get-SPEnterpriseSearchServiceApplication -Times 1 + + } + } + + Context -Name "A search query demoted page does exist and should" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Demoted" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -MockWith { + return @{ + Identity = $testParams.Path + } + } + + 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 + } + + It "Should create the content source in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled -CommandName Get-SPEnterpriseSearchServiceApplication -Times 1 + } + } + + Context -Name "A search query demoted page does exist and shouldn't" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Demoted" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -MockWith { + return @{ + Identity = $testParams.Path + } + } + + 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 Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled -CommandName Remove-SPEnterpriseSearchQueryDemoted -Times 1 + } + } + + Context -Name "A search query demoted page doesn't exist and shouldn't" { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Demoted" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -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 + } + It "Should remove the content source in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled -CommandName Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled -CommandName Remove-SPEnterpriseSearchQueryDemoted -Times 1 + } + } + + Context -Name "A search query demoted page doesn't exist but should" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Path = "http://site.sharepoint.com/pages/authoratative.aspx" + Action = "Demoted" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -MockWith { + return $null + } + + Mock -CommandName New-SPEnterpriseSearchQueryDemoted -MockWith { + return @{ + Url = $params.Path + } + } + + 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 a new query demoted element in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled -CommandName Get-SPEnterpriseSearchServiceApplication -Times 1 + Assert-MockCalled -CommandName New-SPEnterpriseSearchQueryDemoted -Times 1 + } + } + + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 new file mode 100644 index 000000000..ca2f8b816 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 @@ -0,0 +1,377 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSearchCrawlMapping" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + $getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" + + # Mocks for all contexts + Mock -CommandName Remove-SPEnterpriseSearchCrawlMapping -MockWith {} + Mock -CommandName New-SPEnterpriseSearchCrawlMapping -MockWith {} + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith {} + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith {} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @( + New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru + } ` + -PassThru -Force) + } + + # Test contexts + Context -Name "When enterprise search service doesn't exist in the current farm" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (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 throw Exception -- The Search Service Application does not exist" { + { Set-TargetResource @testParams } | Should throw "The Search Service Application does not exist" + } + + } + + Context -Name "When no crawl mappings exists" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return $null + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + + } + + Context -Name "When crawl mappings exists but specific mapping does not" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Url = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Url = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + } + ) + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When a crawl mapping exists, and is configured correctly" -Fixture { + + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Source = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Source = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + }, + @{ + Source = $testParams.Url + Target = $testParams.Target + } + ) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should call the Get Remove New SPEnterpriseSearchCrawlMapping update the crawl mapping" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchServiceApplication + Assert-MockCalled Get-SPEnterpriseSearchCrawlMapping + Assert-MockCalled Remove-SPEnterpriseSearchCrawlMapping + Assert-MockCalled New-SPEnterpriseSearchCrawlMapping + } + } + + Context -Name "When a crawl mapping exists, but isn't configured correctly" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Source = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Source = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + }, + @{ + Source = $testParams.Url + Target = "http://other.sharepoint.com" + } + ) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the Get Remove New -SPEnterpriseSearchCrawlMapping update the crawl mapping" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchCrawlMapping + Assert-MockCalled Remove-SPEnterpriseSearchCrawlMapping + Assert-MockCalled New-SPEnterpriseSearchCrawlMapping + } + } + + Context -Name "When a crawl mapping doesn't exists, but it should" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Source = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Source = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + } + ) + } + + It "Should return absent from the get method" { + (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 call the Get Remove New -SPEnterpriseSearchCrawlMapping update the crawl mapping" { + Set-TargetResource @testParams + Assert-MockCalled New-SPEnterpriseSearchCrawlMapping + } + } + + Context -Name "When a crawl mapping exists, but isn't configured correctly" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Source = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Source = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + }, + @{ + Source = $testParams.Url + Target = "http://other.sharepoint.com" + } + ) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the Get - Remove - New EnterpriseSearchCrawlMapping update the crawl mapping" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchCrawlMapping + Assert-MockCalled Remove-SPEnterpriseSearchCrawlMapping + Assert-MockCalled New-SPEnterpriseSearchCrawlMapping + } + } + + Context -Name "When a crawl mapping does exists, but it shouldn't" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Url = "http://crawl.sharepoint.com" + Target = "http://site.sharepoint.com" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + Name = "Search Service Application" + } + } + + + Mock -CommandName Get-SPEnterpriseSearchCrawlMapping -MockWith { + return @( + @{ + Source = "http://other.sharepoint.com" + Target = "http://site.sharepoint.com" + }, + @{ + Source = "http://site.sharepoint.com" + Target = "http://site2.sharepoint.com" + }, + @{ + Source = $testParams.Url + Target = $testParams.Target + } + ) + } + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the Get Remove New -SPEnterpriseSearchCrawlMapping update the crawl mapping" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPEnterpriseSearchCrawlMapping + Assert-MockCalled Remove-SPEnterpriseSearchCrawlMapping + } + } + } +} + + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 new file mode 100644 index 000000000..f59767f08 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 @@ -0,0 +1,296 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSearchCrawlerImpactRule" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + $getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" + + # Mocks for all contexts + Mock -CommandName Remove-SPEnterpriseSearchSiteHitRule -MockWith { } + Mock -CommandName New-SPEnterpriseSearchSiteHitRule -MockWith { } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @( + New-Object -TypeName "Object" | + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru + } ` + -PassThru -Force) + } + + # Test contexts + Context -Name "When crawler impact requestlimit rule should exist and doesn't exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + RequestLimit = 8 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (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 create a new search site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPEnterpriseSearchSiteHitRule + } + } + + Context -Name "When crawler impact requestlimit rule should exist and does exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + RequestLimit = 8 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return @{ + Name = $testParams.Name + HitRate = $testParams.RequestLimit + Behavior = "0" + } + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should update a new search Site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule + Assert-MockCalled New-SPEnterpriseSearchSiteHitRule + } + } + + Context -Name "When crawler impact requestlimit rule shouldn't exist and doesn't exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return @{ + Name = $testParams.Name + HitRate = $testParams.RequestLimit + } + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should remove the search Site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule + + } + } + + Context -Name "When crawler impact requestlimit rule shouldn't exist and does exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should remove the search Site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule + + } + } + + Context -Name "When the Search Service does not exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return $null + } + + + It "Should return absent from the Get method" { + (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 throw a search service not found exception" { + { Set-TargetResource @testParams } | Should Throw "The Search Service Application does not exist." + + + } + + } + + Context -Name "When the both RequestLimit and WaitTime are specified" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + RequestLimit = 8 + WaitTime = 60 + Ensure = "Present" + } + + It "Should throw an exception when called with both RequestLimit and WaitTime" { + { Get-TargetResource @testParams } | Should Throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + { Test-TargetResource @testParams } | Should Throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + { Set-TargetResource @testParams } | Should Throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + + } + } + + Context -Name "When crawler impact WaitTime rule should exist and doesn't exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + WaitTime = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (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 create a new search site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPEnterpriseSearchSiteHitRule + } + } + + Context -Name "When crawler impact WaitTime rule should exist and does exist" -Fixture { + $testParams = @{ + ServiceAppName = "Search Service Application" + Name = "http://site.sharepoint.com" + WaitTime = 300 + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @{ + DisplayName = $testParams.ServiceAppName + } + } + + Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { + return @{ + Name = $testParams.Name + HitRate = $testParams.WaitTime + Behavior = "1" + } + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should update a new search Site hit rule in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule + Assert-MockCalled New-SPEnterpriseSearchSiteHitRule + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 index 572b9518c..0dbf0da3e 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 @@ -17,17 +17,23 @@ $Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointC Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope - +try { # Initialize tests - Add-Type -TypeDefinition @" - namespace Microsoft.Office.Server.Search.Administration - { - public class SearchObjectLevel { - public static string Ssa { get { return ""; } } - } - } -"@ - + Add-Type -TypeDefinition @" +namespace Microsoft.Office.Server.Search.Administration { + public enum SearchObjectLevel + { + SPWeb, + SPSite, + SPSiteSubscription, + Ssa + } +} +"@ -ErrorAction SilentlyContinue +} +catch { + +} # Mocks for all contexts Mock -CommandName Get-SPEnterpriseSearchServiceApplication { return @{ diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 index 8e25fa815..b5c05c3c3 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 @@ -355,6 +355,79 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { Set-TargetResource @testParams } | Should Throw } } + + Context -Name "A search topology exists that has a server with a new ID in it" -Fixture { + $newServerId = New-Guid + $adminComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.AdminComponent + $adminComponent.ServerName = $null + $adminComponent.ServerId = $newServerId + $adminComponent.ComponentId = [Guid]::NewGuid() + + $crawlComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.CrawlComponent + $crawlComponent.ServerName = $null + $crawlComponent.ServerId = $newServerId + $crawlComponent.ComponentId = [Guid]::NewGuid() + + $contentProcessingComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.ContentProcessingComponent + $contentProcessingComponent.ServerName = $null + $contentProcessingComponent.ServerId = $newServerId + $contentProcessingComponent.ComponentId = [Guid]::NewGuid() + + $analyticsProcessingComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.AnalyticsProcessingComponent + $analyticsProcessingComponent.ServerName = $null + $analyticsProcessingComponent.ServerId = $newServerId + $analyticsProcessingComponent.ComponentId = [Guid]::NewGuid() + + $queryProcessingComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.QueryProcessingComponent + $queryProcessingComponent.ServerName = $null + $queryProcessingComponent.ServerId = $newServerId + $queryProcessingComponent.ComponentId = [Guid]::NewGuid() + + $indexComponent = New-Object Microsoft.Office.Server.Search.Administration.Topology.IndexComponent + $indexComponent.ServerName = $null + $indexComponent.ServerId = $newServerId + $indexComponent.IndexPartitionOrdinal = 0 + + $testParams = @{ + ServiceAppName = "Search Service Application" + Admin = @($env:COMPUTERNAME) + Crawler = @($env:COMPUTERNAME) + ContentProcessing = @($env:COMPUTERNAME) + AnalyticsProcessing = @($env:COMPUTERNAME) + QueryProcessing = @($env:COMPUTERNAME) + IndexPartition = @($env:COMPUTERNAME) + FirstPartitionDirectory = "I:\SearchIndexes\0" + } + + Mock -CommandName Get-SPEnterpriseSearchComponent -MockWith { + return @( + $adminComponent, + $crawlComponent, + $contentProcessingComponent, + $analyticsProcessingComponent, + $queryProcessingComponent, + $indexComponent) + } + + Mock -CommandName Get-SPEnterpriseSearchServiceInstance { + return @{ + Server = @{ + Address = $env:COMPUTERNAME + } + Status = "Online" + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should update the topology in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchComponent -Times 5 + Assert-MockCalled Set-SPEnterpriseSearchTopology + } + } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 index 1ccc42515..b172ce1d9 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 @@ -110,16 +110,43 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer - } - } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Database" + Server = @{ + Name = "DBServer" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru } -PassThru -Force + return $spServiceApp } @@ -145,20 +172,48 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { TypeName = "Secure Store Service Application" DisplayName = $testParams.Name ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer - } + Name = "Wrong App Pool Name" } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Database" + Server = @{ + Name = "DBServer" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru } -PassThru -Force + return $spServiceApp } + Mock -CommandName Get-SPServiceApplicationPool -MockWith { return @{ Name = $testParams.ApplicationPool @@ -252,18 +307,45 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { TypeName = "Secure Store Service Application" DisplayName = $testParams.Name ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ - Name = $testParams.DatabaseServer - } + Name = "Wrong App Pool Name" } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Database" + Server = @{ + Name = "DBServer" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru } -PassThru -Force + return $spServiceApp } @@ -280,7 +362,153 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Remove-SPServiceApplication } } - + + Context -Name "When the database name does not match the actual name" -Fixture { + $testParams = @{ + Name = "Secure Store Service Application" + ApplicationPool = "Service App Pool" + AuditingEnabled = $false + DatabaseName = "SecureStoreDB" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Secure Store Service Application" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "Wrong Database" + Server = @{ + Name = "DBServer" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp + } + + 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 throw exception in the set method" { + { Set-TargetResource @testParams } | Should Throw ("Specified database name does not match " + ` + "the actual database name. This resource " + ` + "cannot rename the database.") + } + } + + Context -Name "When the database server does not match the actual server" -Fixture { + $testParams = @{ + Name = "Secure Store Service Application" + ApplicationPool = "Service App Pool" + AuditingEnabled = $false + DatabaseName = "SecureStoreDB" + DatabaseServer = "SQL_Instance" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Secure Store Service Application" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "Database" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + Name = "SecureStoreDB" + Server = @{ + Name = "Wrong DBServer" + } + FailoverServer = @{ + Name = "DBServer_Failover" + } + }) + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + + return $spServiceApp + } + + 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 throw exception in the set method" { + { Set-TargetResource @testParams } | Should Throw ("Specified database server does " + ` + "not match the actual database server. " + ` + "This resource cannot move the database " + ` + "to a different SQL instance.") + } + } + Context -Name "When the service app doesn't exist and shouldn't" -Fixture { $testParams = @{ Name = "Secure Store Service Application" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 index c9f09e1e9..e0ea469ca 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 @@ -22,13 +22,61 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-ChildItem -MockWith { return @( @{ - Thumbprint = "Mock Thumbrpint" + Thumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" } ) + } -ParameterFilter { $Path -eq 'Cert:\LocalMachine\My' } + + Mock -CommandName New-SPTrustedIdentityTokenIssuer -MockWith { + $sptrust = [pscustomobject]@{ + Name = $testParams.Name + ClaimProviderName = "" + ProviderSignOutUri = "" + } + $sptrust | Add-Member -Name Update -MemberType ScriptMethod -Value { } + return $sptrust + } + + Mock -CommandName New-SPClaimTypeMapping -MockWith { + return [pscustomobject]@{ + MappedClaimType = $testParams.IdentifierClaim + } + } + + Mock -CommandName Get-SPClaimProvider -MockWith { + return [pscustomobject]@(@{ + DisplayName = $testParams.ClaimProviderName + }) } + try + { + [Microsoft.SharePoint.Administration.SPUrlZone] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public enum SPUrlZone { Default, Intranet, Internet, Custom, Extranet }; +} +"@ + } + + try + { + [Microsoft.SharePoint.Administration.SPTrustedAuthenticationProvider] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public class SPTrustedAuthenticationProvider {} +} +"@ + } + # Test contexts - Context -Name "The SPTrustedIdentityTokenIssuer does not exist, but it should be present" -Fixture { + Context -Name "The SPTrustedLoginProvider does not exist but should, using a signing certificate in the certificate store" -Fixture { $testParams = @{ Name = "Contoso" Description = "Contoso" @@ -46,28 +94,59 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } -ClientOnly) ) - SigningCertificateThumbPrint = "Mock Thumbrpint" + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" } - Mock -CommandName New-SPTrustedIdentityTokenIssuer -MockWith { - $sptrust = [pscustomobject]@{ - Name = $testParams.Name - ClaimProviderName = "" - ProviderSignOutUri = "" - } - $sptrust | Add-Member -Name Update -MemberType ScriptMethod -Value { } - return $sptrust + It "Should return absent from the get method" { + $getResults = Get-TargetResource @testParams + $getResults.Ensure | Should Be "Absent" } - Mock -CommandName New-SPClaimTypeMapping -MockWith { - return [pscustomobject]@{ - MappedClaimType = $testParams.IdentifierClaim - } + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false } + It "Should create the SPTrustedIdentityTokenIssuer" { + Set-TargetResource @testParams + Assert-MockCalled New-SPTrustedIdentityTokenIssuer + } + } + + Context -Name "The SPTrustedLoginProvider does not exist but should, using a signing certificate in the file path" -Fixture { + $testParams = @{ + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } -ClientOnly) + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } -ClientOnly) + ) + SigningCertificateFilePath = "F:\Data\DSC\FakeSigning.cer" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + } + + Mock -CommandName New-Object -MockWith { + return @( + @{ + Thumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" + } + ) + } -ParameterFilter { $TypeName -eq 'System.Security.Cryptography.X509Certificates.X509Certificate2' } + It "Should return absent from the get method" { $getResults = Get-TargetResource @testParams $getResults.Ensure | Should Be "Absent" @@ -82,8 +161,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled New-SPTrustedIdentityTokenIssuer } } - - Context -Name "The SPTrustedIdentityTokenIssuer does not exist, but it should be present and claims provider specified exists on the farm" -Fixture { + + Context -Name "The SPTrustedLoginProvider is desired, but both parameters SigningCertificateThumbprint and SigningCertificateFilePath are set while exactly 1 should" -Fixture { $testParams = @{ Name = "Contoso" Description = "Contoso" @@ -101,50 +180,154 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } -ClientOnly) ) - SigningCertificateThumbPrint = "Mock Thumbrpint" + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" + SigningCertificateFilePath = "F:\Data\DSC\FakeSigning.cer" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" + } + + It "should fail validation of signing certificate parameters in the set method" { + { Set-TargetResource @testParams } | Should Throw "Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time." } + } - Mock -CommandName Get-SPClaimProvider -MockWith { - return [pscustomobject]@(@{ - DisplayName = $testParams.ClaimProviderName - }) + Context -Name "The SPTrustedLoginProvider is desired, but none of parameters SigningCertificateThumbprint and SigningCertificateFilePath is set while exactly 1 should" -Fixture { + $testParams = @{ + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } -ClientOnly) + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } -ClientOnly) + ) + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + } + + It "should fail validation of signing certificate parameters in the set method" { + { Set-TargetResource @testParams } | Should Throw "At least one of the following parameters must be specified: SigningCertificateThumbprint, SigningCertificateFilePath." } - - Mock -CommandName New-SPTrustedIdentityTokenIssuer -MockWith { - $sptrust = [pscustomobject]@{ - Name = $testParams.Name - ClaimProviderName = "" - ProviderSignOutUri = "" - } - $sptrust| Add-Member -Name Update -MemberType ScriptMethod -Value { } - return $sptrust + } + + Context -Name "The SPTrustedLoginProvider is desired, but the thumbprint of the signing certificate in parameter SigningCertificateThumbprint is invalid" -Fixture { + $testParams = @{ + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } -ClientOnly) + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } -ClientOnly) + ) + SigningCertificateThumbprint = "XX123ABCFACEXX" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" } - + + It "should fail validation of parameter SigningCertificateThumbprint in the set method" { + { Set-TargetResource @testParams } | Should Throw "Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'." + } + } + + Context -Name "The SPTrustedLoginProvider is desired, but the private key of the signing certificate is present in certificate store while it should not" -Fixture { + $testParams = @{ + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } -ClientOnly) + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } -ClientOnly) + ) + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + } + + Mock -CommandName Get-ChildItem -MockWith { + return @( + @{ + Thumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" + HasPrivateKey = $true + } + ) + } -ParameterFilter { $Path -eq 'Cert:\LocalMachine\My' } + + It "should fail validation of certificate in the set method" { + { Set-TargetResource @testParams } | Should Throw "SharePoint requires that the private key of the signing certificate is not installed in the certificate store." + } + } + + Context -Name "The SPTrustedLoginProvider does not exist but should, with a claims provider that exists on the farm" -Fixture { + $testParams = @{ + Name = "Contoso" + Description = "Contoso" + Realm = "https://sharepoint.contoso.com" + SignInUrl = "https://adfs.contoso.com/adfs/ls/" + IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + ClaimsMappings = @( + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Email" + IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" + } -ClientOnly) + (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ + Name = "Role" + IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" + LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" + } -ClientOnly) + ) + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" + ClaimProviderName = "LDAPCP" + ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" + Ensure = "Present" + } + Mock -CommandName Get-SPTrustedIdentityTokenIssuer -MockWith { $sptrust = [pscustomobject]@{ Name = $testParams.Name ClaimProviderName = $testParams.ClaimProviderName - ProviderSignOutUri = "" } $sptrust| Add-Member -Name Update -MemberType ScriptMethod -Value { } return $sptrust } - Mock -CommandName New-SPClaimTypeMapping -MockWith { - return [pscustomobject]@{ - MappedClaimType = $testParams.IdentifierClaim - } - } - - It "Should create the SPTrustedIdentityTokenIssuer and sets claims provider" { + It "Should create the SPTrustedLoginProvider with claims provider set" { Set-TargetResource @testParams + $getResults = Get-TargetResource @testParams + $getResults.ClaimProviderName | Should Be $testParams.ClaimProviderName } } - Context -Name "The SPTrustedIdentityTokenIssuer already exists, and it should be present" -Fixture { + Context -Name "The SPTrustedLoginProvider already exists and should not be changed" -Fixture { $testParams = @{ Name = "Contoso" Description = "Contoso" @@ -162,7 +345,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } -ClientOnly) ) - SigningCertificateThumbPrint = "Mock Thumbrpint" + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" @@ -171,8 +354,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPTrustedIdentityTokenIssuer -MockWith { $sptrust = [pscustomobject]@{ Name = $testParams.Name - ClaimProviderName = "" - ProviderSignOutUri = "" + ClaimProviderName = $testParams.ClaimProviderName } return $sptrust } @@ -187,7 +369,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "The SPTrustedIdentityTokenIssuer exists, but it should be absent" -Fixture { + Context -Name "The SPTrustedLoginProvider already exists but should be removed" -Fixture { $testParams = @{ Name = "Contoso" Description = "Contoso" @@ -205,7 +387,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } -ClientOnly) ) - SigningCertificateThumbPrint = "Mock Thumbrpint" + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Absent" @@ -219,6 +401,30 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $sptrust } + Mock -CommandName Get-SPWebApplication -MockWith { + $spWebApp = [pscustomobject]@{ + Url = "http://webAppUrl" + } + $spWebApp | Add-Member -Name Update -MemberType ScriptMethod -Value { } + $spWebApp | Add-Member -Name GetIisSettingsWithFallback -MemberType ScriptMethod -Value { } + return $spWebApp + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + $spAP = [pscustomobject]@{ + LoginProviderName = "" + } + $spAP | Add-Member -Name Update -MemberType ScriptMethod -Value { } + $spAP | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.SharePoint.Administration.SPTrustedAuthenticationProvider" + } + } -PassThru -Force + return $spAP + } + Mock -CommandName Remove-SPTrustedIdentityTokenIssuer -MockWith { } It "Should return absent from the get method" { @@ -235,13 +441,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "The IdentifierClaim does not match one of the claim types in ClaimsMappings" -Fixture { + Context -Name "The SPTrustedLoginProvider is desired, but the IdentifierClaim parameter does not match a claim type in ClaimsMappings" -Fixture { $testParams = @{ Name = "Contoso" Description = "Contoso" Realm = "https://sharepoint.contoso.com" SignInUrl = "https://adfs.contoso.com/adfs/ls/" - IdentifierClaim = "UnknownClaimType" + IdentifierClaim = "IdentityClaimTypeNotSpecifiedInClaimsMappings" ClaimsMappings = @( (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ Name = "Email" @@ -253,7 +459,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" } -ClientOnly) ) - SigningCertificateThumbPrint = "Mock Thumbrpint" + SigningCertificateThumbprint = "123ABCFACE123ABCFACE123ABCFACE123ABCFACE" ClaimProviderName = "LDAPCP" ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" Ensure = "Present" @@ -265,39 +471,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - It "validation of IdentifierClaim fails in the set method" { + It "should fail validation of IdentifierClaim in the set method" { { Set-TargetResource @testParams } | Should Throw "IdentifierClaim does not match any claim type specified in ClaimsMappings." } } - - Context -Name "The certificate thumbprint does not match a certificate in certificate store LocalMachine\My" -Fixture { - $testParams = @{ - Name = "Contoso" - Description = "Contoso" - Realm = "https://sharepoint.contoso.com" - SignInUrl = "https://adfs.contoso.com/adfs/ls/" - IdentifierClaim = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" - ClaimsMappings = @( - (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ - Name = "Email" - IncomingClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" - } -ClientOnly) - (New-CimInstance -ClassName MSFT_SPClaimTypeMapping -Property @{ - Name = "Role" - IncomingClaimType = "http://schemas.xmlsoap.org/ExternalSTSGroupType" - LocalClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" - } -ClientOnly) - ) - SigningCertificateThumbPrint = "UnknownSigningCertificateThumbPrint" - ClaimProviderName = "LDAPCP" - ProviderSignOutUri = "https://adfs.contoso.com/adfs/ls/" - Ensure = "Present" - } - - It "Should fail validation of SigningCertificateThumbPrint in the set method" { - { Set-TargetResource @testParams } | Should Throw "The certificate thumbprint does not match a certificate in certificate store LocalMachine\My." - } - } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 new file mode 100644 index 000000000..d32279f5a --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 @@ -0,0 +1,276 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPTrustedRootAuthority" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Mock -CommandName Remove-SPTrustedRootAuthority -MockWith { } + Mock -CommandName Set-SPTrustedRootAuthority -MockWith { } + Mock -CommandName New-SPTrustedRootAuthority -MockWith { } + + Context -Name "When TrustedRootAuthority should exist and does exist in the farm." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + } + + Mock -CommandName Get-Item -MockWith { + return @{ + Subject = "CN=CertName" + Thumbprint = $testParams.CertificateThumbprint + } + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return @{ + Name = $testParams.Name + Certificate = @{ + Thumbprint = $testParams.CertificateThumbprint + } + } + } + + It "Should return Present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should Update the SP Trusted Root Authority in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPTrustedRootAuthority -Times 1 + Assert-MockCalled Set-SPTrustedRootAuthority -Times 1 + } + } + + Context -Name "When TrustedRootAuthority should exist and does exist in the farm, but has incorrect certificate." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return @{ + Name = $testParams.Name + Certificate = @{ + Thumbprint = "770515261D1AB169057E246E0EE6431D557C3AFC" + } + } + } + + Mock -CommandName Get-Item -MockWith { + return @{ + Subject = "CN=CertName" + Thumbprint = $testParams.CertificateThumbprint + } + } + + It "Should return Present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-SPTrustedRootAuthority -Times 1 + Assert-MockCalled Set-SPTrustedRootAuthority -Times 1 + } + } + + Context -Name "When TrustedRootAuthority should exist and does exist in the farm, but has incorrect certificate, but specified certificate doesn't exist;" -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return @{ + Name = $testParams.Name + Certificate = @{ + Thumbprint = "770515261D1AB169057E246E0EE6431D557C3AFC" + } + } + } + + Mock -CommandName Get-Item -MockWith { + return $null + } + + It "Should return Present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should thorw Certificate not found error in the set method" { + { Set-TargetResource @testParams } | Should Throw "Certificate not found in the local Certificate Store" + } + } + + Context -Name "When TrustedRootAuthority should exist and doesn't exist in the farm, but has an invalid certificate." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return $null + } + + Mock -CommandName Get-Item -MockWith { + return $null + } + + It "Should return Absent from the Get method" { + (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 throw a Certificate not found error" { + { Set-TargetResource @testParams } | Should Throw "Certificate not found in the local Certificate Store" + + } + } + + + Context -Name "When TrustedRootAuthority should exist and doesn't exist in the farm." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Present" + } + + Mock -CommandName Get-Item -MockWith { + return @{ + Subject = "CN=CertIdentifier" + Thumbprint = $testParams.CertificateThumbprint + } + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return $null + } + + It "Should return Absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Get-Item -Times 1 + Assert-MockCalled New-SPTrustedRootAuthority -Times 1 + } + + } + + Context -Name "When TrustedRootAuthority shouldn't exist and does exist in the farm." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Absent" + } + + Mock -CommandName Get-Item -MockWith { + return @{ + Subject = "CN=CertIdentifier" + Thumbprint = $testParams.CertificateThumbprint + } + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return @{ + Name = $testParams.Name + Certificate = @{ + Thumbprint = $testParams.CertificateThumbprint + } + } + } + + It "Should return Present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + It "Should remove the Trusted Root Authority" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPTrustedRootAuthority -Times 1 + } + + } + + Context -Name "When TrustedRootAuthority shouldn't exist and doesn't exist in the farm." -Fixture { + + $testParams = @{ + Name = "CertIdentifier" + CertificateThumbprint = "770515261D1AB169057E246E0EE6431D557C3AFB" + Ensure = "Absent" + } + + Mock -CommandName Get-Item -MockWith { + return @{ + Subject = "CN=CertIdentifier" + Thumbprint = $testParams.CertificateThumbprint + } + } + + Mock -CommandName Get-SPTrustedRootAuthority -MockWith { + return $null + } + + It "Should return Absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + It "Should remove the Trusted Root Authority" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPTrustedRootAuthority -Times 1 + } + + } + + } + +} \ No newline at end of file diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 new file mode 100644 index 000000000..8af8947ad --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 @@ -0,0 +1,881 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $false)] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPWebApplicationExtension" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + + try + { + [Microsoft.SharePoint.Administration.SPUrlZone] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public enum SPUrlZone { Default, Intranet, Internet, Custom, Extranet }; +} +"@ + } + + # Mocks for all contexts + Mock -CommandName New-SPAuthenticationProvider -MockWith { } + Mock -CommandName New-SPWebApplicationExtension -MockWith { } + Mock -CommandName Remove-SPWebApplication -MockWith { } + Mock -CommandName Get-SPTrustedIdentityTokenIssuer -MockWith { } + Mock -CommandName Set-SPWebApplication -MockWith { } + + + + # Test contexts + Context -Name "The parent web application does not exist" -Fixture { + $testParams = @{ + WebAppUrl = "http://nosuchwebapplication.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "NTLM" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { return $null } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "retrieving non-existent web application fails in the set method" { + { Set-TargetResource @testParams } | Should Throw "Web Application with URL $($testParams.WebAppUrl) does not exist" + } + } + + Context -Name "The web application extension that uses NTLM authentication doesn't exist but should" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "NTLM" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the new cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled New-SPWebApplicationExtension + Assert-MockCalled New-SPAuthenticationProvider -ParameterFilter { $DisableKerberos -eq $true } + } + + $testParams.Add("AllowAnonymous", $true) + It "Should call the new cmdlet from the set where anonymous authentication is requested" { + Set-TargetResource @testParams + + Assert-MockCalled New-SPWebApplicationExtension + Assert-MockCalled New-SPAuthenticationProvider -ParameterFilter { $DisableKerberos -eq $true } + } + } + + Context -Name "The web application extension that uses Kerberos doesn't exist but should" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Kerberos" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the new cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled New-SPWebApplicationExtension + Assert-MockCalled New-SPAuthenticationProvider -ParameterFilter { $DisableKerberos -eq $false } + } + } + + Context -Name "The web application extension that uses Claims doesn't exist but should" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Claims" + AuthenticationProvider = "MyClaimsProvider" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the new cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled New-SPWebApplicationExtension + Assert-MockCalled Get-SPTrustedIdentityTokenIssuer + } + } + + Context -Name "The web application extension that uses Claims is desired, but no authentication provider is given" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Claims" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an error from the set method" { + {Set-TargetResource @testParams }| Should Throw "When configuring SPWebApplication to use Claims the AuthenticationProvider value must be specified." + } + } + + Context -Name "The web application extension that uses Claims is desired, but the authentication provider is invalid" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Claims" + AuthenticationProvider = "NoSuchProvider" + Ensure = "Present" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + Mock -CommandName Get-SPTrustedIdentityTokenIssuer -MockWith { + throw "Error" + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an error from the set method" { + {Set-TargetResource @testParams }| Should Throw "Cannot find Authentication Provider $($testParams.AuthenticationProvider)" + } + } + + Context -Name "The web appliation extension does exist and should that uses NTLM without AllowAnonymous" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "NTLM" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous False from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $false + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web appliation extension does exist and should that uses NTLM without AllowAnonymous and HTTPS" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "https://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + UseSSL = $true + Zone = "Intranet" + AuthenticationMethod = "NTLM" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 443 + } + ServerBindings = @{} + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous False from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $false + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web appliation extension does exist and should that uses NTLM and AllowAnonymous" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "NTLM" + AllowAnonymous = $true + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $true + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous True from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $true + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web appliation extension does exist and should that uses Kerberos without AllowAnonymous" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Kerberos" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $false + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous False from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $false + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web appliation extension does exist and should that uses Claims Authentication" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Claims" + AuthenticationProvider = "MyClaimsProvider" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "MyClaimsProvider" + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return Claims as local auth mode from the get method" { + (Get-TargetResource @testParams).AuthenticationMethod | Should Be 'Claims' + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The web appliation extension does exist and should that uses Kerberos and AllowAnonymous" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Kerberos" + AllowAnonymous = $true + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $false + AllowAnonymous = $true + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous True from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $true + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + + Context -Name "The web appliation extension does exist and should with mismatched Windows Authentication" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Kerberos" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AuthenticationMethod NTLM from the get method" { + (Get-TargetResource @testParams).AuthenticationMethod | Should Be "NTLM" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should update the web application extension settings in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Set-SPWebApplication + } + } + + Context -Name "The web appliation extension does exist and should with mismatched Authentication (Windows / Claims)" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "Claims" + AuthenticationProvider = "MyClaimsProvider" + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AuthenticationMethod NTLM from the get method" { + (Get-TargetResource @testParams).AuthenticationMethod | Should Be "NTLM" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should update the web application extension authentication settings in the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Set-SPWebApplication + } + } + + Context -Name "The web appliation extension does exist and should with mismatched AllowAnonymous" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + HostHeader = "intranet.sharepoint.com" + Zone = "Intranet" + AuthenticationMethod = "NTLM" + AllowAnonymous = $true + Ensure = "Present" + } + + Mock -CommandName Get-SPAuthenticationProvider -MockWith { + return @{ + DisplayName = "Windows Authentication" + DisableKerberos = $true + AllowAnonymous = $false + } + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return ( + @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } | add-member ScriptMethod Update { $Global:WebAppUpdateCalled = $true} -PassThru + ) + } + + Mock -CommandName Get-SPAlternateUrl -MockWith { + return @{ + PublicURL = $testParams.Url + } + } + + + It "Should return present from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return AllowAnonymous False from the get method" { + (Get-TargetResource @testParams).AllowAnonymous | Should Be $false + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should update the web application extension settings in the set method" { + $Global:WebAppUpdateCalled = $false + Set-TargetResource @testParams + $Global:WebAppUpdateCalled | Should Be $true + } + } + + Context -Name "The web application extension exists but shouldn't" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + Ensure = "Absent" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $IISSettings = @( + @{} + @{ + SecureBindings = @{} + ServerBindings = @{ + HostHeader = "intranet.sharepoint.com" + Port = 80 + } + }) + + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = $IISSettings + } + } + + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should remove the web application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPWebApplication + } + } + + Context -Name "A web application extension doesn't exist and shouldn't" -Fixture { + $testParams = @{ + WebAppUrl = "http://company.sharepoint.com" + Name = "Intranet Zone" + Url = "http://intranet.sharepoint.com" + Zone = "Intranet" + Ensure = "Absent" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + + return @{ + DisplayName = "Company SharePoint" + URL = "http://company.sharepoint.com" + IISSettings = @() + } + } + + + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/Stubs/SharePoint/15.0.4805.1000/Microsoft.SharePoint.PowerShell.psm1 b/Tests/Unit/Stubs/SharePoint/15.0.4805.1000/Microsoft.SharePoint.PowerShell.psm1 index 2790cf2e8..bab3be4e5 100644 --- a/Tests/Unit/Stubs/SharePoint/15.0.4805.1000/Microsoft.SharePoint.PowerShell.psm1 +++ b/Tests/Unit/Stubs/SharePoint/15.0.4805.1000/Microsoft.SharePoint.PowerShell.psm1 @@ -10582,7 +10582,7 @@ param( [Parameter(ParameterSetName='ManualUpdateCertificateParameterSet', Mandatory=$true)] [ValidateNotNull()] - [System.Security.Cryptography.X509Certificates.X509Certificate2] + [object] ${Certificate}, [Parameter(ParameterSetName='MetadataEndPointParameterSet', Mandatory=$true)] @@ -18711,7 +18711,7 @@ param( [Parameter(ParameterSetName='ManualUpdateCertificateParameterSet')] [ValidateNotNull()] - [System.Security.Cryptography.X509Certificates.X509Certificate2] + [object] ${Certificate}, [Parameter(ParameterSetName='MetadataEndPointParameterSet')] @@ -19848,21 +19848,6 @@ param( } -function Test-SPInfoPathFormTemplate { - [CmdletBinding()] -param( - [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] - [string] - ${Path}, - - [Parameter(ValueFromPipeline=$true)] - [object] - ${AssignmentCollection}) - - - } - - function Test-SPO365LinkSettings { [CmdletBinding()] param( diff --git a/Tests/Unit/Stubs/SharePoint/16.0.4456.1000/Microsoft.SharePoint.PowerShell.psm1 b/Tests/Unit/Stubs/SharePoint/16.0.4456.1000/Microsoft.SharePoint.PowerShell.psm1 index 136172d31..62abc9c8d 100644 --- a/Tests/Unit/Stubs/SharePoint/16.0.4456.1000/Microsoft.SharePoint.PowerShell.psm1 +++ b/Tests/Unit/Stubs/SharePoint/16.0.4456.1000/Microsoft.SharePoint.PowerShell.psm1 @@ -11094,7 +11094,7 @@ param( [Parameter(ParameterSetName='ManualUpdateCertificateParameterSet', Mandatory=$true)] [ValidateNotNull()] - [System.Security.Cryptography.X509Certificates.X509Certificate2] + [object] ${Certificate}, [Parameter(ParameterSetName='MetadataEndPointParameterSet', Mandatory=$true)] @@ -19437,7 +19437,7 @@ param( [Parameter(ParameterSetName='ManualUpdateCertificateParameterSet')] [ValidateNotNull()] - [System.Security.Cryptography.X509Certificates.X509Certificate2] + [object] ${Certificate}, [Parameter(ParameterSetName='MetadataEndPointParameterSet')] @@ -20678,7 +20678,6 @@ param( } - function Test-SPInfoPathFormTemplate { [CmdletBinding()] param( diff --git a/appveyor.yml b/appveyor.yml index c6e1c8748..57558be0b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.6.0.{build} +version: 1.7.0.{build} image: WMF 5 install: