diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e3dc78320..0e90fb22a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -8,6 +8,8 @@ _Please provide the following information regarding your issue (place N/A if cer **Version of the Operating System and PowerShell the DSC Target Node is running:** +**Version of SharePoint that is used (e.g. SharePoint 2016):** + **Version of the DSC module you're using:** diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9657858..f4009ace5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,53 @@ # Change log for SharePointDsc +## 2.1 + +* General + * Updated the integration tests for building the Azure environment + * Works in any Azure environment. + * Updated the SqlServer configuration to use SqlServerDsc version 10.0.0.0. +* SPAlternateURL + * Added the ability to manage the Central Administration AAMs +* SPDiagnosticsProvider + * Added the resource +* SPFarm + * Corrected issue where ServerRole parameter is returned in SP2013 +* SPInfoPathFormsServiceConfig + * Added the resource +* SPInstallPrereqs + * Fixed two typos in to be installed Windows features for SharePoint 2016 +* SPSearchAutoritativePage + * Added missing readme.md +* SPSearchCrawlerImpactRule + * Fixed issue where an error was thrown when retrieving Crawl Impact rules + * Added missing readme.md +* SPSearchCrawlMapping + * Added missing readme.md +* SPSecureStoreServiceApp + * Fixed issue in Get-TargetResource to return AuditingEnabled property +* SPSecurityTokenServiceConfig + * Added the resource +* SPServiceIdentity + * Fixed issue with correctly retrieving the process identity for the + Search instance + * Added support for LocalSystem, LocalService and NetworkService +* SPUserProfileProperty + * Fixed issues with the User Profile properties for 2016 +* SPUserProfileServiceAppPermissions + * Removed the mandatory requirement from secondary parameters +* SPUserProfileSyncConnection + * Fixed issues with the User Profile Sync connection for SharePoint + 2016 +* SPUserProfileSyncService + * Added returning the FarmAccount to the Get method +* SPWebAppAuthentication + * Corrected issue where parameter validation wasn't performed correctly +* SPWebApplicationExtension + * Fixed issue with test always failing when Ensure was set to Absent +* SPWorkManagementServiceApp + * Added check for SharePoint 2016, since this functionality has been + removed in SharePoint 2016 + ## 2.0 * General diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 index 8b6790830..9318a3ab0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 @@ -5,29 +5,29 @@ function Get-TargetResource param ( [Parameter(Mandatory = $true)] - [System.String] + [System.String] $WebAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] + [System.String] $Zone, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Internal = $false, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -41,7 +41,7 @@ function Get-TargetResource $aam = Get-SPAlternateURL -Identity $params.Url ` -ErrorAction SilentlyContinue - if ($null -eq $aam) + if ($null -eq $aam) { return @{ WebAppName = $params.WebAppName @@ -60,7 +60,7 @@ function Get-TargetResource $wa = Get-SPWebApplication -Identity $aam.PublicUrl return @{ - WebAppName = $wa.Name + WebAppName = $wa.DisplayName Zone = $aam.Zone Url = $aam.IncomingUrl Internal = $internal @@ -77,43 +77,45 @@ function Set-TargetResource param ( [Parameter(Mandatory = $true)] - [System.String] + [System.String] $WebAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] + [System.String] $Zone, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Internal = $false, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting Alternate URL for $Zone in $WebAppName" - if ($Ensure -eq "Present") + if ($Ensure -eq "Present") { Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - $webapp = Get-SPWebApplication $params.WebAppName + $webapp = Get-SPWebApplication -IncludeCentralAdministration | Where-Object -FilterScript { + $_.DisplayName -eq $params.WebAppName + } if ($null -eq $webapp) { @@ -123,22 +125,22 @@ function Set-TargetResource $urlAam = Get-SPAlternateURL -Identity $params.Url ` -ErrorAction SilentlyContinue - $webAppAams = Get-SPAlternateURL -WebApplication $params.WebAppName ` + $webAppAams = Get-SPAlternateURL -WebApplication $webapp ` -Zone $params.Zone ` -ErrorAction SilentlyContinue - if ($null -eq $webAppAams) + if ($null -eq $webAppAams) { # No AAM found on specified WebApp in specified Zone if ($null -eq $urlAam) { # urlAAM not found, so it is safe to create AAM on specified zone $cmdParams = @{ - WebApplication = $params.WebAppName + WebApplication = $webapp Url = $params.Url Zone = $params.Zone } - if (($params.ContainsKey("Internal") -eq $true)) + if ($params.ContainsKey("Internal") -eq $true) { $cmdParams.Add("Internal", $params.Internal) } @@ -149,12 +151,12 @@ function Set-TargetResource throw ("Specified URL found on different WebApp/Zone: WebApp " + ` "$($urlAam.PublicUrl) in zone $($urlAam.Zone)") } - } - else + } + else { # WebApp has one or more AAMs, check for URL $aamForUrl = $webAppAams | Where-Object -FilterScript { - $_.IncomingUrl -eq $params.Url + $_.IncomingUrl -eq $params.Url } if ($null -eq $aamForUrl) @@ -164,7 +166,7 @@ function Set-TargetResource { # urlAAM not found, so it is safe to create AAM on specified zone $cmdParams = @{ - WebApplication = $params.WebAppName + WebApplication = $webapp Url = $params.Url Zone = $params.Zone } @@ -202,8 +204,8 @@ function Set-TargetResource } } } - } - else + } + else { Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` @@ -214,7 +216,7 @@ function Set-TargetResource Remove-SPAlternateURL -Identity $aam -Confirm:$false } - } + } } function Test-TargetResource @@ -224,35 +226,35 @@ function Test-TargetResource param ( [Parameter(Mandatory = $true)] - [System.String] + [System.String] $WebAppName, - [Parameter(Mandatory = $true)] - [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] + [System.String] $Zone, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Internal = $false, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Testing Alternate URL for $Zone in $WebAppName" - + $PSBoundParameters.Ensure = $Ensure $PSBoundParameters.Internal = $Internal @@ -266,7 +268,7 @@ function Test-TargetResource "Ensure", ` "Internal") } - else + else { return Test-SPDscParameterState -CurrentValues (Get-TargetResource @PSBoundParameters) ` -DesiredValues $PSBoundParameters ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md index 636d2291c..3eed3e88b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/readme.md @@ -5,5 +5,11 @@ 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. +To select the Central Administration site, use the following command to retrieve +the correct web application name: +(Get-SPWebApplication -IncludeCentralAdministration | Where-Object { + $_.IsAdministrationWebApplication + }).DisplayName + 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_SPBlobCacheSettings/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/Readme.md index d506b9543..06be5b8f9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/Readme.md @@ -9,11 +9,10 @@ file directly and is NOT using the SPWebConfigModifications class. In order to configure all WFE servers in the farm, you have to apply this resource to all servers. -Note: - -- In order to prevent inconsistancy between different web front end servers, - make sure you configure this setting on all servers equally. -- If the specified folder does not exist, the resource will create the folder. +NOTE: +In order to prevent inconsistancy between different web front end servers, +make sure you configure this setting on all servers equally. +If the specified folder does not exist, the resource will create the folder. Best practice: Specify a directory that is not on the same drive as where either the server diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md index b41a0f47a..89a9e6d34 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPContentDatabase/Readme.md @@ -1,10 +1,12 @@ # Description This resource is used to add and remove Content Databases to web applications -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. +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_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 new file mode 100644 index 000000000..74dd11706 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 @@ -0,0 +1,181 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.UInt16] + $Retention, + + [Parameter()] + [System.UInt64] + $MaxTotalSizeInBytes, + + [Parameter()] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Getting the Diagnostics Provider" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $diagnosticProvider = Get-SPDiagnosticsProvider | Where-Object {$_.Name -eq $params.Name} + $nullReturn = @{ + Name = $params.Name + Retention = $params.Retention + MaxTotalSizeInBytes = $params.MaxTotalSizeInBytes + Enabled = $params.Enabled + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + if ($null -eq $diagnosticProvider) + { + return $nullReturn + } + + return @{ + Name = $diagnosticProvider.Name + Retention = $diagnosticProvider.Retention + MaxTotalSizeInBytes = $diagnosticProvider.MaxTotalSizeInBytes + Enabled = $diagnosticProvider.Enabled + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.UInt16] + $Retention, + + [Parameter()] + [System.UInt64] + $MaxTotalSizeInBytes, + + [Parameter()] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Setting configuration for the Diagnostics Provider" + + if($Ensure -eq "Absent") + { + throw "This resource cannot remove Diagnostics Provider. Please use ensure equals Present." + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $diagnosticProvider = Get-SPDiagnosticsProvider | Where-Object {$_.Name -eq $params.Name} + + if($null -eq $diagnosticProvider) + { + throw "The specified Diagnostic Provider {" + $params.Name + "} could not be found." + } + + if($params.ContainsKey("Retention")) + { + $diagnosticProvider.Retention = $params.Retention + } + + if($params.ContainsKey("MaxTotalSizeInBytes")) + { + $diagnosticProvider.MaxTotalSizeInBytes = $params.MaxTotalSizeInBytes + } + + if($params.ContainsKey("Enabled")) + { + $diagnosticProvider.Enabled = $params.Enabled + } + + $diagnosticProvider.Update() + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.UInt16] + $Retention, + + [Parameter()] + [System.UInt64] + $MaxTotalSizeInBytes, + + [Parameter()] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Testing the Diagnostic Provider" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure", + "Name", + "Retention", + "MaxTotalSizeInBytes", + "Enabled") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.schema.mof new file mode 100644 index 000000000..1d7e4e5de --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.schema.mof @@ -0,0 +1,10 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPDiagnosticsProvider")] +class MSFT_SPDiagnosticsProvider : OMI_BaseResource +{ + [Key, Description("Name of the Diagnostics Provider to configure")] string Name; + [Write, Description("Sets the retention period in days")] Uint16 Retention; + [Write, Description("Sets the maximum retention size in bytes")] Uint64 MaxTotalSizeInBytes; + [Write, Description("True enables the Diagnostics Provider")] Boolean Enabled; + [Write, Description("Present to configure the diagnostics provider"), 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_SPDiagnosticsProvider/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/readme.md new file mode 100644 index 000000000..6d14c7fa8 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/readme.md @@ -0,0 +1,5 @@ +# Description + +This resource is responsible for configuring the Diagnostics Provider within +the local SharePoint farm. Using Ensure equals to Absent is not supported. +This resource can only apply configuration, not ensure they don't exist. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index d7ffcbb6e..ef82642b9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -4,50 +4,50 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] $Ensure, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $FarmConfigDatabaseName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $DatabaseServer, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $FarmAccount, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $Passphrase, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $AdminContentDatabaseName, [Parameter(Mandatory = $true)] [System.Boolean] $RunCentralAdmin, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $CentralAdministrationPort, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("NTLM","Kerberos")] $CentralAdministrationAuth, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("Application", "ApplicationWithSearch", "Custom", @@ -56,7 +56,7 @@ function Get-TargetResource "SingleServer", "SingleServerFarm", "WebFrontEnd", - "WebFrontEndWithDistributedCache")] + "WebFrontEndWithDistributedCache")] $ServerRole ) @@ -85,7 +85,7 @@ function Get-TargetResource if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) ` - -and $installedVersion.FileMajorPart -ne 16) + -and $installedVersion.FileMajorPart -ne 16) { throw [Exception] "Server role is only supported in SharePoint 2016." } @@ -94,7 +94,7 @@ function Get-TargetResource -and $installedVersion.FileMajorPart -eq 16 ` -and $installedVersion.FileBuildPart -lt 4456 ` -and ($ServerRole -eq "ApplicationWithSearch" ` - -or $ServerRole -eq "WebFrontEndWithDistributedCache")) + -or $ServerRole -eq "WebFrontEndWithDistributedCache")) { throw [Exception] ("ServerRole values of 'ApplicationWithSearch' or " + ` "'WebFrontEndWithDistributedCache' require the SharePoint 2016 " + ` @@ -116,41 +116,41 @@ function Get-TargetResource -ScriptBlock { $params = $args[0] - try + try { $spFarm = Get-SPFarm - } - catch + } + catch { Write-Verbose -Message "Unable to detect local farm." return $null } - - if ($null -eq $spFarm) + + if ($null -eq $spFarm) { - return $null + return $null } $configDb = Get-SPDatabase | Where-Object -FilterScript { - $_.Name -eq $spFarm.Name -and $_.Type -eq "Configuration Database" + $_.Name -eq $spFarm.Name -and $_.Type -eq "Configuration Database" } $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { - $_.IsAdministrationWebApplication -eq $true + $_.IsAdministrationWebApplication -eq $true } - if ($params.FarmAccount.UserName -eq $spFarm.DefaultServiceAccount.Name) + if ($params.FarmAccount.UserName -eq $spFarm.DefaultServiceAccount.Name) { $farmAccount = $params.FarmAccount - } - else + } + else { $farmAccount = $spFarm.DefaultServiceAccount.Name } $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { - $_.IsAdministrationWebApplication -eq $true + $_.IsAdministrationWebApplication -eq $true } $centralAdminProvisioned = $false @@ -177,7 +177,7 @@ function Get-TargetResource DatabaseServer = $configDb.NormalizedDataSource FarmAccount = $farmAccount # Need to return this as a credential to match the type expected InstallAccount = $null - Passphrase = $null + Passphrase = $null AdminContentDatabaseName = $centralAdminSite.ContentDatabases[0].Name RunCentralAdmin = $centralAdminProvisioned CentralAdministrationPort = (New-Object -TypeName System.Uri $centralAdminSite.Url).Port @@ -192,12 +192,8 @@ function Get-TargetResource $returnValue.Add("ServerRole", $server.Role) } } - elseif($installedVersion.FileMajorPart -eq 15) - { - $returnValue.Add("ServerRole", $null) - } return $returnValue - } + } if ($null -eq $result) { @@ -213,7 +209,7 @@ function Get-TargetResource DatabaseServer = $null FarmAccount = $null InstallAccount = $null - Passphrase = $null + Passphrase = $null AdminContentDatabaseName = $null RunCentralAdmin = $null CentralAdministrationPort = $null @@ -227,7 +223,7 @@ function Get-TargetResource return $result } } - else + else { # This node has never been connected to a farm, return the null return object return @{ @@ -235,7 +231,7 @@ function Get-TargetResource DatabaseServer = $null FarmAccount = $null InstallAccount = $null - Passphrase = $null + Passphrase = $null AdminContentDatabaseName = $null RunCentralAdmin = $null CentralAdministrationPort = $null @@ -252,50 +248,50 @@ function Set-TargetResource [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")] param ( - [Parameter(Mandatory = $true)] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] $Ensure, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $FarmConfigDatabaseName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $DatabaseServer, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $FarmAccount, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $Passphrase, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $AdminContentDatabaseName, [Parameter(Mandatory = $true)] [System.Boolean] $RunCentralAdmin, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $CentralAdministrationPort, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("NTLM","Kerberos")] $CentralAdministrationAuth, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("Application", "ApplicationWithSearch", "Custom", @@ -304,10 +300,10 @@ function Set-TargetResource "SingleServer", "SingleServerFarm", "WebFrontEnd", - "WebFrontEndWithDistributedCache")] + "WebFrontEndWithDistributedCache")] $ServerRole ) - + Write-Verbose -Message "Setting local SP Farm settings" if ($Ensure -eq "Absent") @@ -323,18 +319,18 @@ function Set-TargetResource throw ("This server is already connected to a farm. " + ` "Please manually remove it to apply this change.") } - + # Set default values to ensure they are passed to Invoke-SPDSCCommand - if (-not $PSBoundParameters.ContainsKey("CentralAdministrationPort")) + if (-not $PSBoundParameters.ContainsKey("CentralAdministrationPort")) { - $PSBoundParameters.Add("CentralAdministrationPort", 9999) + $PSBoundParameters.Add("CentralAdministrationPort", 9999) } - if (-not $PSBoundParameters.ContainsKey("CentralAdministrationAuth")) + if (-not $PSBoundParameters.ContainsKey("CentralAdministrationAuth")) { - $PSBoundParameters.Add("CentralAdministrationAuth", "NTLM") + $PSBoundParameters.Add("CentralAdministrationAuth", "NTLM") } - + $actionResult = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters, $PSScriptRoot) ` -ScriptBlock { @@ -396,7 +392,7 @@ function Set-TargetResource } } - if ($dbStatus.DatabaseExists -eq $true) + if ($dbStatus.DatabaseExists -eq $true) { Write-Verbose -Message ("The SharePoint config database " + ` "'$($params.FarmConfigDatabaseName)' already exists, so " + ` @@ -414,7 +410,7 @@ function Set-TargetResource "create one.") $createFarm = $false } - else + else { Write-Verbose -Message ("The SharePoint config database " + ` "'$($params.FarmConfigDatabaseName)' does not exist, so " + ` @@ -426,15 +422,15 @@ function Set-TargetResource if ($createFarm -eq $false) { # The database exists, so attempt to join the farm to the server - + # Remove the server role optional attribute as it is only used when creating # a new farm if ($executeArgs.ContainsKey("ServerRoleOptional") -eq $true) { - $executeArgs.Remove("ServerRoleOptional") + $executeArgs.Remove("ServerRoleOptional") } - + Write-Verbose -Message ("The server will attempt to join the farm now once every " + ` "60 seconds for the next 15 minutes.") $loopCount = 0 @@ -442,12 +438,12 @@ function Set-TargetResource $lastException = $null while ($connectedToFarm -eq $false -and $loopCount -lt 15) { - try + try { $joinObject = Connect-SPConfigurationDatabase @executeArgs $connectedToFarm = $true } - catch + catch { $lastException = $_.Exception Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - An error " + ` @@ -474,7 +470,7 @@ function Set-TargetResource Add-SPDscConfigDBLock -SQLServer $params.DatabaseServer ` -Database $params.FarmConfigDatabaseName - try + try { $executeArgs += @{ FarmCredentials = $params.FarmAccount @@ -493,38 +489,38 @@ function Set-TargetResource } # Run common tasks for a new server - Install-SPHelpCollection -All | Out-Null - Initialize-SPResourceSecurity | Out-Null - Install-SPService | Out-Null - Install-SPFeature -AllExistingFeatures -Force | Out-Null + Install-SPHelpCollection -All | Out-Null + Initialize-SPResourceSecurity | Out-Null + Install-SPService | Out-Null + Install-SPFeature -AllExistingFeatures -Force | Out-Null # Provision central administration if ($params.RunCentralAdmin -eq $true) { $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { - $_.IsAdministrationWebApplication -eq $true + $_.IsAdministrationWebApplication -eq $true } - + $centralAdminProvisioned = $false if ((New-Object -TypeName System.Uri $centralAdminSite.Url).Port -eq $params.CentralAdministrationPort) { $centralAdminProvisioned = $true } - + if ($centralAdminProvisioned -eq $false) { New-SPCentralAdministration -Port $params.CentralAdministrationPort ` -WindowsAuthProvider $params.CentralAdministrationAuth } - else + else { $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` | Where-Object -FilterScript { $_.TypeName -eq "Central Administration" } - if ($null -eq $serviceInstance) + if ($null -eq $serviceInstance) { $domain = (Get-CimInstance -ClassName Win32_ComputerSystem).Domain $fqdn = "$($env:COMPUTERNAME).$domain" @@ -533,15 +529,15 @@ function Set-TargetResource $_.TypeName -eq "Central Administration" } } - if ($null -eq $serviceInstance) + if ($null -eq $serviceInstance) { throw [Exception] "Unable to locate Central Admin service instance on this server" } - Start-SPServiceInstance -Identity $serviceInstance + Start-SPServiceInstance -Identity $serviceInstance } } - Install-SPApplicationContent | Out-Null + Install-SPApplicationContent | Out-Null return $farmAction } @@ -567,50 +563,50 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] $Ensure, - - [Parameter(Mandatory = $true)] - [System.String] + + [Parameter(Mandatory = $true)] + [System.String] $FarmConfigDatabaseName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $DatabaseServer, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $FarmAccount, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] $Passphrase, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $AdminContentDatabaseName, [Parameter(Mandatory = $true)] [System.Boolean] $RunCentralAdmin, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $CentralAdministrationPort, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("NTLM","Kerberos")] $CentralAdministrationAuth, - [Parameter()] - [System.String] + [Parameter()] + [System.String] [ValidateSet("Application", "ApplicationWithSearch", "Custom", @@ -619,7 +615,7 @@ function Test-TargetResource "SingleServer", "SingleServerFarm", "WebFrontEnd", - "WebFrontEndWithDistributedCache")] + "WebFrontEndWithDistributedCache")] $ServerRole ) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 new file mode 100644 index 000000000..689242778 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 @@ -0,0 +1,362 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserEnabling, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserRendering, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $DefaultDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionResponseSize, + + [Parameter()] + [System.Boolean] + $RequireSslForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowEmbeddedSqlForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUdcAuthenticationForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUserFormCrossDomainDataConnections, + + [Parameter()] + [System.UInt16] + $MaxPostbacksPerSession, + + [Parameter()] + [System.UInt16] + $MaxUserActionsPerPostback, + + [Parameter()] + [System.UInt16] + $ActiveSessionsTimeout, + + [Parameter()] + [System.UInt16] + $MaxSizeOfUserFormState, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting InfoPath Forms Service Configuration" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $config = Get-SPInfoPathFormsService + $nullReturn = @{ + AllowUserFormBrowserEnabling = $params.AllowUserFormBrowserEnabling + AllowUserFormBrowserRendering = $params.AllowUserFormBrowserRendering + MaxDataConnectionTimeout = $params.MaxDataConnectionTimeout + DefaultDataConnectionTimeout = $params.DefaultDataConnectionTimeout + MaxDataConnectionResponseSize = $params.MaxDataConnectionResponseSize + RequireSslForDataConnections = $params.RequireSslForDataConnections + AllowEmbeddedSqlForDataConnections = $params.AllowEmbeddedSqlForDataConnections + AllowUdcAuthenticationForDataConnections = $params.AllowUdcAuthenticationForDataConnections + AllowUserFormCrossDomainDataConnections = $params.AllowUserFormCrossDomainDataConnections + MaxPostbacksPerSession = $params.MaxPostbacksPerSession + MaxUserActionsPerPostback = $params.MaxUserActionsPerPostback + ActiveSessionsTimeout = $params.ActiveSessionsTimeout + MaxSizeOfUserFormState = ($params.MaxSizeOfUserFormState / 1024) + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + if ($null -eq $config) + { + return $nullReturn + } + + return @{ + AllowUserFormBrowserEnabling = $config.AllowUserFormBrowserEnabling + AllowUserFormBrowserRendering = $config.AllowUserFormBrowserRendering + MaxDataConnectionTimeout = $config.MaxDataConnectionTimeout + DefaultDataConnectionTimeout = $config.DefaultDataConnectionTimeout + MaxDataConnectionResponseSize = $config.MaxDataConnectionResponseSize + RequireSslForDataConnections = $config.RequireSslForDataConnections + AllowEmbeddedSqlForDataConnections = $config.AllowEmbeddedSqlForDataConnections + AllowUdcAuthenticationForDataConnections = $config.AllowUdcAuthenticationForDataConnections + AllowUserFormCrossDomainDataConnections = $config.AllowUserFormCrossDomainDataConnections + MaxPostbacksPerSession = $config.MaxPostbacksPerSession + MaxUserActionsPerPostback = $config.MaxUserActionsPerPostback + ActiveSessionsTimeout = $config.ActiveSessionsTimeout + MaxSizeOfUserFormState = ($config.MaxSizeOfUserFormState / 1024) + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserEnabling, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserRendering, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $DefaultDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionResponseSize, + + [Parameter()] + [System.Boolean] + $RequireSslForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowEmbeddedSqlForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUdcAuthenticationForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUserFormCrossDomainDataConnections, + + [Parameter()] + [System.UInt16] + $MaxPostbacksPerSession, + + [Parameter()] + [System.UInt16] + $MaxUserActionsPerPostback, + + [Parameter()] + [System.UInt16] + $ActiveSessionsTimeout, + + [Parameter()] + [System.UInt16] + $MaxSizeOfUserFormState, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting InfoPath Forms Service Configuration" + + if($Ensure -eq "Absent") + { + throw "This resource cannot undo InfoPath Forms Service Configuration changes. ` + Please set Ensure to Present or omit the resource" + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $config = Get-SPInfoPathFormsService + + if($params.ContainsKey("AllowUserFormBrowserEnabling")) + { + $config.AllowUserFormBrowserEnabling = $params.AllowUserFormBrowserEnabling + } + + if($params.ContainsKey("AllowUserFormBrowserRendering")) + { + $config.AllowUserFormBrowserRendering = $params.AllowUserFormBrowserRendering + } + + if($params.ContainsKey("MaxDataConnectionTimeout")) + { + $config.MaxDataConnectionTimeout = $params.MaxDataConnectionTimeout + } + + if($params.ContainsKey("DefaultDataConnectionTimeout")) + { + $config.DefaultDataConnectionTimeout = $params.DefaultDataConnectionTimeout + } + + if($params.ContainsKey("MaxDataConnectionResponseSize")) + { + $config.MaxDataConnectionResponseSize = $params.MaxDataConnectionResponseSize + } + + if($params.ContainsKey("RequireSslForDataConnections")) + { + $config.RequireSslForDataConnections = $params.RequireSslForDataConnections + } + + if($params.ContainsKey("AllowEmbeddedSqlForDataConnections")) + { + $config.AllowEmbeddedSqlForDataConnections = $params.AllowEmbeddedSqlForDataConnections + } + + if($params.ContainsKey("AllowUdcAuthenticationForDataConnections")) + { + $config.AllowUdcAuthenticationForDataConnections = $params.AllowUdcAuthenticationForDataConnections + } + + if($params.ContainsKey("AllowUserFormCrossDomainDataConnections")) + { + $config.AllowUserFormCrossDomainDataConnections = $params.AllowUserFormCrossDomainDataConnections + } + + if($params.ContainsKey("MaxPostbacksPerSession")) + { + $config.MaxPostbacksPerSession = $params.MaxPostbacksPerSession + } + + if($params.ContainsKey("MaxUserActionsPerPostback")) + { + $config.MaxUserActionsPerPostback = $params.MaxUserActionsPerPostback + } + + if($params.ContainsKey("ActiveSessionsTimeout")) + { + $config.ActiveSessionsTimeout = $params.ActiveSessionsTimeout + } + + if($params.ContainsKey("MaxSizeOfUserFormState")) + { + $config.MaxSizeOfUserFormState = ($config.MaxSizeOfUserFormState * 1024) + } + + $config.Update() + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserEnabling, + + [Parameter()] + [System.Boolean] + $AllowUserFormBrowserRendering, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $DefaultDataConnectionTimeout, + + [Parameter()] + [System.UInt32] + $MaxDataConnectionResponseSize, + + [Parameter()] + [System.Boolean] + $RequireSslForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowEmbeddedSqlForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUdcAuthenticationForDataConnections, + + [Parameter()] + [System.Boolean] + $AllowUserFormCrossDomainDataConnections, + + [Parameter()] + [System.UInt16] + $MaxPostbacksPerSession, + + [Parameter()] + [System.UInt16] + $MaxUserActionsPerPostback, + + [Parameter()] + [System.UInt16] + $ActiveSessionsTimeout, + + [Parameter()] + [System.UInt16] + $MaxSizeOfUserFormState, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing the InfoPath Form Services Configuration" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure", + "AllowUserFormBrowserEnabling", + "AllowUserFormBrowserRendering", + "MaxDataConnectionTimeout", + "DefaultDataConnectionTimeout", + "MaxDataConnectionResponseSize", + "RequireSslForDataConnections", + "AllowEmbeddedSqlForDataConnections", + "AllowUdcAuthenticationForDataConnections", + "AllowUserFormCrossDomainDataConnections", + "MaxPostbacksPerSession", + "MaxUserActionsPerPostback", + "ActiveSessionsTimeout", + "MaxSizeOfUserFormState") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.schema.mof new file mode 100644 index 000000000..9f17d34e7 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.schema.mof @@ -0,0 +1,19 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPInfoPathFormsServiceConfig")] +class MSFT_SPInfoPathFormsServiceConfig : OMI_BaseResource +{ + [Key, Description("Present ensures the settings are applied"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("True sets the InfoPath Forms Service to allow users to browse forms")] Boolean AllowUserFormBrowserEnabling; + [Write, Description("True sets the InfoPath Forms Service to render forms in the browser")] Boolean AllowUserFormBrowserRendering; + [Write, Description("Sets the maximum connection timeout in milliseconds")] Uint32 MaxDataConnectionTimeout; + [Write, Description("Sets the default connection timeout in milliseconds")] Uint32 DefaultDataConnectionTimeout; + [Write, Description("Sets the maximum response size in kb for the user response")] Uint32 MaxDataConnectionResponseSize; + [Write, Description("True sets the InfoPath Forms Service to require SSL for its connections")] Boolean RequireSslForDataConnections; + [Write, Description("True sets the InfoPath Forms Service to allow embedded SQL sonnections in Forms")] Boolean AllowEmbeddedSqlForDataConnections; + [Write, Description("True sets the InfoPath Forms Service to allow User Defined connections")] Boolean AllowUdcAuthenticationForDataConnections; + [Write, Description("True sets the InfoPath Forms Service to allow Cross-Domain connections")] Boolean AllowUserFormCrossDomainDataConnections; + [Write, Description("Maximum number of postback allowed per session")] Uint16 MaxPostbacksPerSession; + [Write, Description("Maximum number of actions that can be triggered per postback")] Uint16 MaxUserActionsPerPostback; + [Write, Description("Timeout in minutes for active sessions")] Uint16 ActiveSessionsTimeout; + [Write, Description("Maximum size of user session data")] Uint16 MaxSizeOfUserFormState; + [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_SPInfoPathFormsServiceConfig/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/readme.md new file mode 100644 index 000000000..da7265889 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/readme.md @@ -0,0 +1,5 @@ +# Description + +This resource is responsible for configuring the InfoPath Forms service within +the local SharePoint farm. Using Ensure equals to Absent is not supported. +This resource can only apply configuration, not ensure they don't exist. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md index dc8d3103d..5de1e89a0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md @@ -6,7 +6,8 @@ itself). The ProductKey parameter is used to inject in to the configuration file and validate the license key during the installation process. This module depends on the prerequisites already being installed, which can be done -NOTE: This resource only supports SharePoint Server. SharePoint Foundation +NOTE: +This resource only supports SharePoint Server. SharePoint Foundation is not supported. For examples to install SharePoint Foundation using DSC, see: https://github.com/PowerShell/SharePointDsc/wiki/SPInstall (Example 3) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 index 3749fec82..4cc19b817 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 @@ -1,53 +1,53 @@ -$Script:SP2013Features = @("Application-Server", "AS-NET-Framework", - "AS-TCP-Port-Sharing", "AS-Web-Support", "AS-WAS-Support", - "AS-HTTP-Activation", "AS-Named-Pipes", "AS-TCP-Activation","Web-Server", - "Web-WebServer", "Web-Common-Http", "Web-Default-Doc", "Web-Dir-Browsing", - "Web-Http-Errors", "Web-Static-Content", "Web-Http-Redirect", "Web-Health", - "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", - "Web-Http-Tracing", "Web-Performance", "Web-Stat-Compression", - "Web-Dyn-Compression", "Web-Security", "Web-Filtering", "Web-Basic-Auth", - "Web-Client-Auth", "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", - "Web-Url-Auth", "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", - "Web-Net-Ext45", "Web-Asp-Net", "Web-Asp-Net45", "Web-ISAPI-Ext", - "Web-ISAPI-Filter", "Web-Mgmt-Tools", "Web-Mgmt-Console", "Web-Mgmt-Compat", - "Web-Metabase", "Web-Lgcy-Scripting", "Web-WMI", "Web-Scripting-Tools", - "NET-Framework-Features", "NET-Framework-Core", "NET-Framework-45-ASPNET", - "NET-WCF-HTTP-Activation45", "NET-WCF-Pipe-Activation45", - "NET-WCF-TCP-Activation45", "Server-Media-Foundation", - "Windows-Identity-Foundation", "PowerShell-V2", "WAS", "WAS-Process-Model", +$Script:SP2013Features = @("Application-Server", "AS-NET-Framework", + "AS-TCP-Port-Sharing", "AS-Web-Support", "AS-WAS-Support", + "AS-HTTP-Activation", "AS-Named-Pipes", "AS-TCP-Activation","Web-Server", + "Web-WebServer", "Web-Common-Http", "Web-Default-Doc", "Web-Dir-Browsing", + "Web-Http-Errors", "Web-Static-Content", "Web-Http-Redirect", "Web-Health", + "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", + "Web-Http-Tracing", "Web-Performance", "Web-Stat-Compression", + "Web-Dyn-Compression", "Web-Security", "Web-Filtering", "Web-Basic-Auth", + "Web-Client-Auth", "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", + "Web-Url-Auth", "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", + "Web-Net-Ext45", "Web-Asp-Net", "Web-Asp-Net45", "Web-ISAPI-Ext", + "Web-ISAPI-Filter", "Web-Mgmt-Tools", "Web-Mgmt-Console", "Web-Mgmt-Compat", + "Web-Metabase", "Web-Lgcy-Scripting", "Web-WMI", "Web-Scripting-Tools", + "NET-Framework-Features", "NET-Framework-Core", "NET-Framework-45-ASPNET", + "NET-WCF-HTTP-Activation45", "NET-WCF-Pipe-Activation45", + "NET-WCF-TCP-Activation45", "Server-Media-Foundation", + "Windows-Identity-Foundation", "PowerShell-V2", "WAS", "WAS-Process-Model", "WAS-NET-Environment", "WAS-Config-APIs", "XPS-Viewer") -$Script:SP2016Win16Features = @("Web-Server", "Web-WebServer", - "Web-Common-Http", "Web-Default-Doc", "Web-Dir-Browsing", - "Web-Http-Errors", "Web-Static-Content", "Web-Health", - "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", - "Web-Http-Tracing", "Web-Performance", "Web-Stat-Compression", - "Web-Dyn-Compression", "Web-Security", "Web-Filering", "Web-Basic-Auth", - "Web-Digest-Auth", "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", - "Web-Net-Ext45Web-Asp-Net", "Web-Asp-Net45", "Web-ISAPI-Ext", - "Web-ISAPI-Filter", "Web-Mgmt-Tools", "Web-Mgmt-Console", - "Web-Mgmt-Compat", "Web-Metabase", "Web-Lgcy-Scripting", "Web-WMI", - "NET-Framework-Features", "NET-HTTP-Activation", "NET-Non-HTTP-Activ", - "NET-Framework-45-ASPNET", "NET-WCF-Pipe-Activation45", - "Windows-Identity-Foundation", "WAS", "WAS-Process-Model", +$Script:SP2016Win16Features = @("Web-Server", "Web-WebServer", + "Web-Common-Http", "Web-Default-Doc", "Web-Dir-Browsing", + "Web-Http-Errors", "Web-Static-Content", "Web-Health", + "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", + "Web-Http-Tracing", "Web-Performance", "Web-Stat-Compression", + "Web-Dyn-Compression", "Web-Security", "Web-Filtering", "Web-Basic-Auth", + "Web-Digest-Auth", "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", + "Web-Net-Ext45", "Web-Asp-Net", "Web-Asp-Net45", "Web-ISAPI-Ext", + "Web-ISAPI-Filter", "Web-Mgmt-Tools", "Web-Mgmt-Console", + "Web-Mgmt-Compat", "Web-Metabase", "Web-Lgcy-Scripting", "Web-WMI", + "NET-Framework-Features", "NET-HTTP-Activation", "NET-Non-HTTP-Activ", + "NET-Framework-45-ASPNET", "NET-WCF-Pipe-Activation45", + "Windows-Identity-Foundation", "WAS", "WAS-Process-Model", "WAS-NET-Environment", "WAS-Config-APIs", "XPS-Viewer") -$Script:SP2016Win12r2Features = @("Application-Server", "AS-NET-Framework", - "AS-Web-Support", "Web-Server", "Web-WebServer", "Web-Common-Http", - "Web-Default-Doc", "Web-Dir-Browsing", "Web-Http-Errors", - "Web-Static-Content", "Web-Http-Redirect", "Web-Health", - "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", - "Web-Performance", "Web-Stat-Compression", "Web-Dyn-Compression", - "Web-Security", "Web-Filtering", "Web-Basic-Auth", "Web-Client-Auth", - "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", "Web-Url-Auth", - "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", "Web-Net-Ext45", - "Web-Asp-Net45", "Web-ISAPI-Ext", "Web-ISAPI-Filter", "Web-Mgmt-Tools", - "Web-Mgmt-Console", "Web-Mgmt-Compat", "Web-Metabase", - "Web-Lgcy-Mgmt-Console", "Web-Lgcy-Scripting", "Web-WMI", - "Web-Scripting-Tools", "NET-Framework-Features", "NET-Framework-Core", - "NET-HTTP-Activation", "NET-Non-HTTP-Activ", "NET-Framework-45-ASPNET", - "NET-WCF-HTTP-Activation45", "Windows-Identity-Foundation", - "PowerShell-V2", "WAS", "WAS-Process-Model", "WAS-NET-Environment", +$Script:SP2016Win12r2Features = @("Application-Server", "AS-NET-Framework", + "AS-Web-Support", "Web-Server", "Web-WebServer", "Web-Common-Http", + "Web-Default-Doc", "Web-Dir-Browsing", "Web-Http-Errors", + "Web-Static-Content", "Web-Http-Redirect", "Web-Health", + "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", + "Web-Performance", "Web-Stat-Compression", "Web-Dyn-Compression", + "Web-Security", "Web-Filtering", "Web-Basic-Auth", "Web-Client-Auth", + "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", "Web-Url-Auth", + "Web-Windows-Auth", "Web-App-Dev", "Web-Net-Ext", "Web-Net-Ext45", + "Web-Asp-Net45", "Web-ISAPI-Ext", "Web-ISAPI-Filter", "Web-Mgmt-Tools", + "Web-Mgmt-Console", "Web-Mgmt-Compat", "Web-Metabase", + "Web-Lgcy-Mgmt-Console", "Web-Lgcy-Scripting", "Web-WMI", + "Web-Scripting-Tools", "NET-Framework-Features", "NET-Framework-Core", + "NET-HTTP-Activation", "NET-Non-HTTP-Activ", "NET-Framework-45-ASPNET", + "NET-WCF-HTTP-Activation45", "Windows-Identity-Foundation", + "PowerShell-V2", "WAS", "WAS-Process-Model", "WAS-NET-Environment", "WAS-Config-APIs") @@ -57,110 +57,110 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $InstallerPath, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $OnlineMode, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SXSpath, - - [Parameter()] - [System.String] - $SQLNCli, - - [Parameter()] - [System.String] - $PowerShell, - - [Parameter()] - [System.String] - $NETFX, - - [Parameter()] - [System.String] - $IDFX, - - [Parameter()] - [System.String] - $Sync, - - [Parameter()] - [System.String] - $AppFabric, - - [Parameter()] - [System.String] - $IDFX11, - - [Parameter()] - [System.String] - $MSIPCClient, - - [Parameter()] - [System.String] - $WCFDataServices, - - [Parameter()] - [System.String] - $KB2671763, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] + $SQLNCli, + + [Parameter()] + [System.String] + $PowerShell, + + [Parameter()] + [System.String] + $NETFX, + + [Parameter()] + [System.String] + $IDFX, + + [Parameter()] + [System.String] + $Sync, + + [Parameter()] + [System.String] + $AppFabric, + + [Parameter()] + [System.String] + $IDFX11, + + [Parameter()] + [System.String] + $MSIPCClient, + + [Parameter()] + [System.String] + $WCFDataServices, + + [Parameter()] + [System.String] + $KB2671763, + + [Parameter()] + [System.String] $WCFDataServices56, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT11, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT14, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $KB3092423, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ODBC, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DotNetFx, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present" ) - + Write-Verbose -Message "Getting installation status of SharePoint prerequisites" $majorVersion = (Get-SPDSCAssemblyVersion -PathToAssembly $InstallerPath) - if ($majorVersion -eq 15) + if ($majorVersion -eq 15) { Write-Verbose -Message "Version: SharePoint 2013" } - if ($majorVersion -eq 16) + if ($majorVersion -eq 16) { Write-Verbose -Message "Version: SharePoint 2016" } Write-Verbose -Message "Getting installed windows features" - $osVersion = Get-SPDscOSVersion - if ($majorVersion -eq 15) + $osVersion = Get-SPDscOSVersion + if ($majorVersion -eq 15) { $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2013Features } - if ($majorVersion -eq 16) + if ($majorVersion -eq 16) { - if ($osVersion.Major -eq 10) + if ($osVersion.Major -eq 10) { # Server 2016 $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2016Win16Features @@ -170,16 +170,16 @@ function Get-TargetResource # Server 2012 R2 $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2016Win12r2Features } - else + else { - throw "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" - } + throw "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" + } } - + $windowsFeaturesInstalled = $true - foreach ($feature in $WindowsFeatures) + foreach ($feature in $WindowsFeatures) { - if ($feature.Installed -eq $false) + if ($feature.Installed -eq $false) { $windowsFeaturesInstalled = $false Write-Verbose -Message "Windows feature $($feature.Name) is not installed" @@ -190,7 +190,7 @@ function Get-TargetResource $x86Path = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" $installedItemsX86 = Get-ItemProperty -Path $x86Path | Select-Object -Property DisplayName - + $x64Path = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" $installedItemsX64 = Get-ItemProperty -Path $x64Path | Select-Object -Property DisplayName @@ -224,9 +224,9 @@ function Get-TargetResource SearchValue = "WCF Data Services 5.6.0 Runtime" } ) - + #SP2013 prereqs - if ($majorVersion -eq 15) + if ($majorVersion -eq 15) { $prereqsToTest += @( [PSObject]@{ @@ -248,7 +248,7 @@ function Get-TargetResource } #SP2016 prereqs - if ($majorVersion -eq 16) + if ($majorVersion -eq 16) { $prereqsToTest += @( [PSObject]@{ @@ -286,11 +286,11 @@ function Get-TargetResource SearchType = "Like" SearchValue = "Microsoft Visual C++ 2015 x64 Additional Runtime - 14.0.*" } - ) + ) } $prereqsInstalled = Test-SPDscPrereqInstallStatus -InstalledItems $installedItems ` -PrereqsToCheck $prereqsToTest - + $results = @{ InstallerPath = $InstallerPath OnlineMode = $OnlineMode @@ -313,15 +313,15 @@ function Get-TargetResource DotNetFx = $DotNetFx } - if ($prereqsInstalled -eq $true -and $windowsFeaturesInstalled -eq $true) + if ($prereqsInstalled -eq $true -and $windowsFeaturesInstalled -eq $true) { $results.Ensure = "Present" - } - else + } + else { $results.Ensure = "Absent" } - + return $results } @@ -332,91 +332,91 @@ function Set-TargetResource [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $InstallerPath, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $OnlineMode, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SXSpath, - - [Parameter()] - [System.String] - $SQLNCli, - - [Parameter()] - [System.String] - $PowerShell, - - [Parameter()] - [System.String] - $NETFX, - - [Parameter()] - [System.String] - $IDFX, - - [Parameter()] - [System.String] - $Sync, - - [Parameter()] - [System.String] - $AppFabric, - - [Parameter()] - [System.String] - $IDFX11, - - [Parameter()] - [System.String] - $MSIPCClient, - - [Parameter()] - [System.String] - $WCFDataServices, - - [Parameter()] - [System.String] - $KB2671763, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] + $SQLNCli, + + [Parameter()] + [System.String] + $PowerShell, + + [Parameter()] + [System.String] + $NETFX, + + [Parameter()] + [System.String] + $IDFX, + + [Parameter()] + [System.String] + $Sync, + + [Parameter()] + [System.String] + $AppFabric, + + [Parameter()] + [System.String] + $IDFX11, + + [Parameter()] + [System.String] + $MSIPCClient, + + [Parameter()] + [System.String] + $WCFDataServices, + + [Parameter()] + [System.String] + $KB2671763, + + [Parameter()] + [System.String] $WCFDataServices56, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT11, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT14, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $KB3092423, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ODBC, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DotNetFx, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present" ) Write-Verbose -Message "Setting installation status of SharePoint prerequisites" - if ($Ensure -eq "Absent") + if ($Ensure -eq "Absent") { throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or its " + ` "prerequisites. Please remove this manually.") @@ -427,7 +427,7 @@ function Set-TargetResource $majorVersion = Get-SPDSCAssemblyVersion -PathToAssembly $InstallerPath $osVersion = Get-SPDscOSVersion - if ($majorVersion -eq 15) + if ($majorVersion -eq 15) { $BinaryDir = Split-Path -Path $InstallerPath $svrsetupDll = Join-Path -Path $BinaryDir -ChildPath "updates\svrsetup.dll" @@ -459,82 +459,82 @@ function Set-TargetResource } } - if ($dotNet46Installed -eq $true) + if ($dotNet46Installed -eq $true) { throw [Exception] ("A known issue prevents installation of SharePoint 2013 on " + ` "servers that have .NET 4.6 already installed. See details " + ` "at https://support.microsoft.com/en-us/kb/3087184") return - } + } } - + Write-Verbose -Message "Version: SharePoint 2013" $requiredParams = @("SQLNCli","PowerShell","NETFX","IDFX","Sync","AppFabric","IDFX11", "MSIPCClient","WCFDataServices","KB2671763","WCFDataServices56") $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2013Features } - - if ($majorVersion -eq 16) + + if ($majorVersion -eq 16) { Write-Verbose -Message "Version: SharePoint 2016" $requiredParams = @("SQLNCli","Sync","AppFabric","IDFX11","MSIPCClient","KB3092423", "WCFDataServices56","DotNetFx","MSVCRT11","MSVCRT14","ODBC") - if ($osVersion.Major -eq 10) + if ($osVersion.Major -eq 10) { # Server 2016 $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2016Win16Features - } + } elseif ($osVersion.Major -eq 6 -and $osVersion.Minor -eq 3) { # Server 2012 R2 $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2016Win12r2Features } - else + else { - throw "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" + throw "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" } } - - # SXSstore for feature install specified, we will manually install features from the + + # SXSstore for feature install specified, we will manually install features from the # store, rather then relying on the prereq installer to download them if ($SXSpath) { Write-Verbose -Message "Getting installed windows features" - foreach ($feature in $WindowsFeatures) + foreach ($feature in $WindowsFeatures) { - if ($feature.Installed -ne $true) + if ($feature.Installed -ne $true) { Write-Verbose "Installing $($feature.name)" $installResult = Install-WindowsFeature -Name $feature.Name -Source $SXSpath - if ($installResult.restartneeded -eq "yes") + if ($installResult.restartneeded -eq "yes") { $global:DSCMachineStatus = 1 } - if ($installResult.Success -ne $true) + if ($installResult.Success -ne $true) { throw "Error installing $($feature.name)" } } } - + # see if we need to reboot after feature install - if ($global:DSCMachineStatus -eq 1) + if ($global:DSCMachineStatus -eq 1) { return - } + } } - + $prereqArgs = "/unattended" - if ($OnlineMode -eq $false) + if ($OnlineMode -eq $false) { $requiredParams | ForEach-Object -Process { if (($PSBoundParameters.ContainsKey($_) -eq $true ` -and [string]::IsNullOrEmpty($PSBoundParameters.$_)) ` - -or (-not $PSBoundParameters.ContainsKey($_))) + -or (-not $PSBoundParameters.ContainsKey($_))) { throw "In offline mode for version $majorVersion parameter $_ is required" } - if ((Test-Path $PSBoundParameters.$_) -eq $false) + if ((Test-Path $PSBoundParameters.$_) -eq $false) { throw ("The $_ parameter has been passed but the file cannot be found at the " + ` "path supplied: `"$($PSBoundParameters.$_)`"") @@ -549,39 +549,39 @@ function Set-TargetResource Write-Verbose -Message "Args for prereq installer are: $prereqArgs" $process = Start-Process -FilePath $InstallerPath -ArgumentList $prereqArgs -Wait -PassThru - switch ($process.ExitCode) + switch ($process.ExitCode) { - 0 + 0 { Write-Verbose -Message "Prerequisite installer completed successfully." } - 1 + 1 { throw "Another instance of the prerequisite installer is already running" } - 2 + 2 { throw "Invalid command line parameters passed to the prerequisite installer" } - 1001 + 1001 { Write-Verbose -Message ("A pending restart is blocking the prerequisite " + ` "installer from running. Scheduling a reboot.") $global:DSCMachineStatus = 1 } - 3010 + 3010 { Write-Verbose -Message ("The prerequisite installer has run correctly and needs " + ` "to reboot the machine before continuing.") $global:DSCMachineStatus = 1 } - default + default { throw ("The prerequisite installer ran with the following unknown " + ` "exit code $($process.ExitCode)") } } - + $rebootKey1 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\" + ` "Component Based Servicing\RebootPending" $rebootTest1 = Get-Item -Path $rebootKey1 -ErrorAction SilentlyContinue @@ -599,7 +599,7 @@ function Set-TargetResource Write-Verbose -Message ("SPInstallPrereqs has detected the server has pending a " + ` "reboot. Flagging to the DSC engine that the server should " + ` "reboot before continuing.") - $global:DSCMachineStatus = 1 + $global:DSCMachineStatus = 1 } } @@ -610,85 +610,85 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $InstallerPath, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $OnlineMode, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $SXSpath, - - [Parameter()] - [System.String] - $SQLNCli, - - [Parameter()] - [System.String] - $PowerShell, - - [Parameter()] - [System.String] - $NETFX, - - [Parameter()] - [System.String] - $IDFX, - - [Parameter()] - [System.String] - $Sync, - - [Parameter()] - [System.String] - $AppFabric, - - [Parameter()] - [System.String] - $IDFX11, - - [Parameter()] - [System.String] - $MSIPCClient, - - [Parameter()] - [System.String] - $WCFDataServices, - - [Parameter()] - [System.String] - $KB2671763, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] + $SQLNCli, + + [Parameter()] + [System.String] + $PowerShell, + + [Parameter()] + [System.String] + $NETFX, + + [Parameter()] + [System.String] + $IDFX, + + [Parameter()] + [System.String] + $Sync, + + [Parameter()] + [System.String] + $AppFabric, + + [Parameter()] + [System.String] + $IDFX11, + + [Parameter()] + [System.String] + $MSIPCClient, + + [Parameter()] + [System.String] + $WCFDataServices, + + [Parameter()] + [System.String] + $KB2671763, + + [Parameter()] + [System.String] $WCFDataServices56, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT11, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $MSVCRT14, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $KB3092423, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $ODBC, - - [Parameter()] - [System.String] + + [Parameter()] + [System.String] $DotNetFx, - - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present" ) @@ -696,7 +696,7 @@ function Test-TargetResource $PSBoundParameters.Ensure = $Ensure - if ($Ensure -eq "Absent") + if ($Ensure -eq "Absent") { throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or its " + ` "prerequisites. Please remove this manually.") @@ -704,7 +704,7 @@ function Test-TargetResource } $CurrentValues = Get-TargetResource @PSBoundParameters - + return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters -ValuesToCheck @("Ensure") } @@ -730,42 +730,42 @@ function Test-SPDscPrereqInstallStatus $itemsInstalled = $true $PrereqsToCheck | ForEach-Object -Process { $itemToCheck = $_ - switch ($itemToCheck.SearchType) + switch ($itemToCheck.SearchType) { - "Equals" + "Equals" { if ($null -eq ($InstalledItems | Where-Object -FilterScript { $null -ne $_.DisplayName -and $_.DisplayName.Trim() -eq $itemToCheck.SearchValue - })) + })) { $itemsInstalled = $false Write-Verbose -Message ("Prerequisite $($itemToCheck.Name) was not found " + ` "on this system") } } - "Match" + "Match" { if ($null -eq ($InstalledItems | Where-Object -FilterScript { $null -ne $_.DisplayName -and $_.DisplayName.Trim() -match $itemToCheck.SearchValue - })) + })) { $itemsInstalled = $false Write-Verbose -Message ("Prerequisite $($itemToCheck.Name) was not found " + ` "on this system") } } - "Like" + "Like" { if ($null -eq ($InstalledItems | Where-Object -FilterScript { $null -ne $_.DisplayName -and $_.DisplayName.Trim() -like $itemToCheck.SearchValue - })) + })) { $itemsInstalled = $false Write-Verbose -Message ("Prerequisite $($itemToCheck.Name) was not found " + ` "on this system") } } - Default + Default { throw ("Unable to search for a prereq with mode '$($itemToCheck.SearchType)'. " + ` "please use either 'Equals', 'Like' or 'Match'") diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 index 93888c397..c97b2b394 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 @@ -144,4 +144,7 @@ function Test-TargetResource -ValuesToCheck @("State") } -Export-ModuleMember -Function *-TargetResource +Export-ModuleMember -Function Get-TargetResource, ` + Test-TargetResource, ` + Set-TargetResource, ` + Get-SPDscRoleTestMethod diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md index 046459a2d..94cbae815 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPOfficeOnlineServerBinding/readme.md @@ -4,7 +4,8 @@ This resource will create a binding to an Office Online Server (formerly known as Office Web Apps). The DnsName property can be a single server name, or a FQDN of a load balanced end point that will direct traffic to a farm. -NOTE: This resource is designed to be used where all WOPI bindings will be +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 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/readme.md index 69b6a58ae..ba49d0e34 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/readme.md @@ -5,7 +5,8 @@ resource pool sync for Project Server, for a specific PWA instance. You can control which AD groups should be imported from and control settings about reactivitating users. -Note: The schedule for this import is controlled via a standard +NOTE: +The schedule for this import is controlled via a standard SharePoint server timer job, and as such it can be controlled with the SPTimerJobState resource. Below is an example of how to set this resource to run the AD import job daily. The name of the job diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/readme.md index d1851a945..a922c8dbd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/readme.md @@ -3,7 +3,8 @@ This resource is used to control settings that relate to the SharePoint sites that are linked to projects in Project Server. -NOTE: The account you use to run this resource (through either the InstallAccount +NOTE: +The account you use to run this resource (through either the InstallAccount or PsDscRunAsCredential properties) needs to have elevated rights to execute this resource. It is recommended to use the SharePoint Farm Account for this purpose to avoid receiving a "GeneralSecurityAccessDenied" error. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/readme.md new file mode 100644 index 000000000..46ca782cf --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/readme.md @@ -0,0 +1,8 @@ +# Description + +This resource is responsible for managing the search authoritative pages in the +search service application. You can create new pages, change existing pages and +remove existing pages. + +The default value for the Ensure parameter is Present. When you omit this +parameter the crawl rule is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/readme.md new file mode 100644 index 000000000..0f6770f34 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/readme.md @@ -0,0 +1,8 @@ +# Description + +This resource is responsible for managing the search crawl mapping in the +search service application. You can create new mappings, change existing mappings +and remove existing mappings. + +The default value for the Ensure parameter is Present. When you omit 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 index 5fe8479fc..4bdc4b44b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 @@ -19,19 +19,19 @@ function Get-TargetResource [Parameter()] [System.UInt32] $WaitTime = 0, - + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [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" @@ -41,9 +41,9 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $nullReturn = @{ - + ServiceAppName = $params.ServiceAppName Name = $params.Name RequestLimit = $null @@ -59,14 +59,14 @@ function Get-TargetResource $nullReturn.ServiceAppName = $null return $nullReturn } - else + else { - $crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -Identity $params.Name -SearchService $serviceApp + $crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -Identity $params.Name -SearchService $params.ServiceAppName if($null -eq $crawlerImpactRule) { return $nullReturn } - else + else { if($crawlerImpactRule.Behavior -eq "0") { @@ -79,7 +79,7 @@ function Get-TargetResource InstallAccount = $params.InstallAccount } } - else + else { return @{ ServiceAppName = $params.ServiceAppName @@ -95,7 +95,7 @@ function Get-TargetResource } - + return $result } @@ -140,7 +140,7 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters - if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") { Write-Verbose -Message "Creating Crawler Impact Rule $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -154,7 +154,7 @@ function Set-TargetResource $behavior = "1" $hitRate = $params.WaitTime } - else + else { $behavior = "0" $hitRate = $params.RequestLimit @@ -171,7 +171,7 @@ function Set-TargetResource -SearchService $serviceApp } } - if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { Write-Verbose -Message "Updating Crawler Impact Rule $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -185,7 +185,7 @@ function Set-TargetResource $behavior = "1" $hitRate = $params.WaitTime } - else + else { $behavior = "0" $hitRate = $params.RequestLimit @@ -237,30 +237,30 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] $ServiceAppName, - + [Parameter(Mandatory = $true)] [System.String] $Name, - + [Parameter()] [System.UInt32] $RequestLimit = 0, - + [Parameter()] [System.UInt32] $WaitTime = 0, - + [Parameter()] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [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" @@ -271,7 +271,7 @@ function Test-TargetResource { $behavior = "RequestLimit" } - else + else { $behavior = "WaitTime" } @@ -282,18 +282,18 @@ function Test-TargetResource { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("ServiceAppName", - "Name", + -ValuesToCheck @("ServiceAppName", + "Name", $behavior) } - else + else { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("ServiceAppName", - "Name", + -ValuesToCheck @("ServiceAppName", + "Name", "Ensure") - } + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/readme.md new file mode 100644 index 000000000..e193c9f7c --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/readme.md @@ -0,0 +1,8 @@ +# Description + +This resource is responsible for managing the search crawl impact 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 you omit this +parameter the crawl rule is created. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 index 068b51b97..7663a96dd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 @@ -4,62 +4,62 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $AuditingEnabled, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $AuditlogMaxSize, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $FailoverDatabaseServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $PartitionMode, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Sharing, - [Parameter()] - [ValidateSet("Windows", "SQL")] - [System.String] + [Parameter()] + [ValidateSet("Windows", "SQL")] + [System.String] $DatabaseAuthenticationType, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $DatabaseCredentials, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -69,7 +69,7 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $nullReturn = @{ Name = $params.Name ApplicationPool = $params.ApplicationPool @@ -77,20 +77,20 @@ function Get-TargetResource Ensure = "Absent" } - $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue - if ($null -eq $serviceApps) + $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue + if ($null -eq $serviceApps) { - return $nullReturn + return $nullReturn } $serviceApp = $serviceApps | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" + $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" } - if ($null -eq $serviceApp) + if ($null -eq $serviceApp) { - return $nullReturn - } - else + return $nullReturn + } + else { $serviceAppProxies = Get-SPServiceApplicationProxy -ErrorAction SilentlyContinue if ($null -ne $serviceAppProxies) @@ -98,7 +98,7 @@ function Get-TargetResource $serviceAppProxy = $serviceAppProxies | Where-Object -FilterScript { $serviceApp.IsConnected($_) } - if ($null -ne $serviceAppProxy) + if ($null -ne $serviceAppProxy) { $proxyName = $serviceAppProxy.Name } @@ -118,13 +118,13 @@ function Get-TargetResource $auditProp = $propData | Where-Object -FilterScript { $_.Name -eq "AuditEnabled" } - + $auditEnabled = $auditProp.GetValue($serviceApp) return @{ Name = $serviceApp.DisplayName ProxyName = $proxyName - AuditEnabled = $auditEnabled + AuditingEnabled = $auditEnabled ApplicationPool = $serviceApp.ApplicationPool.Name DatabaseName = $db.Name DatabaseServer = $db.NormalizedDataSource @@ -142,62 +142,62 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $AuditingEnabled, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $AuditlogMaxSize, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $FailoverDatabaseServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $PartitionMode, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Sharing, - [Parameter()] - [ValidateSet("Windows", "SQL")] - [System.String] + [Parameter()] + [ValidateSet("Windows", "SQL")] + [System.String] $DatabaseAuthenticationType, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $DatabaseCredentials, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -209,33 +209,33 @@ function Set-TargetResource if ((($params.ContainsKey("DatabaseAuthenticationType") -eq $true) -and ` ($params.ContainsKey("DatabaseCredentials") -eq $false)) -or ` (($params.ContainsKey("DatabaseCredentials") -eq $true) -and ` - ($params.ContainsKey("DatabaseAuthenticationType") -eq $false))) + ($params.ContainsKey("DatabaseAuthenticationType") -eq $false))) { throw ("Where DatabaseCredentials are specified you must also specify " + ` "DatabaseAuthenticationType to identify the type of credentials being passed") return } - if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") { Write-Verbose -Message "Creating Secure Store Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $params ` -ScriptBlock { $params = $args[0] - - if ($params.ContainsKey("Ensure")) + + if ($params.ContainsKey("Ensure")) { - $params.Remove("Ensure") | Out-Null + $params.Remove("Ensure") | Out-Null } - if ($params.ContainsKey("InstallAccount")) + if ($params.ContainsKey("InstallAccount")) { - $params.Remove("InstallAccount") | Out-Null + $params.Remove("InstallAccount") | Out-Null } - if($params.ContainsKey("DatabaseAuthenticationType")) + if($params.ContainsKey("DatabaseAuthenticationType")) { - if ($params.DatabaseAuthenticationType -eq "SQL") + if ($params.DatabaseAuthenticationType -eq "SQL") { $params.Add("DatabaseUsername", $params.DatabaseCredentials.Username) $params.Add("DatabasePassword", $params.DatabaseCredentials.Password) @@ -243,20 +243,20 @@ function Set-TargetResource $params.Remove("DatabaseAuthenticationType") } - if ($params.ContainsKey("ProxyName")) + if ($params.ContainsKey("ProxyName")) { $pName = $params.ProxyName - $params.Remove("ProxyName") | Out-Null + $params.Remove("ProxyName") | Out-Null } - if ($null -eq $pName) + if ($null -eq $pName) { $pName = "$($params.Name) Proxy" } New-SPSecureStoreServiceApplication @params | New-SPSecureStoreServiceApplicationProxy -Name $pName } - } - - if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + } + + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { if ($PSBoundParameters.ContainsKey("DatabaseServer") -and ` ($result.DatabaseServer -ne $DatabaseServer)) @@ -274,7 +274,7 @@ function Set-TargetResource } if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false ` - -and $ApplicationPool -ne $result.ApplicationPool) + -and $ApplicationPool -ne $result.ApplicationPool) { Write-Verbose -Message "Updating Secure Store Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -283,15 +283,15 @@ function Set-TargetResource $params = $args[0] $serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" + $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" } - $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool + $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool Set-SPSecureStoreServiceApplication -Identity $serviceApp -ApplicationPool $appPool } } } - - if ($Ensure -eq "Absent") + + if ($Ensure -eq "Absent") { # The service app should not exit Write-Verbose -Message "Removing Secure Store Service Application $Name" @@ -299,9 +299,9 @@ function Set-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" + $_.GetType().FullName -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication" } # Remove the connected proxy(ies) @@ -316,7 +316,7 @@ function Set-TargetResource Remove-SPServiceApplication $serviceApp -Confirm:$false } - } + } } function Test-TargetResource @@ -325,62 +325,62 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter(Mandatory = $true)] - [System.Boolean] + [Parameter(Mandatory = $true)] + [System.Boolean] $AuditingEnabled, - [Parameter()] - [System.UInt32] + [Parameter()] + [System.UInt32] $AuditlogMaxSize, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $DatabaseServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $FailoverDatabaseServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $PartitionMode, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $Sharing, - [Parameter()] - [ValidateSet("Windows", "SQL")] - [System.String] + [Parameter()] + [ValidateSet("Windows", "SQL")] + [System.String] $DatabaseAuthenticationType, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $DatabaseCredentials, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 new file mode 100644 index 000000000..206a7511e --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 @@ -0,0 +1,193 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.String] + $NameIdentifier, + + [Parameter()] + [System.Boolean] + $UseSessionCookies = $false, + + [Parameter()] + [System.Boolean] + $AllowOAuthOverHttp = $false, + + [Parameter()] + [System.Boolean] + $AllowMetadataOverHttp = $false, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Getting Security Token Service Configuration" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $config = Get-SPSecurityTokenServiceConfig + $nullReturn = @{ + Name = $params.Name + NameIdentifier = $params.NameIdentifier + UseSessionCookies = $params.UseSessionCookies + AllowOAuthOverHttp = $params.AllowOAuthOverHttp + AllowMetadataOverHttp = $params.AllowMetadataOverHttp + Ensure = "Absent" + InstallAccount = $params.InstallAccount + } + if ($null -eq $config) + { + return $nullReturn + } + + return @{ + Name = $config.Name + NameIdentifier = $config.NameIdentifier + UseSessionCookies = $config.UseSessionCookies + AllowOAuthOverHttp = $config.AllowOAuthOverHttp + AllowMetadataOverHttp = $config.AllowMetadataOverHttp + Ensure = "Present" + InstallAccount = $params.InstallAccount + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.String] + $NameIdentifier, + + [Parameter()] + [System.Boolean] + $UseSessionCookies = $false, + + [Parameter()] + [System.Boolean] + $AllowOAuthOverHttp = $false, + + [Parameter()] + [System.Boolean] + $AllowMetadataOverHttp = $false, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Setting Security Token Service Configuration" + + if($Ensure -eq "Absent") + { + throw "This resource cannot undo Security Token Service Configuration changes. ` + Please set Ensure to Present or omit the resource" + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + $config = Get-SPSecurityTokenServiceConfig + $config.Name = $params.Name + + if($params.ContainsKey("NameIdentifier")) + { + $config.NameIdentifier = $params.NameIdentifier + } + + if($params.ContainsKey("UseSessionCookies")) + { + $config.UseSessionCookies = $params.UseSessionCookies + } + + if($params.ContainsKey("AllowOAuthOverHttp")) + { + $config.AllowOAuthOverHttp = $params.AllowOAuthOverHttp + } + + if($params.ContainsKey("AllowMetadataOverHttp")) + { + $config.AllowMetadataOverHttp = $params.AllowMetadataOverHttp + } + + $config.Update() + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter()] + [System.String] + $NameIdentifier, + + [Parameter()] + [System.Boolean] + $UseSessionCookies = $false, + + [Parameter()] + [System.Boolean] + $AllowOAuthOverHttp = $false, + + [Parameter()] + [System.Boolean] + $AllowMetadataOverHttp = $false, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present" + ) + + Write-Verbose -Message "Testing the Security Token Service Configuration" + + $PSBoundParameters.Ensure = $Ensure + + $CurrentValues = Get-TargetResource @PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Ensure") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.schema.mof new file mode 100644 index 000000000..11d8bb789 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.schema.mof @@ -0,0 +1,11 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPSecurityTokenServiceConfig")] +class MSFT_SPSecurityTokenServiceConfig : OMI_BaseResource +{ + [Key, Description("The name of the security token service")] string Name; + [Write, Description("The identifier for the security token service")] string NameIdentifier; + [Write, Description("True set the security token service to use cookies")] Boolean UseSessionCookies; + [Write, Description("True set the security token service to allow OAuth over HTTP")] Boolean AllowOAuthOverHttp; + [Write, Description("True set the security token service to allow metadata exchange over HTTP")] Boolean AllowMetadataOverHttp; + [Write, Description("Present ensures the configurations are applied"), 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_SPSecurityTokenServiceConfig/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/readme.md new file mode 100644 index 000000000..abe450295 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/readme.md @@ -0,0 +1,5 @@ +# Description + +This resource is responsible for configuring the Security Token Service within +the local SharePoint farm. Using Ensure equals to Absent is not supported. +This resource can only apply configuration, not ensure they don't exist. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 index 7e5f31b91..d188b24f2 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 @@ -4,16 +4,16 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ManagedAccount ) @@ -21,26 +21,40 @@ function Get-TargetResource $result = Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] - - $serviceInstance = Get-SPServiceInstance -Server $env:computername | Where-Object { $_.TypeName -eq $params.Name } - - if ($null -eq $serviceInstance.service.processidentity) + if ($params.Name -eq "SharePoint Server Search") { - Write-Verbose "WARNING: Service $($params.name) does not support setting the process identity" + $processIdentity = (Get-SPEnterpriseSearchService).get_ProcessIdentity() } - - $ManagedAccount = $serviceInstance.service.processidentity.username - + else + { + $serviceInstance = Get-SPServiceInstance -Server $env:computername | Where-Object { + $_.TypeName -eq $params.Name + } + + if ($null -eq $serviceInstance.service.processidentity) + { + Write-Verbose "WARNING: Service $($params.name) does not support setting the process identity" + } + + $processIdentity = $serviceInstance.Service.ProcessIdentity + } + + switch ($processIdentity.CurrentIdentityType) + { + "LocalSystem" { $ManagedAccount = "LocalSystem" } + "NetworkService" { $ManagedAccount = "NetworkService" } + "LocalService" { $ManagedAccount = "LocalService" } + Default { $ManagedAccount = $processIdentity.Username } + } + return @{ Name = $params.Name ManagedAccount = $ManagedAccount - } - + } } - + return $result - } function Set-TargetResource @@ -48,16 +62,16 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ManagedAccount ) @@ -65,34 +79,52 @@ function Set-TargetResource Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] - - $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME| Where-Object { $_.TypeName -eq $params.Name } - $managedAccount = Get-SPManagedAccount $params.ManagedAccount - if ($null -eq $serviceInstance) + if ($params.Name -eq "SharePoint Server Search") { - throw [System.Exception] "Unable to locate service $($params.Name)" + $processIdentity = (Get-SPEnterpriseSearchService).get_ProcessIdentity() } - if ($null -eq $managedAccount) + else { - throw [System.Exception] "Unable to locate Managed Account $($params.ManagedAccount)" + $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME | Where-Object { + $_.TypeName -eq $params.Name + } + if ($null -eq $serviceInstance) + { + throw [System.Exception] "Unable to locate service $($params.Name)" + } + + if ($null -eq $serviceInstance.service.processidentity) + { + throw [System.Exception] "Service $($params.name) does not support setting the process identity" + } + + $processIdentity = $serviceInstance.Service.ProcessIdentity } - - if ($null -eq $serviceInstance.service.processidentity) - { - throw [System.Exception] "Service $($params.name) does not support setting the process identity" - } - - $serviceInstance.service.processIdentity.CurrentIdentityType = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser - $serviceInstance.service.processIdentity.ManagedAccount = $managedAccount - $serviceInstance.service.processIdentity.update() - $serviceInstance.service.processIdentity.deploy() - - } - - -} + if ($params.ManagedAccount -eq "LocalSystem" -or ` + $params.ManagedAccount -eq "LocalService" -or ` + $params.ManagedAccount -eq "NetworkService") + { + $processIdentity.CurrentIdentityType = $params.ManagedAccount + } + else + { + $managedAccount = Get-SPManagedAccount -Identity $params.ManagedAccount ` + -ErrorAction SilentlyContinue + if ($null -eq $managedAccount) + { + throw [System.Exception] "Unable to locate Managed Account $($params.ManagedAccount)" + } + + $processIdentity.CurrentIdentityType = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser + $processIdentity.ManagedAccount = $managedAccount + } + + $processIdentity.Update() + $processIdentity.Deploy() + } +} function Test-TargetResource { @@ -100,23 +132,22 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ManagedAccount ) - $CurrentValues = Get-TargetResource @PSBoundParameters - Write-Verbose -Message "Testing service instance '$Name' Process Identity" - - return ($CurrentValues.ManagedAccount -eq $ManagedAccount) - - + Write-Verbose -Message "Testing service instance '$Name' Process Identity" + + $CurrentValues = Get-TargetResource @PSBoundParameters + + return ($CurrentValues.ManagedAccount -eq $ManagedAccount) } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.schema.mof index 7efbd3a37..e245d3e7c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.schema.mof @@ -2,6 +2,6 @@ class MSFT_SPServiceIdentity : OMI_BaseResource { [Key, Description("The name of the service instance to manage")] string Name; - [Required, Description("The user name of a managed account that will be used to run the service") ] string ManagedAccount; + [Required, Description("The user name of a managed account, LocalService, LocalSystem or NetworkService that will be used to run the service") ] string ManagedAccount; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/readme.md index 2f2537161..a33e7ae09 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/readme.md @@ -1,6 +1,7 @@ # Description This resource is used to specify a managed account to be used to run a service instance. +You can also specify LocalService, LocalSystem or NetworkService as ManagedAccount. The name is the typename of the service as shown in the Central Admin website. This resource only needs to be run on one server in the farm, as the process identity update method will apply the settings to all instances of the service. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md index 46dc1886c..d20e07062 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md @@ -8,7 +8,8 @@ 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 +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. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTimerJobState/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPTimerJobState/readme.md index f38b0682b..f2b6c5b19 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTimerJobState/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTimerJobState/readme.md @@ -16,7 +16,8 @@ Examples are: - Monthly at 15 15:00:00 - Yearly at Jan 1 15:00:00 -NOTE: Make sure you use the typename timer job name, not the display name! Use +NOTE: +Make sure you use the typename timer job name, not the display name! Use "Get-SPTimerJob | Where-Object { $_.Title -eq "\" } | Select typename" to find the typename for each Timer Job. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 index e8eb40910..3047fc995 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 @@ -4,21 +4,21 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $Name, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $UserProfileService, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $DisplayName, [Parameter()] @@ -33,7 +33,7 @@ function Get-TargetResource "HTML", "Integer", "Person", - "String (Single Value)", + "String (Single Value)", "String (Multi Value)", "TimeZone", "Unique Identifier", @@ -41,82 +41,82 @@ function Get-TargetResource [System.string] $Type, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $Description, - [Parameter()] - [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] - [System.string] + [Parameter()] + [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] + [System.string] $PolicySetting, - [Parameter()] - [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] - [System.string] + [Parameter()] + [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] + [System.string] $PrivacySetting, [Parameter()] - [System.string] + [System.string] $MappingConnectionName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingPropertyName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingDirection, - [Parameter()] + [Parameter()] [System.uint32] $Length, - [Parameter()] - [System.uint32] + [Parameter()] + [System.uint32] $DisplayOrder, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsEventLog, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnEditor, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnViewer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsUserEditable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsAlias, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsSearchable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $UserOverridePrivacy, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermStore, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermGroup, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermSet, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -126,34 +126,34 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $upsa = Get-SPServiceApplication -Name $params.UserProfileService ` -ErrorAction SilentlyContinue $nullReturn = @{ Name = $params.Name UserProfileService = $params.UserProfileService Ensure = "Absent" - } - if ($null -eq $upsa) + } + if ($null -eq $upsa) { - return $nullReturn + return $nullReturn } $caURL = (Get-SPWebApplication -IncludeCentralAdministration | Where-Object -FilterScript { - $_.IsAdministrationWebApplication -eq $true + $_.IsAdministrationWebApplication -eq $true }).Url - $context = Get-SPServiceContext -Site $caURL - + $context = Get-SPServiceContext -Site $caURL + $userProfileSubTypeManager = Get-SPDSCUserProfileSubTypeManager -Context $context $userProfileSubType = $userProfileSubTypeManager.GetProfileSubtype("UserProfile") - - $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) + + $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) if ($null -eq $userProfileProperty) { - return $nullReturn + return $nullReturn } - + $termSet = @{ TermSet = "" TermGroup ="" @@ -174,24 +174,24 @@ function Get-TargetResource $userProfileConfigManager = New-Object -TypeName "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" ` -ArgumentList $context - + if ($null -eq $userProfileConfigManager.ConnectionManager) { - return $nullReturn + return $nullReturn } $syncConnection = $userProfileConfigManager.ConnectionManager | ` Where-Object -FilterScript { - $null -ne $_.PropertyMapping -and $null -ne $_.PropertyMapping.Item($params.Name) + $null -ne $_.PropertyMapping -and $null -ne $_.PropertyMapping.Item($params.Name) } - if($null -ne $syncConnection) + if($null -ne $syncConnection) { $currentMapping = $syncConnection.PropertyMapping.Item($params.Name) if($null -ne $currentMapping) { $mapping.Direction = "Import" - $mapping.ConnectionName = $params.MappingConnectionName + $mapping.ConnectionName = $params.MappingConnectionName if($currentMapping.IsExport) { $mapping.Direction = "Export" @@ -199,26 +199,26 @@ function Get-TargetResource $mapping.PropertyName = $currentMapping.DataSourcePropertyName } } - + return @{ - Name = $userProfileProperty.Name + Name = $userProfileProperty.Name UserProfileService = $params.UserProfileService DisplayName = $userProfileProperty.DisplayName Type = $userProfileProperty.CoreProperty.Type - Description = $userProfileProperty.Description + Description = $userProfileProperty.Description PolicySetting = $userProfileProperty.PrivacyPolicy PrivacySetting = $userProfileProperty.DefaultPrivacy MappingConnectionName = $mapping.ConnectionName MappingPropertyName = $mapping.PropertyName MappingDirection = $Mapping.Direction Length = $userProfileProperty.CoreProperty.Length - DisplayOrder =$userProfileProperty.DisplayOrder + DisplayOrder =$userProfileProperty.DisplayOrder IsEventLog =$userProfileProperty.TypeProperty.IsEventLog IsVisibleOnEditor=$userProfileProperty.TypeProperty.IsVisibleOnEditor IsVisibleOnViewer =$userProfileProperty.TypeProperty.IsVisibleOnViewer IsUserEditable = $userProfileProperty.IsUserEditable - IsAlias = $userProfileProperty.IsAlias - IsSearchable = $userProfileProperty.CoreProperty.IsSearchable + IsAlias = $userProfileProperty.IsAlias + IsSearchable = $userProfileProperty.CoreProperty.IsSearchable TermStore = $termSet.TermStore TermGroup = $termSet.TermGroup TermSet = $termSet.TermSet @@ -235,21 +235,21 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $Name, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $UserProfileService, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $DisplayName, [Parameter()] @@ -264,7 +264,7 @@ function Set-TargetResource "HTML", "Integer", "Person", - "String (Single Value)", + "String (Single Value)", "String (Multi Value)", "TimeZone", "Unique Identifier", @@ -272,87 +272,87 @@ function Set-TargetResource [System.string] $Type, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $Description, - [Parameter()] - [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] - [System.string] + [Parameter()] + [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] + [System.string] $PolicySetting, - [Parameter()] - [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] - [System.string] + [Parameter()] + [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] + [System.string] $PrivacySetting, [Parameter()] - [System.string] + [System.string] $MappingConnectionName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingPropertyName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingDirection, - [Parameter()] + [Parameter()] [System.uint32] $Length, - [Parameter()] - [System.uint32] + [Parameter()] + [System.uint32] $DisplayOrder, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsEventLog, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnEditor, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnViewer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsUserEditable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsAlias, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsSearchable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $UserOverridePrivacy, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermStore, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermGroup, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermSet, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) - # Note for integration test: CA can take a couple of minutes to notice the change. don't try - # refreshing properties page. Go through from a fresh "flow" from Service apps page + # Note for integration test: CA can take a couple of minutes to notice the change. don't try + # refreshing properties page. Go through from a fresh "flow" from Service apps page Write-Verbose -Message "Setting user profile property $Name" @@ -370,7 +370,7 @@ function Set-TargetResource -or $params.ContainsKey("TermSet") ) ` -and ($params.ContainsKey("TermSet") ` -and $params.ContainsKey("TermGroup") ` - -and $params.ContainsKey("TermSet") -eq $false) + -and $params.ContainsKey("TermSet") -eq $false) ) { throw ("You have to provide all 3 parameters Termset, TermGroup and TermStore " + ` @@ -384,17 +384,17 @@ function Set-TargetResource } $ups = Get-SPServiceApplication -Name $params.UserProfileService ` - -ErrorAction SilentlyContinue - + -ErrorAction SilentlyContinue + if ($null -eq $ups) { return $null } - + $caURL = (Get-SPWebApplication -IncludeCentralAdministration | Where-Object -FilterScript { - $_.IsAdministrationWebApplication -eq $true + $_.IsAdministrationWebApplication -eq $true }).Url - $context = Get-SPServiceContext $caURL + $context = Get-SPServiceContext $caURL $userProfileConfigManager = New-Object -TypeName "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" ` -ArgumentList $context @@ -405,12 +405,12 @@ function Set-TargetResource throw ("Account running process needs admin permissions on the user profile " + ` "service application") } - $coreProperties = $userProfileConfigManager.ProfilePropertyManager.GetCoreProperties() - + $coreProperties = $userProfileConfigManager.ProfilePropertyManager.GetCoreProperties() + $userProfileSubTypeManager = Get-SPDSCUserProfileSubTypeManager $context $userProfileSubType = $userProfileSubTypeManager.GetProfileSubtype("UserProfile") - $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) + $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) if ($null -ne $userProfileProperty ` -and $userProfileProperty.CoreProperty.Type -ne $params.Type) @@ -424,8 +424,8 @@ function Set-TargetResource if ($params.ContainsKey("TermSet")) { $currentTermSet = $userProfileProperty.CoreProperty.TermSet; - if($currentTermSet.Name -ne $params.TermSet -or - $currentTermSet.Group.Name -ne $params.TermGroup -or + if($currentTermSet.Name -ne $params.TermSet -or + $currentTermSet.Group.Name -ne $params.TermGroup -or $currentTermSet.TermStore.Name -ne $params.TermStore) { $session = New-Object -TypeName Microsoft.SharePoint.Taxonomy.TaxonomySession ` @@ -444,7 +444,7 @@ function Set-TargetResource { throw "Term Group $($params.termGroup) not found" } - + $termSet = $group.TermSets[$params.TermSet] if($null -eq $termSet) { @@ -460,7 +460,7 @@ function Set-TargetResource $coreProperties.RemovePropertyByName($params.Name) return } - } + } elseif($null -eq $userProfileProperty) { $coreProperty = $coreProperties.Create($false) @@ -470,8 +470,8 @@ function Set-TargetResource Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $coreProperty ` -PropertyToSet "Length" ` -ParamsValue $params ` - -ParamKey "Length" - + -ParamKey "Length" + if($params.Type -eq "String (Multi Value)") { $coreProperty.IsMultivalued = $true @@ -480,7 +480,7 @@ function Set-TargetResource $coreProperty.Type = $params.Type if($null -ne $termSet) { - $coreProperty.TermSet = $termSet + $coreProperty.TermSet = $termSet } $userProfilePropertyManager = $userProfileConfigManager.ProfilePropertyManager @@ -488,12 +488,12 @@ function Set-TargetResource $userProfileSubTypeProperties = $userProfileSubType.Properties $CoreProperties.Add($coreProperty) - $upTypeProperty = $userProfileTypeProperties.Create($coreProperty) + $upTypeProperty = $userProfileTypeProperties.Create($coreProperty) $userProfileTypeProperties.Add($upTypeProperty) $upSubProperty = $userProfileSubTypeProperties.Create($UPTypeProperty) - $userProfileSubTypeProperties.Add($upSubProperty) + $userProfileSubTypeProperties.Add($upSubProperty) Start-Sleep -Milliseconds 100 - $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) + $userProfileProperty = $userProfileSubType.Properties.GetPropertyByName($params.Name) } @@ -547,8 +547,8 @@ function Set-TargetResource Set-SPDscObjectPropertyIfValuePresent -ObjectToSet $userProfileProperty ` -PropertyToSet "UserOverridePrivacy" ` -ParamsValue $params ` - -ParamKey "UserOverridePrivacy" - if ($null -ne $termSet) + -ParamKey "UserOverridePrivacy" + if ($termSet) { $coreProperty.TermSet = $termSet } @@ -556,7 +556,7 @@ function Set-TargetResource $userProfileProperty.CoreProperty.Commit() $userProfileTypeProperty.Commit() $userProfileProperty.Commit() - + if ($params.ContainsKey("DisplayOrder")) { $profileManager = New-Object -TypeName "Microsoft.Office.Server.UserProfiles.UserProfileManager" ` @@ -564,29 +564,32 @@ function Set-TargetResource $profileManager.Properties.SetDisplayOrderByPropertyName($params.Name, $params.DisplayOrder) $profileManager.Properties.CommitDisplayOrder() } - + if ($params.ContainsKey("MappingConnectionName") ` - -and $params.ContainsKey("MappingPropertyName")) + -and $params.ContainsKey("MappingPropertyName")) { $syncConnection = $userProfileConfigManager.ConnectionManager | Where-Object -FilterScript { $_.DisplayName -eq $params.MappingConnectionName - } - - if ($null -eq $syncConnection ) + } + + if ($null -eq $syncConnection ) { throw "connection not found" } $syncConnection = $userProfileConfigManager.ConnectionManager | Where-Object -FilterScript { $_.DisplayName -eq $params.MappingConnectionName - } - - $currentMapping = $syncConnection.PropertyMapping.Item($params.Name) + } + + if($null -ne $syncConnection.PropertyMapping) + { + $currentMapping = $syncConnection.PropertyMapping.Item($params.Name) + } if($null -eq $currentMapping ` -or ($currentMapping.DataSourcePropertyName -ne $params.MappingPropertyName) ` -or ($currentMapping.IsImport ` -and $params.ContainsKey("MappingDirection") ` - -and $params.MappingDirection -eq "Export") + -and $params.MappingDirection -eq "Export") ) { if ($null -ne $currentMapping) @@ -595,18 +598,18 @@ function Set-TargetResource } $export = $params.ContainsKey("MappingDirection") -and $params.MappingDirection -eq "Export" - if ($syncConnection.Type -eq "ActiveDirectoryImport") + if ($syncConnection.Type -eq "ActiveDirectoryImport") { - if ($export) + if ($export) { throw "not implemented" - } - else + } + else { - $syncConnection.AddPropertyMapping($params.MappingPropertyName,$params.Name) - $syncConnection.Update() + $syncConnection.AddPropertyMapping($params.MappingPropertyName,$params.Name) + $syncConnection.Update() } - } + } else { if ($export) @@ -622,7 +625,7 @@ function Set-TargetResource $params.MappingPropertyName) } } - } + } } } } @@ -633,21 +636,21 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $Name, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter(Mandatory = $true)] - [System.string] + [Parameter(Mandatory = $true)] + [System.string] $UserProfileService, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $DisplayName, [Parameter()] @@ -662,7 +665,7 @@ function Test-TargetResource "HTML", "Integer", "Person", - "String (Single Value)", + "String (Single Value)", "String (Multi Value)", "TimeZone", "Unique Identifier", @@ -670,82 +673,82 @@ function Test-TargetResource [System.string] $Type, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $Description, - [Parameter()] - [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] - [System.string] + [Parameter()] + [ValidateSet("Mandatory", "Optin","Optout", "Disabled")] + [System.string] $PolicySetting, - [Parameter()] - [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] - [System.string] + [Parameter()] + [ValidateSet("Public", "Contacts", "Organization", "Manager", "Private")] + [System.string] $PrivacySetting, [Parameter()] - [System.string] + [System.string] $MappingConnectionName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingPropertyName, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $MappingDirection, - [Parameter()] + [Parameter()] [System.uint32] $Length, - [Parameter()] - [System.uint32] + [Parameter()] + [System.uint32] $DisplayOrder, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsEventLog, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnEditor, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsVisibleOnViewer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsUserEditable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsAlias, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $IsSearchable, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $UserOverridePrivacy, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermStore, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermGroup, - [Parameter()] - [System.string] + [Parameter()] + [System.string] $TermSet, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -756,39 +759,39 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters - if ($Ensure -eq "Present") + if ($Ensure -eq "Present") { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Name", "DisplayName", - "Type", - "Description", - "PolicySetting", + "Type", + "Description", + "PolicySetting", "PrivacySetting", "MappingConnectionName", - "MappingPropertyName", - "MappingDirection", - "Length", - "DisplayOrder", - "IsEventLog", - "IsVisibleOnEditor", + "MappingPropertyName", + "MappingDirection", + "Length", + "DisplayOrder", + "IsEventLog", + "IsVisibleOnEditor", "IsVisibleOnViewer", - "IsUserEditable", - "IsAlias", - "IsSearchabe", - "UserOverridePrivacy", - "TermGroup", - "TermStore", - "TermSet", + "IsUserEditable", + "IsAlias", + "IsSearchabe", + "UserOverridePrivacy", + "TermGroup", + "TermStore", + "TermSet", "Ensure") - } - else + } + else { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Ensure") - } + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index d6a56d569..aa6bfb873 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -4,75 +4,75 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $MySiteHostLocation, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $EnableNetBIOS = $false, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $NoILMUsed = $false, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) - + Write-Verbose -Message "Getting user profile service application $Name" $farmAccount = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { - return Get-SPDSCFarmAccountName + return Get-SPDSCFarmAccountName } if ($null -ne $farmAccount) { - if ($PSBoundParameters.ContainsKey("InstallAccount") -eq $true) + if ($PSBoundParameters.ContainsKey("InstallAccount") -eq $true) { # InstallAccount used if ($InstallAccount.UserName -ne $farmAccount) @@ -106,18 +106,18 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue $nullReturn = @{ Name = $params.Name Ensure = "Absent" - } - if ($null -eq $serviceApps) + } + if ($null -eq $serviceApps) { - return $nullReturn + return $nullReturn } $serviceApp = $serviceApps | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.Server.Administration.UserProfileApplication" + $_.GetType().FullName -eq "Microsoft.Office.Server.Administration.UserProfileApplication" } if ($null -eq $serviceApp) @@ -135,7 +135,7 @@ function Get-TargetResource $socialProp = $propData | Where-Object -FilterScript { $_.Name -eq "SocialDatabase" } - $databases.Add("SocialDatabase", $socialProp.GetValue($serviceApp)) + $databases.Add("SocialDatabase", $socialProp.GetValue($serviceApp)) $profileProp = $propData | Where-Object -FilterScript { $_.Name -eq "ProfileDatabase" @@ -153,7 +153,7 @@ function Get-TargetResource $serviceAppProxy = $serviceAppProxies | Where-Object -FilterScript { $serviceApp.IsConnected($_) } - if ($null -ne $serviceAppProxy) + if ($null -ne $serviceAppProxy) { $proxyName = $serviceAppProxy.Name } @@ -184,67 +184,67 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $MySiteHostLocation, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $EnableNetBIOS = $false, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $NoILMUsed = $false, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting user profile service application $Name" - if ($Ensure -eq "Present") + if ($Ensure -eq "Present") { $farmAccount = Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` @@ -254,7 +254,7 @@ function Set-TargetResource if ($null -ne $farmAccount) { - if ($PSBoundParameters.ContainsKey("InstallAccount") -eq $true) + if ($PSBoundParameters.ContainsKey("InstallAccount") -eq $true) { # InstallAccount used if ($InstallAccount.UserName -ne $farmAccount) @@ -281,9 +281,9 @@ function Set-TargetResource { throw ("Unable to retrieve the Farm Account. Check if the farm exists.") } - + Write-Verbose -Message "Creating user profile service application $Name" - + # Add the InstallAccount to the local Administrators group, if it's not already there $isLocalAdmin = Test-SPDSCUserIsLocalAdmin -UserName $farmAccount @@ -299,30 +299,30 @@ function Set-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $updateEnableNetBIOS = $false - if ($params.ContainsKey("EnableNetBIOS")) + if ($params.ContainsKey("EnableNetBIOS")) { $updateEnableNetBIOS = $true $enableNetBIOS = $params.EnableNetBIOS - $params.Remove("EnableNetBIOS") | Out-Null + $params.Remove("EnableNetBIOS") | Out-Null } $updateNoILMUsed = $false - if ($params.ContainsKey("NoILMUsed")) + if ($params.ContainsKey("NoILMUsed")) { $updateNoILMUsed = $true $NoILMUsed = $params.NoILMUsed - $params.Remove("NoILMUsed") | Out-Null + $params.Remove("NoILMUsed") | Out-Null } - if ($params.ContainsKey("InstallAccount")) + if ($params.ContainsKey("InstallAccount")) { - $params.Remove("InstallAccount") | Out-Null + $params.Remove("InstallAccount") | Out-Null } - if ($params.ContainsKey("Ensure")) + if ($params.ContainsKey("Ensure")) { - $params.Remove("Ensure") | Out-Null + $params.Remove("Ensure") | Out-Null } $params = Rename-SPDSCParamValue -params $params ` @@ -333,23 +333,23 @@ function Set-TargetResource -oldName "SyncDBServer" ` -newName "ProfileSyncDBServer" - if ($params.ContainsKey("ProxyName")) + if ($params.ContainsKey("ProxyName")) { $pName = $params.ProxyName - $params.Remove("ProxyName") | Out-Null + $params.Remove("ProxyName") | Out-Null } - if ($null -eq $pName) + if ($null -eq $pName) { $pName = "$($params.Name) Proxy" } $serviceApps = Get-SPServiceApplication -Name $params.Name ` - -ErrorAction SilentlyContinue + -ErrorAction SilentlyContinue $app = $serviceApps | Select-Object -First 1 - if ($null -eq $serviceApps) + if ($null -eq $serviceApps) { $app = New-SPProfileServiceApplication @params - if ($null -ne $app) + if ($null -ne $app) { New-SPProfileServiceApplicationProxy -Name $pName ` -ServiceApplication $app ` @@ -369,7 +369,7 @@ function Set-TargetResource ($app.NoILMUsed -ne $NoILMUsed)) { $app.NoILMUsed = $NoILMUsed - } + } $app.Update() } } @@ -380,8 +380,8 @@ function Set-TargetResource Remove-SPDSCUserToLocalAdmin -UserName $farmAccount } } - - if ($Ensure -eq "Absent") + + if ($Ensure -eq "Absent") { Write-Verbose -Message "Removing user profile service application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -389,10 +389,10 @@ function Set-TargetResource -ScriptBlock { $params = $args[0] - + $app = Get-SPServiceApplication -Name $params.Name ` | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.Server.Administration.UserProfileApplication" + $_.GetType().FullName -eq "Microsoft.Office.Server.Administration.UserProfileApplication" } $proxies = Get-SPServiceApplicationProxy @@ -406,7 +406,7 @@ function Set-TargetResource Remove-SPServiceApplication -Identity $app -Confirm:$false } - } + } } function Test-TargetResource @@ -415,61 +415,61 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ApplicationPool, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $MySiteHostLocation, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ProfileDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SocialDBServer, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBName, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $SyncDBServer, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $EnableNetBIOS = $false, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $NoILMUsed = $false, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -485,7 +485,7 @@ function Test-TargetResource -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Name", "EnableNetBIOS", - "NoILMUsed", + "NoILMUsed", "Ensure") } else diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 index df3722576..dca5b9d6e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 @@ -4,24 +4,24 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $CreatePersonalSite, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $FollowAndEditProfile, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $UseTagsAndNotes, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -33,7 +33,7 @@ function Get-TargetResource $params = $args[0] $proxy = Get-SPServiceApplicationProxy | Where-Object { $_.DisplayName -eq $params.ProxyName } - if ($null -eq $proxy) + if ($null -eq $proxy) { return @{ ProxyName = $params.ProxyName @@ -49,54 +49,54 @@ function Get-TargetResource $followAndEditProfile = @() $useTagsAndNotes = @() - foreach ($securityEntry in $security.AccessRules) + foreach ($securityEntry in $security.AccessRules) { $user = $securityEntry.Name - if ($user -like "i:*|*" -or $user -like "c:*|*") + if ($user -like "i:*|*" -or $user -like "c:*|*") { # Only claims users can be processed by the PowerShell cmdlets, so only # report on and manage the claims identities - if ($user -eq "c:0(.s|true") + if ($user -eq "c:0(.s|true") { $user = "Everyone" - } - else + } + else { - $user = (New-SPClaimsPrincipal -Identity $user -IdentityType EncodedClaim).Value + $user = (New-SPClaimsPrincipal -Identity $user -IdentityType EncodedClaim).Value } } - if ($securityEntry.AllowedRights.ToString() -eq "All") + if ($securityEntry.AllowedRights.ToString() -eq "All") { $createPersonalSite += $user $followAndEditProfile += $user $useTagsAndNotes += $user } - if ($securityEntry.AllowedRights.ToString() -like "*UsePersonalFeatures*") + if ($securityEntry.AllowedRights.ToString() -like "*UsePersonalFeatures*") { $followAndEditProfile += $user } - if ($securityEntry.AllowedRights.ToString() -like "*UseSocialFeatures*") + if ($securityEntry.AllowedRights.ToString() -like "*UseSocialFeatures*") { $useTagsAndNotes += $user } if (($securityEntry.AllowedRights.ToString() -like "*CreatePersonalSite*") ` - -and ($securityEntry.AllowedRights.ToString() -like "*UseMicrobloggingAndFollowing*")) + -and ($securityEntry.AllowedRights.ToString() -like "*UseMicrobloggingAndFollowing*")) { $createPersonalSite += $user } } - if ($createPersonalSite.Length -eq 0) + if (!$createPersonalSite) { - $createPersonalSite += "None" + $createPersonalSite += "None" } - if ($followAndEditProfile.Length -eq 0) + if (!$followAndEditProfile) { - $followAndEditProfile += "None" + $followAndEditProfile += "None" } - if ($useTagsAndNotes.Length -eq 0) + if (!$useTagsAndNotes) { - $useTagsAndNotes += "None" + $useTagsAndNotes += "None" } return @{ @@ -115,24 +115,24 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $CreatePersonalSite, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $FollowAndEditProfile, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $UseTagsAndNotes, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -144,7 +144,7 @@ function Set-TargetResource if ($CurrentValues.CreatePersonalSite -contains "NT AUTHORITY\Authenticated Users" ` -or $CurrentValues.FollowAndEditProfile -contains "NT AUTHORITY\Authenticated Users" ` - -or $CurrentValues.UseTagsAndNotes -contains "NT AUTHORITY\Authenticated Users") + -or $CurrentValues.UseTagsAndNotes -contains "NT AUTHORITY\Authenticated Users") { Write-Warning -Message ("Permissions were found for the non-claims identity " + ` "'NT AUTHORITY\Authenticated Users'. This will be removed as " + ` @@ -171,7 +171,7 @@ function Set-TargetResource $CurrentValues = $args[1] $proxy = Get-SPServiceApplicationProxy | Where-Object { $_.DisplayName -eq $params.ProxyName } - if ($null -eq $proxy) + if ($null -eq $proxy) { throw "Unable to find service application proxy called '$($params.ProxyName)'" return @@ -184,28 +184,28 @@ function Set-TargetResource "UseTagsAndNotes" = "Use Social Features" } - foreach ($permission in $permissionsToUpdate.Keys) + foreach ($permission in $permissionsToUpdate.Keys) { $permissionsDiff = Compare-Object -ReferenceObject $CurrentValues.$permission ` -DifferenceObject $params.$permission - + $everyoneDiff = $permissionsDiff | Where-Object -FilterScript { $_.InputObject -eq "Everyone" } $noneDiff = $permissionsDiff | Where-Object -FilterScript { $_.InputObject -eq "None" } - if (($null -ne $noneDiff) -and ($noneDiff.SideIndicator -eq "=>")) + if (($null -ne $noneDiff) -and ($noneDiff.SideIndicator -eq "=>")) { # Need to remove everyone foreach($user in $CurrentValues.$permission) { - if ($user -ne "Everyone" -and $user -ne "None") + if ($user -ne "Everyone" -and $user -ne "None" -and $user) { $isUser = Test-SPDSCIsADUser -IdentityName $user - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $user ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $user ` -IdentityType WindowsSecurityGroupName @@ -213,8 +213,8 @@ function Set-TargetResource Revoke-SPObjectSecurity -Identity $security ` -Principal $claim ` -Rights $permissionsToUpdate.$permission - } - elseif ($user -eq "Everyone") + } + elseif ($user -eq "Everyone") { # Revoke the all user permissions $allClaimsUsersClaim = New-SPClaimsPrincipal -Identity "c:0(.s|true" ` @@ -225,21 +225,21 @@ function Set-TargetResource } } } - elseif (($null -ne $everyoneDiff) -and ($everyoneDiff.SideIndicator -eq "=>")) + elseif (($null -ne $everyoneDiff) -and ($everyoneDiff.SideIndicator -eq "=>")) { # Need to add everyone, so remove all the permissions that exist currently of this type # and then add the everyone permissions foreach($user in $CurrentValues.$permission) { - if ($user -ne "Everyone" -and $user -ne "None") + if ($user -ne "Everyone" -and $user -ne "None" -and $user) { $isUser = Test-SPDSCIsADUser -IdentityName $user if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $user ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $user ` -IdentityType WindowsSecurityGroupName @@ -255,22 +255,22 @@ function Set-TargetResource Grant-SPObjectSecurity -Identity $security ` -Principal $allClaimsUsersClaim ` -Rights $permissionsToUpdate.$permission - } - else + } + else { # permission changes aren't to everyone or none, process each change - foreach ($permissionChange in $permissionsDiff) + foreach ($permissionChange in $permissionsDiff) { if ($permissionChange.InputObject -ne "Everyone" -and ` - $permissionChange.InputObject -ne "None") + $permissionChange.InputObject -ne "None") { $isUser = Test-SPDSCIsADUser -IdentityName $permissionChange.InputObject - if ($isUser -eq $true) + if ($isUser -eq $true) { $claim = New-SPClaimsPrincipal -Identity $permissionChange.InputObject ` - -IdentityType WindowsSamAccountName - } - else + -IdentityType WindowsSamAccountName + } + else { $claim = New-SPClaimsPrincipal -Identity $permissionChange.InputObject ` -IdentityType WindowsSecurityGroupName @@ -306,24 +306,24 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $ProxyName, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $CreatePersonalSite, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $FollowAndEditProfile, - [Parameter(Mandatory = $true)] - [System.String[]] + [Parameter()] + [System.String[]] $UseTagsAndNotes, - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -355,7 +355,7 @@ function Confirm-SPDscUpaPermissionsConfig() "FollowAndEditProfile", "UseTagsAndNotes" ) | ForEach-Object -Process { - if (($Parameters.$_ -contains "Everyone") -and ($Parameters.$_ -contains "None")) + if (($Parameters.$_ -contains "Everyone") -and ($Parameters.$_ -contains "None")) { throw ("You can not specify 'Everyone' and 'None' in the same property. " + ` "Check the value for the '$_' property on this resource.") diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.schema.mof index 499f6862f..6fdd05ad8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.schema.mof @@ -2,8 +2,8 @@ class MSFT_SPUserProfileServiceAppPermissions : OMI_BaseResource { [Key, Description("The name of the proxy that is attached to the user profile service you wish to set permissions for")] string ProxyName; - [Required, Description("A list of user principals that will have the Create personal site permission")] string CreatePersonalSite[]; - [Required, Description("A list of user principals that will have the Follow users and edit profile permission")] string FollowAndEditProfile[]; - [Required, Description("A list of user principals that will have the Use tags and notes permission")] string UseTagsAndNotes[]; + [Write, Description("A list of user principals that will have the Create personal site permission")] string CreatePersonalSite[]; + [Write, Description("A list of user principals that will have the Follow users and edit profile permission")] string FollowAndEditProfile[]; + [Write, Description("A list of user principals that will have the Use tags and notes permission")] string UseTagsAndNotes[]; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 index 3bf5573ba..f9d6b0ee9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 @@ -324,9 +324,18 @@ function Set-TargetResource } 16 { - Add-SPProfileSyncConnection -ProfileServiceApplication $ups -ConnectionForestName $params.Forest -ConnectionDomain $userDomain ` - -ConnectionUserName $userName -ConnectionPassword $params.ConnectionCredentials.Password -ConnectionUseSSL $params.UseSSL ` - -ConnectionSynchronizationOU $params.IncludedOUs.ToString() + foreach($ou in $params.IncludedOUs) + { + Add-SPProfileSyncConnection -ProfileServiceApplication $ups -ConnectionForestName $params.Forest -ConnectionDomain $userDomain ` + -ConnectionUserName $userName -ConnectionPassword $params.ConnectionCredentials.Password -ConnectionUseSSL $params.UseSSL ` + -ConnectionSynchronizationOU $ou + } + + foreach($ou in $params.ExcludedOUs) + { + Remove-SPProfilesyncConnection -ProfileServiceApplication $ups -ConnectionForestName $params.Forest -ConnectionDomain $userDomain ` + -ConnectionUserName $userName -ConnectionPassword $params.ConnectionCredentials.Password -ConnectionSynchronizationOU $ou + } } } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 index 08b0d7c94..110f6d86d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 @@ -129,6 +129,7 @@ function Get-TargetResource return @{ UserProfileServiceAppName = $upa.Name Ensure = $localEnsure + FarmAccount = $params.FarmAccount RunOnlyWhenWriteable = $params.RunOnlyWhenWriteable InstallAccount = $params.InstallAccount } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 index 06621ddb7..012f92559 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 @@ -578,7 +578,7 @@ function Test-Parameter() $prop = $zoneConfig.CimInstanceProperties | Where-Object -FilterScript { $_.Name -eq "AuthenticationProvider" } - if ($null -ne $prop) + if ($null -ne $prop.Value) { $authProviderUsed = $true } @@ -587,7 +587,7 @@ function Test-Parameter() $prop = $zoneConfig.CimInstanceProperties | Where-Object -FilterScript { $_.Name -eq "MembershipProvider" } - if ($null -ne $prop) + if ($null -ne $prop.Value) { $membProviderUsed = $true } @@ -596,7 +596,7 @@ function Test-Parameter() $prop = $zoneConfig.CimInstanceProperties | Where-Object -FilterScript { $_.Name -eq "RoleProvider" } - if ($null -ne $prop) + if ($null -ne $prop.Value) { $roleProviderUsed = $true } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/readme.md index 940a9106e..cf2745036 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/readme.md @@ -5,9 +5,11 @@ application within the local SharePoint farm. The resource is able to configure the five available zones (if they exist) separately and each zone can have multiple authentication methods configured. -NOTE: This resource cannot be used to convert a Classic web application +NOTE: +This resource cannot be used to convert a Classic web application to Claims mode. You have to run Convert-SPWebApplication manually for that. -NOTE 2: Updating the configuration can take a long time, up to five minutes. +NOTE 2: +Updating the configuration can take a long time, up to five minutes. The Set-SPWebApplication cmdlet sometimes requires several minutes to complete its action. This is not a SharePointDsc issue. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md index 709d6fecd..eb0ffd693 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplication/readme.md @@ -8,7 +8,8 @@ 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 +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. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 index e34a72ed1..bf4e448c1 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 @@ -4,37 +4,37 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $WebAppUrl, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, [Parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] - [System.String] + [System.String] $Zone, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $AllowAnonymous, [Parameter()] - [System.String] + [System.String] $HostHeader, [Parameter()] - [System.String] + [System.String] $Path, [Parameter()] - [System.String] + [System.String] $Port, [Parameter()] @@ -47,7 +47,7 @@ function Get-TargetResource $Ensure = "Present", [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -57,19 +57,20 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $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 + Url = $null + Zone = $null + AllowAnonymous = $null Ensure = "Absent" - } + } } $zone = [Microsoft.SharePoint.Administration.SPUrlZone]::$($params.Zone) @@ -81,24 +82,25 @@ function Get-TargetResource WebAppUrl = $params.WebAppUrl Name = $params.Name Url = $params.Url - Zone = $params.zone + Zone = $params.zone + AllowAnonymous = $params.AllowAnonymous Ensure = "Absent" - } + } } $publicUrl = (Get-SPAlternateURL -WebApplication $params.WebAppUrl -Zone $params.zone).PublicUrl - - if ($null -ne $waExt.SecureBindings.HostHeader) #default to SSL bindings if present + + if ($null -ne $waExt.SecureBindings.HostHeader) #default to SSL bindings if present { $HostHeader = $waExt.SecureBindings.HostHeader $Port = $waExt.SecureBindings.Port - $UseSSL = $true + $UseSSL = $true } - else + else { $HostHeader = $waExt.ServerBindings.HostHeader $Port = $waExt.ServerBindings.Port - $UseSSL = $false + $UseSSL = $false } return @{ @@ -106,7 +108,7 @@ function Get-TargetResource Name = $waExt.ServerComment Url = $PublicURL AllowAnonymous = $waExt.AllowAnonymous - HostHeader = $HostHeader + HostHeader = $HostHeader Path = $waExt.Path Port = $Port Zone = $params.zone @@ -124,37 +126,37 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $WebAppUrl, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, [Parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] - [System.String] + [System.String] $Zone, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $AllowAnonymous, [Parameter()] - [System.String] + [System.String] $HostHeader, [Parameter()] - [System.String] + [System.String] $Path, [Parameter()] - [System.String] + [System.String] $Port, [Parameter()] @@ -167,13 +169,13 @@ function Set-TargetResource $Ensure = "Present", [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting web application extension '$Name' config" - - if ($Ensure -eq "Present") + + if ($Ensure -eq "Present") { Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` @@ -181,7 +183,7 @@ function Set-TargetResource $params = $args[0] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue - if ($null -eq $wa) + if ($null -eq $wa) { throw "Web Application with URL $($params.WebAppUrl) does not exist" } @@ -190,40 +192,40 @@ function Set-TargetResource $zone = [Microsoft.SharePoint.Administration.SPUrlZone]::$($params.Zone) $waExt = $wa.IisSettings[$zone] - if ($null -eq $waExt) + if ($null -eq $waExt) { $newWebAppExtParams = @{ Name = $params.Name Url = $params.Url - Zone = $params.zone + Zone = $params.zone } - + if ($params.ContainsKey("AllowAnonymous") -eq $true) { - $newWebAppExtParams.Add("AllowAnonymousAccess", $params.AllowAnonymous) + $newWebAppExtParams.Add("AllowAnonymousAccess", $params.AllowAnonymous) } if ($params.ContainsKey("HostHeader") -eq $true) { - $newWebAppExtParams.Add("HostHeader", $params.HostHeader) + $newWebAppExtParams.Add("HostHeader", $params.HostHeader) } if ($params.ContainsKey("Path") -eq $true) { - $newWebAppExtParams.Add("Path", $params.Path) + $newWebAppExtParams.Add("Path", $params.Path) } if ($params.ContainsKey("Port") -eq $true) { - $newWebAppExtParams.Add("Port", $params.Port) - } + $newWebAppExtParams.Add("Port", $params.Port) + } if ($params.ContainsKey("UseSSL") -eq $true) { - $newWebAppExtParams.Add("SecureSocketsLayer", $params.UseSSL) - } - + $newWebAppExtParams.Add("SecureSocketsLayer", $params.UseSSL) + } + $wa | New-SPWebApplicationExtension @newWebAppExtParams | Out-Null } - else + else { - if ($params.ContainsKey("AllowAnonymous") -eq $true) + if ($params.ContainsKey("AllowAnonymous") -eq $true) { $waExt.AllowAnonymous = $params.AllowAnonymous $wa.update() @@ -231,8 +233,8 @@ function Set-TargetResource } } } - - if ($Ensure -eq "Absent") + + if ($Ensure -eq "Absent") { Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` @@ -240,11 +242,11 @@ function Set-TargetResource $params = $args[0] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue - if ($null -eq $wa) + if ($null -eq $wa) { throw "Web Application with URL $($params.WebAppUrl) does not exist" } - if ($null -ne $wa) + if ($null -ne $wa) { $wa | Remove-SPWebApplication -Zone $params.zone -Confirm:$false -DeleteIISSite } @@ -259,37 +261,37 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $WebAppUrl, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Url, [Parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Internet","Extranet","Custom")] - [System.String] + [System.String] $Zone, - [Parameter()] - [System.Boolean] + [Parameter()] + [System.Boolean] $AllowAnonymous, [Parameter()] - [System.String] + [System.String] $HostHeader, [Parameter()] - [System.String] + [System.String] $Path, [Parameter()] - [System.String] + [System.String] $Port, [Parameter()] @@ -302,7 +304,7 @@ function Test-TargetResource $Ensure = "Present", [Parameter()] - [System.Management.Automation.PSCredential] + [System.Management.Automation.PSCredential] $InstallAccount ) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 index 7133cd75b..747629408 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 @@ -7,35 +7,35 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] $Name, - + [Parameter()] [System.String] $ProxyName, - + [Parameter()] [System.String] $ApplicationPool, - + [Parameter()] [System.UInt32] - $MinimumTimeBetweenEwsSyncSubscriptionSearches, - + $MinimumTimeBetweenEwsSyncSubscriptionSearches, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenProviderRefreshes, - + $MinimumTimeBetweenProviderRefreshes, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenSearchQueries, - + $MinimumTimeBetweenSearchQueries, + [Parameter()] [System.UInt32] - $NumberOfSubscriptionSyncsPerEwsSyncRun, - + $NumberOfSubscriptionSyncsPerEwsSyncRun, + [Parameter()] [System.UInt32] - $NumberOfUsersEwsSyncWillProcessAtOnce, - + $NumberOfUsersEwsSyncWillProcessAtOnce, + [Parameter()] [System.UInt32] $NumberOfUsersPerEwsSyncBatch, @@ -44,7 +44,7 @@ function Get-TargetResource [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -52,22 +52,30 @@ function Get-TargetResource Write-Verbose -Message "Getting Work management service app '$Name'" + $installedVersion = Get-SPDSCInstalledProductVersion + if ($installedVersion.FileMajorPart -eq 16) + { + throw [Exception] ("Work Management Service Application is no longer available " + ` + "in SharePoint 2016: " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + } + $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 + return $nullReturn } $serviceApp = $serviceApps | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" @@ -95,9 +103,9 @@ function Get-TargetResource Name = $serviceApp.DisplayName ProxyName = $proxyName ApplicationPool = $serviceApp.ApplicationPool.Name - MinimumTimeBetweenEwsSyncSubscriptionSearches = $serviceApp.AdminSettings.MinimumTimeBetweenEwsSyncSubscriptionSearches.TotalMinutes - MinimumTimeBetweenProviderRefreshes = $serviceApp.AdminSettings.MinimumTimeBetweenProviderRefreshes.TotalMinutes - MinimumTimeBetweenSearchQueries = $serviceApp.AdminSettings.MinimumTimeBetweenProviderRefreshes.TotalMinutes + MinimumTimeBetweenEwsSyncSubscriptionSearches = $serviceApp.AdminSettings.MinimumTimeBetweenEwsSyncSubscriptionSearches.TotalMinutes + MinimumTimeBetweenProviderRefreshes = $serviceApp.AdminSettings.MinimumTimeBetweenProviderRefreshes.TotalMinutes + MinimumTimeBetweenSearchQueries = $serviceApp.AdminSettings.MinimumTimeBetweenProviderRefreshes.TotalMinutes NumberOfSubscriptionSyncsPerEwsSyncRun = $serviceApp.AdminSettings.NumberOfSubscriptionSyncsPerEwsSyncRun NumberOfUsersEwsSyncWillProcessAtOnce = $serviceApp.AdminSettings.NumberOfUsersEwsSyncWillProcessAtOnce NumberOfUsersPerEwsSyncBatch = $serviceApp.AdminSettings.NumberOfUsersPerEwsSyncBatch @@ -116,35 +124,35 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] $Name, - + [Parameter()] [System.String] $ProxyName, - + [Parameter()] [System.String] $ApplicationPool, - + [Parameter()] [System.UInt32] - $MinimumTimeBetweenEwsSyncSubscriptionSearches, - + $MinimumTimeBetweenEwsSyncSubscriptionSearches, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenProviderRefreshes, - + $MinimumTimeBetweenProviderRefreshes, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenSearchQueries, - + $MinimumTimeBetweenSearchQueries, + [Parameter()] [System.UInt32] - $NumberOfSubscriptionSyncsPerEwsSyncRun, - + $NumberOfSubscriptionSyncsPerEwsSyncRun, + [Parameter()] [System.UInt32] - $NumberOfUsersEwsSyncWillProcessAtOnce, - + $NumberOfUsersEwsSyncWillProcessAtOnce, + [Parameter()] [System.UInt32] $NumberOfUsersPerEwsSyncBatch, @@ -153,7 +161,7 @@ function Set-TargetResource [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -162,6 +170,14 @@ function Set-TargetResource Write-Verbose -Message "Setting Work management service app '$Name'" $PSBoundParameters.Ensure = $Ensure + $installedVersion = Get-SPDSCInstalledProductVersion + if ($installedVersion.FileMajorPart -eq 16) + { + throw [Exception] ("Work Management Service Application is no longer available " + ` + "in SharePoint 2016: " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + } + if ($Ensure -ne "Absent" -and $PSBoundParameters.ContainsKey("ApplicationPool") -eq $false) { throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" @@ -169,7 +185,7 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters - if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") { Write-Verbose -Message "Creating work management Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -178,23 +194,23 @@ function Set-TargetResource $params = $args[0] if ($params.ContainsKey("Ensure")) { - $params.Remove("Ensure") | Out-Null + $params.Remove("Ensure") | Out-Null } if ($params.ContainsKey("InstallAccount")) { - $params.Remove("InstallAccount") | Out-Null + $params.Remove("InstallAccount") | Out-Null } if ($params.ContainsKey("ProxyName")) { $pName = $params.ProxyName - $params.Remove("ProxyName") | Out-Null + $params.Remove("ProxyName") | Out-Null } if ($null -eq $pName) { $pName = "$($params.Name) Proxy" } - $app = New-SPWorkManagementServiceApplication @params + $app = New-SPWorkManagementServiceApplication @params if ($null -ne $app) { New-SPWorkManagementServiceApplicationProxy -Name $pName ` @@ -205,17 +221,17 @@ function Set-TargetResource } } - if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") + if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false ` - -and $ApplicationPool -ne $result.ApplicationPool) + -and $ApplicationPool -ne $result.ApplicationPool) { Write-Verbose -Message "Updating Application Pool of Work Management Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" } @@ -229,41 +245,41 @@ function Set-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $setParams = @{} if ($params.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) { - $setParams.Add("MinimumTimeBetweenEwsSyncSubscriptionSearches", - $params.MinimumTimeBetweenEwsSyncSubscriptionSearches) + $setParams.Add("MinimumTimeBetweenEwsSyncSubscriptionSearches", + $params.MinimumTimeBetweenEwsSyncSubscriptionSearches) } if ($params.ContainsKey("MinimumTimeBetweenProviderRefreshes")) { - $setParams.Add("MinimumTimeBetweenProviderRefreshes", - $params.MinimumTimeBetweenProviderRefreshes) + $setParams.Add("MinimumTimeBetweenProviderRefreshes", + $params.MinimumTimeBetweenProviderRefreshes) } if ($params.ContainsKey("MinimumTimeBetweenSearchQueries")) { - $setParams.Add("MinimumTimeBetweenSearchQueries", - $params.MinimumTimeBetweenSearchQueries) + $setParams.Add("MinimumTimeBetweenSearchQueries", + $params.MinimumTimeBetweenSearchQueries) } if ($params.ContainsKey("NumberOfSubscriptionSyncsPerEwsSyncRun")) { - $setParams.Add("NumberOfSubscriptionSyncsPerEwsSyncRun", - $params.NumberOfSubscriptionSyncsPerEwsSyncRun) + $setParams.Add("NumberOfSubscriptionSyncsPerEwsSyncRun", + $params.NumberOfSubscriptionSyncsPerEwsSyncRun) } if ($params.ContainsKey("NumberOfUsersEwsSyncWillProcessAtOnce")) { - $setParams.Add("NumberOfUsersEwsSyncWillProcessAtOnce", - $params.NumberOfUsersEwsSyncWillProcessAtOnce) + $setParams.Add("NumberOfUsersEwsSyncWillProcessAtOnce", + $params.NumberOfUsersEwsSyncWillProcessAtOnce) } if ($params.ContainsKey("NumberOfUsersPerEwsSyncBatch")) { - $setParams.Add("NumberOfUsersPerEwsSyncBatch", - $params.NumberOfUsersPerEwsSyncBatch) + $setParams.Add("NumberOfUsersPerEwsSyncBatch", + $params.NumberOfUsersPerEwsSyncBatch) } - $setParams.Add("Name", $params.Name) - $setParams.Add("ApplicationPool", $params.ApplicationPool) + $setParams.Add("Name", $params.Name) + $setParams.Add("ApplicationPool", $params.ApplicationPool) if ($setParams.ContainsKey("MinimumTimeBetweenEwsSyncSubscriptionSearches")) { @@ -279,14 +295,14 @@ function Set-TargetResource } $setParams.Add("Confirm", $false) $appService = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { - $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" + $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" } $appService | Set-SPWorkManagementServiceApplication @setPArams | Out-Null } } - if ($Ensure -eq "Absent") + if ($Ensure -eq "Absent") { # The service app should not exit Write-Verbose -Message "Removing Work Management Service Application $Name" @@ -294,7 +310,7 @@ function Set-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] - + $serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" } @@ -322,35 +338,35 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] $Name, - + [Parameter()] [System.String] $ProxyName, - + [Parameter()] [System.String] $ApplicationPool, - + [Parameter()] [System.UInt32] - $MinimumTimeBetweenEwsSyncSubscriptionSearches, - + $MinimumTimeBetweenEwsSyncSubscriptionSearches, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenProviderRefreshes, - + $MinimumTimeBetweenProviderRefreshes, + [Parameter()] [System.UInt32] - $MinimumTimeBetweenSearchQueries, - + $MinimumTimeBetweenSearchQueries, + [Parameter()] [System.UInt32] - $NumberOfSubscriptionSyncsPerEwsSyncRun, - + $NumberOfSubscriptionSyncsPerEwsSyncRun, + [Parameter()] [System.UInt32] - $NumberOfUsersEwsSyncWillProcessAtOnce, - + $NumberOfUsersEwsSyncWillProcessAtOnce, + [Parameter()] [System.UInt32] $NumberOfUsersPerEwsSyncBatch, @@ -359,14 +375,22 @@ function Test-TargetResource [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", - + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount ) - + Write-Verbose -Message "Testing Work management service app '$Name'" + $installedVersion = Get-SPDSCInstalledProductVersion + if ($installedVersion.FileMajorPart -eq 16) + { + throw [Exception] ("Work Management Service Application is no longer available " + ` + "in SharePoint 2016: " + ` + "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + } + $PSBoundParameters.Ensure = $Ensure $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md index 85f52449a..3cbd643c9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/readme.md @@ -15,3 +15,9 @@ Remarks The default value for the Ensure parameter is Present. When not specifying this parameter, the service application is provisioned. + +NOTE: +You cannot use this resource with SharePoint 2016, since the Work +Management functionality has been removed in SharePoint 2016. +More information: +https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx diff --git a/Modules/SharePointDsc/Examples/Resources/SPDiagnosticsProvider/1-Configure.ps1 b/Modules/SharePointDsc/Examples/Resources/SPDiagnosticsProvider/1-Configure.ps1 new file mode 100644 index 000000000..aff18c34b --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPDiagnosticsProvider/1-Configure.ps1 @@ -0,0 +1,26 @@ +<# +.EXAMPLE + This example shows how to configure the retention period for a Diagnostics Provider. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPDiagnosticsProvider BlockingQueryProvider + { + Ensure = "Present" + Name = "job-diagnostics-blocking-query-provider" + MaxTotalSizeInBytes = 10000000000000 + Retention = 14 + Enabled = $true + PSDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPInfoPathFormsServiceConfig/1-Configure.ps1 b/Modules/SharePointDsc/Examples/Resources/SPInfoPathFormsServiceConfig/1-Configure.ps1 new file mode 100644 index 000000000..fa2cd4b79 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPInfoPathFormsServiceConfig/1-Configure.ps1 @@ -0,0 +1,35 @@ +<# +.EXAMPLE + This example shows how to configure the InfoPath Forms Service + in the local SharePoint farm. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPInfoPathFormsServiceConfig InfoPathFormsServiceConfig + { + Ensure = "Present" + AllowUserFormBrowserEnabling = $true + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4096 + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSecurityTokenServiceConfig/1-SetConfiguration.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSecurityTokenServiceConfig/1-SetConfiguration.ps1 new file mode 100644 index 000000000..196cf57ba --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSecurityTokenServiceConfig/1-SetConfiguration.ps1 @@ -0,0 +1,26 @@ +<# +.EXAMPLE + This example configures the Security Token Service +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSecurityTokenServiceConfig SecurityTokenService + { + Name = "SPSecurityTokenService" + NameIdentifier = "00000003-0000-0ff1-ce00-000000000000@9f11c5ea-2df9-4950-8dcf-da8cd7aa4eff" + UseSessionCookies = $false + AllowOAuthOverHttp = $false + AllowMetadataOverHttp = $false + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 b/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 index 34ba60885..fcb3bb1fd 100644 --- a/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 +++ b/Modules/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 @@ -838,4 +838,75 @@ function Remove-SPDSCGenericObject $SourceCollection.Remove($Target) } +function Format-OfficePatchGUID +{ + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] + [String] + $PatchGUID + ) + + $guidParts = $PatchGUID.Split("-") + if($guidParts.Count -ne 5 ` + -or $guidParts[0].Length -ne 8 ` + -or $guidParts[1].Length -ne 4 ` + -or $guidParts[2].Length -ne 4 ` + -or $guidParts[3].Length -ne 4 ` + -or $guidParts[4].Length -ne 12) + { + throw "The provided Office Patch GUID is not in the expected format (e.g. XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" + } + + $newPart1 = ConvertTo-ReverseString -InputString $guidParts[0] + $newPart2 = ConvertTo-ReverseString -InputString $guidParts[1] + $newPart3 = ConvertTo-ReverseString -InputString $guidParts[2] + $newPart4 = ConvertTo-TwoDigitFlipString -InputString $guidParts[3] + $newPart5 = ConvertTo-TwoDigitFlipString -InputString $guidParts[4] + + $newGUID = $newPart1 + $newPart2 +$newPart3 + $newPart4 + $newPart5 + return $newGUID +} + +function ConvertTo-TwoDigitFlipString +{ + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] + [string] + $InputString + ) + + if($InputString.Length % 2 -ne 0) + { + throw "The input string was not in the correct format. It needs to have an even length." + } + + $flippedString = "" + + for($i = 0; $i -lt $InputString.Length; $i++) + { + $flippedString += $InputString[$i+1] + $InputString[$i] + $i++ + } + return $flippedString +} + +function ConvertTo-ReverseString +{ + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] + [string] + $InputString + ) + + $reverseString = "" + for($i = $InputString.Length - 1; $i -ge 0; $i--) + { + $reverseString += $InputString[$i] + } + return $reverseString +} + Export-ModuleMember -Function * diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index f722ca47b..572a6319f 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '2.0.0.0' +ModuleVersion = '2.1.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-2017 Microsoft Corporation. All rights reserved.' +Copyright = '(c) 2015-2018 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.' @@ -128,145 +128,51 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = " - * General - * Added VSCode workspace settings to meet coding guidelines - * Corrected comment in CodeCov.yml - * Fixed several PSScriptAnalyzer warnings - * SPAppManagementServiceApp - * Fixed an issue where the instance name wasn't detected correctly - * SPBCSServiceApp - * Added custom Proxy Name support - * Fixed an issue where the instance name wasn't detected correctly - * SPBlobCacheSettings - * Update to set non-default or missing blob cache properties - * SPContentDatabase - * Fixed localized issue - * SPDesignerSettings - * Fixed issue where URL with capitals were not accepted correctly - * SPDistributedCacheService - * Fixed issue where reprovisioning the Distributed Cache - did not work + * General + * Updated the integration tests for building the Azure environment + * Works in any Azure environment. + * Updated the SqlServer configuration to use SqlServerDsc version 10.0.0.0. + * SPAlternateURL + * Added the ability to manage the Central Administration AAMs + * SPDiagnosticsProvider + * Added the resource * SPFarm - * Implemented ToDo to return Central Admin Auth mode - * Fixed an issue where the instance name wasn't detected correctly - * SPInstall - * Updated to document the requirements for an English ISO + * Corrected issue where ServerRole parameter is returned in SP2013 + * SPInfoPathFormsServiceConfig + * Added the resource * SPInstallPrereqs - * Updated to document which parameter is required for which - version of SharePoint - * Added SharePoint 2016 example - * SPLogLevel - * New resource - * SPMachineTranslationServiceApp - * Added custom Proxy Name support - * Fixed an issue where the instance name wasn't detected correctly - * SPManagedMetadataAppDefault - * New resource - * SPManagedMetadataServiceApp - * Update to allow the configuration of the default and - working language - * Fixed issue where the termstore could not be retrieved if the - MMS service instance was stopped - * Fixed an issue where the instance name wasn't detected correctly - * SPMinRoleCompliance - * New resource - * SPPerformancePointServiceApp - * Fixed an issue where the instance name wasn't detected correctly - * SPProjectServer - * New resources to add Project Server 2016 support: - SPProjectServerLicense, SPProjectServerAdditionalSettings, - SPProjectServerADResourcePoolSync, SPProjectServerGlobalPermissions, - SPProjectServerGroup, SPProjectServerTimeSheetSettings, - SPProjectServerUserSyncSettings, SPProjectServerWssSettings - * SPSearchContentSource - * Fixed examples - * SPSearchIndexPartition - * Fixed to return the RootFolder parameter - * SPSearchServiceApp - * Fixed an issue where the instance name wasn't detected correctly - * SPSearchTopology - * Updated to better document how the resource works - * Fixed issue to only return first index partition to prevent - conflicts with SPSearchIndexPartition + * Fixed two typos in to be installed Windows features for SharePoint 2016 + * SPSearchAutoritativePage + * Added missing readme.md + * SPSearchCrawlerImpactRule + * Fixed issue where an error was thrown when retrieving Crawl Impact rules + * Added missing readme.md + * SPSearchCrawlMapping + * Added missing readme.md * SPSecureStoreServiceApp - * Fixed issue with not returning AuditEnabled parameter in Get method - * Fixed an issue where the instance name wasn't detected correctly - * SPServiceAppSecurity - * Fixed issue with NullException when no accounts are configured - in SharePoint - * SPStateServiceApp - * Added custom Proxy Name support - * Fixed an issue where the instance name wasn't detected correctly - * SPSubscriptionSettings - * Fixed an issue where the instance name wasn't detected correctly - * SPTrustedRootAuthority - * Updated to enable using private key certificates. - * SPUsageApplication - * Fixed an issue where the instance name wasn't detected correctly + * Fixed issue in Get-TargetResource to return AuditingEnabled property + * SPSecurityTokenServiceConfig + * Added the resource + * SPServiceIdentity + * Fixed issue with correctly retrieving the process identity for the + Search instance + * Added support for LocalSystem, LocalService and NetworkService * SPUserProfileProperty - * Fixed two NullException issues - * SPUserProfileServiceApp - * Fixed an issue where the instance name wasn't detected correctly - * SPUserProfileSynConnection - * Fix an issue with ADImportConnection - * SPWeb - * Update to allow the management of the access requests settings - * SPWebAppGeneralSettings - * Added DefaultQuotaTemplate parameter - * SPWebApplicationExtension - * Update to fix how property AllowAnonymous is returned in the - hashtable - * SPWebAppPeoplePickerSettings - * New resource - * SPWebAppPolicy - * Fixed issue where the SPWebPolicyPermissions couldn't be used - twice with the exact same values - * SPWebAppSuiteBar - * New resource - * SPWebApplication.Throttling - * Fixed issue with where the RequestThrottling parameter was - not applied - * SPWordAutomationServiceApp - * Fixed an issue where the instance name wasn't detected correctly - * SPWorkflowService - * New resource - - The following changes will break 1.x configurations that use these resources: - - * SPAlternateUrl - * Added the Internal parameter, which implied a change to the key parameters - * SPCreateFarm - * Removed resource, please update your configurations to use SPFarm. - See http://aka.ms/SPDsc-SPFarm for details. - * SPJoinFarm - * Removed resource, please update your configurations to use SPFarm. - See http://aka.ms/SPDsc-SPFarm for details. - * SPManagedMetadataServiceApp - * Changed implementation of resource. This resource will not set any defaults - for the keyword and site collection term store. The new resource - SPManagedMetadataServiceAppDefault has to be used for this setting. - * SPShellAdmin - * Updated so it also works for non-content databases - * SPTimerJobState - * Updated to make the WebAppUrl parameter a key parameter. - The resource can now be used to configure the same job for multiple - web applications. Also changed the Name parameter to TypeName, due to - a limitation with the SPTimerJob cmdlets - * SPUserProfileProperty - * Fixed an issue where string properties were not created properly - * SPUSerProfileServiceApp - * Updated to remove the requirement for CredSSP + * Fixed issues with the User Profile properties for 2016 + * SPUserProfileServiceAppPermissions + * Removed the mandatory requirement from secondary parameters + * SPUserProfileSyncConnection + * Fixed issues with the User Profile Sync connection for SharePoint + 2016 * SPUserProfileSyncService - * Updated to remove the requirement for CredSSP + * Added returning the FarmAccount to the Get method * SPWebAppAuthentication - * New resource - * SPWebApplication - * Changed implementation of the Web Application authentication configuration. - A new resource has been added and existing properties have been removed + * Corrected issue where parameter validation wasn't performed correctly * SPWebApplicationExtension - * Updated so it infers the UseSSL value from the URL - * Changed implementation of the Web Application authentication configuration. - A new resource has been added and existing properties have been removed + * Fixed issue with test always failing when Ensure was set to Absent + * SPWorkManagementServiceApp + * Added check for SharePoint 2016, since this functionality has been + removed in SharePoint 2016 " } # End of PSData hashtable diff --git a/Modules/SharePointDsc/en-US/about_SPAlternateUrl.help.txt b/Modules/SharePointDsc/en-US/about_SPAlternateUrl.help.txt index 72e49de10..03d24fd59 100644 --- a/Modules/SharePointDsc/en-US/about_SPAlternateUrl.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPAlternateUrl.help.txt @@ -8,6 +8,12 @@ application. Alternatively a URL can be removed from a zone to ensure that it will remain empty and have no alternate URL. + To select the Central Administration site, use the following command to retrieve + the correct web application name: + (Get-SPWebApplication -IncludeCentralAdministration | Where-Object { + $_.IsAdministrationWebApplication + }).DisplayName + The default value for the Ensure parameter is Present. When not specifying this parameter, the setting is configured. diff --git a/Modules/SharePointDsc/en-US/about_SPBlobCacheSettings.help.txt b/Modules/SharePointDsc/en-US/about_SPBlobCacheSettings.help.txt index bc524e718..fb91f98c1 100644 --- a/Modules/SharePointDsc/en-US/about_SPBlobCacheSettings.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPBlobCacheSettings.help.txt @@ -12,11 +12,10 @@ to configure all WFE servers in the farm, you have to apply this resource to all servers. - Note: - - - In order to prevent inconsistancy between different web front end servers, - make sure you configure this setting on all servers equally. - - If the specified folder does not exist, the resource will create the folder. + NOTE: + In order to prevent inconsistancy between different web front end servers, + make sure you configure this setting on all servers equally. + If the specified folder does not exist, the resource will create the folder. Best practice: Specify a directory that is not on the same drive as where either the server diff --git a/Modules/SharePointDsc/en-US/about_SPContentDatabase.help.txt b/Modules/SharePointDsc/en-US/about_SPContentDatabase.help.txt index 1ef44784b..c0ca49d45 100644 --- a/Modules/SharePointDsc/en-US/about_SPContentDatabase.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPContentDatabase.help.txt @@ -4,10 +4,12 @@ # Description This resource is used to add and remove Content Databases to web applications - 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. + 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/en-US/about_SPDiagnosticsProvider.help.txt b/Modules/SharePointDsc/en-US/about_SPDiagnosticsProvider.help.txt new file mode 100644 index 000000000..3db3722f9 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPDiagnosticsProvider.help.txt @@ -0,0 +1,62 @@ +.NAME + SPDiagnosticsProvider + +# Description + + This resource is responsible for configuring the Diagnostics Provider within + the local SharePoint farm. Using Ensure equals to Absent is not supported. + This resource can only apply configuration, not ensure they don't exist. + +.PARAMETER Name + Key - string + Name of the Diagnostics Provider to configure + +.PARAMETER Retention + Write - Uint16 + Sets the retention period in days + +.PARAMETER MaxTotalSizeInBytes + Write - Uint64 + Sets the maximum retention size in bytes + +.PARAMETER Enabled + Write - Boolean + True enables the Diagnostics Provider + +.PARAMETER Ensure + Write - string + Allowed values: Present, Absent + Present to configure the diagnostics provider + +.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 configure the retention period for a Diagnostics Provider. + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPDiagnosticsProvider BlockingQueryProvider + { + Ensure = "Present" + Name = "job-diagnostics-blocking-query-provider" + MaxTotalSizeInBytes = 10000000000000 + Retention = 14 + Enabled = $true + PSDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPInfoPathFormsServiceConfig.help.txt b/Modules/SharePointDsc/en-US/about_SPInfoPathFormsServiceConfig.help.txt new file mode 100644 index 000000000..c8115f783 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPInfoPathFormsServiceConfig.help.txt @@ -0,0 +1,107 @@ +.NAME + SPInfoPathFormsServiceConfig + +# Description + + This resource is responsible for configuring the InfoPath Forms service within + the local SharePoint farm. Using Ensure equals to Absent is not supported. + This resource can only apply configuration, not ensure they don't exist. + +.PARAMETER Ensure + Key - string + Allowed values: Present, Absent + Present ensures the settings are applied + +.PARAMETER AllowUserFormBrowserEnabling + Write - Boolean + True sets the InfoPath Forms Service to allow users to browse forms + +.PARAMETER AllowUserFormBrowserRendering + Write - Boolean + True sets the InfoPath Forms Service to render forms in the browser + +.PARAMETER MaxDataConnectionTimeout + Write - Uint32 + Sets the maximum connection timeout in milliseconds + +.PARAMETER DefaultDataConnectionTimeout + Write - Uint32 + Sets the default connection timeout in milliseconds + +.PARAMETER MaxDataConnectionResponseSize + Write - Uint32 + Sets the maximum response size in kb for the user response + +.PARAMETER RequireSslForDataConnections + Write - Boolean + True sets the InfoPath Forms Service to require SSL for its connections + +.PARAMETER AllowEmbeddedSqlForDataConnections + Write - Boolean + True sets the InfoPath Forms Service to allow embedded SQL sonnections in Forms + +.PARAMETER AllowUdcAuthenticationForDataConnections + Write - Boolean + True sets the InfoPath Forms Service to allow User Defined connections + +.PARAMETER AllowUserFormCrossDomainDataConnections + Write - Boolean + True sets the InfoPath Forms Service to allow Cross-Domain connections + +.PARAMETER MaxPostbacksPerSession + Write - Uint16 + Maximum number of postback allowed per session + +.PARAMETER MaxUserActionsPerPostback + Write - Uint16 + Maximum number of actions that can be triggered per postback + +.PARAMETER ActiveSessionsTimeout + Write - Uint16 + Timeout in minutes for active sessions + +.PARAMETER MaxSizeOfUserFormState + Write - Uint16 + Maximum size of user session data + +.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 configure the InfoPath Forms Service + in the local SharePoint farm. + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPInfoPathFormsServiceConfig InfoPathFormsServiceConfig + { + Ensure = "Present" + AllowUserFormBrowserEnabling = $true + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4096 + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPInstall.help.txt b/Modules/SharePointDsc/en-US/about_SPInstall.help.txt index 8abaa689a..4023dd69b 100644 --- a/Modules/SharePointDsc/en-US/about_SPInstall.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPInstall.help.txt @@ -9,7 +9,8 @@ file and validate the license key during the installation process. This module depends on the prerequisites already being installed, which can be done - NOTE: This resource only supports SharePoint Server. SharePoint Foundation + NOTE: + This resource only supports SharePoint Server. SharePoint Foundation is not supported. For examples to install SharePoint Foundation using DSC, see: https://github.com/PowerShell/SharePointDsc/wiki/SPInstall (Example 3) diff --git a/Modules/SharePointDsc/en-US/about_SPOfficeOnlineServerBinding.help.txt b/Modules/SharePointDsc/en-US/about_SPOfficeOnlineServerBinding.help.txt index ef9deab6c..f2a0d5e05 100644 --- a/Modules/SharePointDsc/en-US/about_SPOfficeOnlineServerBinding.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPOfficeOnlineServerBinding.help.txt @@ -7,7 +7,8 @@ as Office Web Apps). The DnsName property can be a single server name, or a FQDN of a load balanced end point that will direct traffic to a farm. - NOTE: This resource is designed to be used where all WOPI bindings will be + 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 diff --git a/Modules/SharePointDsc/en-US/about_SPProjectServerADResourcePoolSync.help.txt b/Modules/SharePointDsc/en-US/about_SPProjectServerADResourcePoolSync.help.txt index 13a809f3a..7147c5960 100644 --- a/Modules/SharePointDsc/en-US/about_SPProjectServerADResourcePoolSync.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPProjectServerADResourcePoolSync.help.txt @@ -8,7 +8,8 @@ You can control which AD groups should be imported from and control settings about reactivitating users. - Note: The schedule for this import is controlled via a standard + NOTE: + The schedule for this import is controlled via a standard SharePoint server timer job, and as such it can be controlled with the SPTimerJobState resource. Below is an example of how to set this resource to run the AD import job daily. The name of the job diff --git a/Modules/SharePointDsc/en-US/about_SPProjectServerWssSettings.help.txt b/Modules/SharePointDsc/en-US/about_SPProjectServerWssSettings.help.txt index efae83fc3..2b2fe458e 100644 --- a/Modules/SharePointDsc/en-US/about_SPProjectServerWssSettings.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPProjectServerWssSettings.help.txt @@ -6,7 +6,8 @@ This resource is used to control settings that relate to the SharePoint sites that are linked to projects in Project Server. - NOTE: The account you use to run this resource (through either the InstallAccount + NOTE: + The account you use to run this resource (through either the InstallAccount or PsDscRunAsCredential properties) needs to have elevated rights to execute this resource. It is recommended to use the SharePoint Farm Account for this purpose to avoid receiving a "GeneralSecurityAccessDenied" error. diff --git a/Modules/SharePointDsc/en-US/about_SPSearchAuthoritativePage.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchAuthoritativePage.help.txt new file mode 100644 index 000000000..2bcee98a1 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSearchAuthoritativePage.help.txt @@ -0,0 +1,92 @@ +.NAME + SPSearchAuthoritativePage + +# Description + + This resource is responsible for managing the search authoritative pages in the + search service application. You can create new pages, change existing pages and + remove existing pages. + + The default value for the Ensure parameter is Present. When you omit this + parameter the crawl rule is created. + +.PARAMETER ServiceAppName + Key - String + Search Service Application Name + +.PARAMETER Path + Key - String + Source URI for the authoritative page + +.PARAMETER Level + Write - Real32 + Level of Authoratitive Page, values between 0.0 and 2.0 + +.PARAMETER Action + Write - String + Allowed values: Authoratative, Demoted + The resource will either make the page authoritative or demoted based on this value + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Ensure the Authoritative is Present or Absent + +.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 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 + } + } + } + + +.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/en-US/about_SPSearchCrawlMapping.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchCrawlMapping.help.txt new file mode 100644 index 000000000..5722696ee --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSearchCrawlMapping.help.txt @@ -0,0 +1,64 @@ +.NAME + SPSearchCrawlMapping + +# Description + + This resource is responsible for managing the search crawl mapping in the + search service application. You can create new mappings, change existing mappings + and remove existing mappings. + + The default value for the Ensure parameter is Present. When you omit this + parameter the crawl rule is created. + +.PARAMETER ServiceAppName + Key - String + Search Service Application Name + +.PARAMETER Url + Key - String + Source URI for the crawl mapping + +.PARAMETER Target + Required - String + Target URI for the crawl mapping + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Ensure the crawl mapping is Present or Absent + +.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 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/en-US/about_SPSearchCrawlerImpactRule.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchCrawlerImpactRule.help.txt new file mode 100644 index 000000000..f6dbc8c59 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSearchCrawlerImpactRule.help.txt @@ -0,0 +1,42 @@ +.NAME + SPSearchCrawlerImpactRule + +# Description + + This resource is responsible for managing the search crawl impact 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 you omit this + parameter the crawl rule is created. + +.PARAMETER ServiceAppName + Key - String + Search Service Application Name + +.PARAMETER Name + Key - String + The Site for the crawl impact rule + +.PARAMETER Behavior + Read - String + The Behavior (RequestLimit or WaitTime) for this crawl impact rule + +.PARAMETER RequestLimit + Write - UInt32 + The RequestLimit setting for the crawl impact rule + +.PARAMETER WaitTime + Write - UInt32 + The WaitTime setting for the crawl impact rule + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Ensure the crawl rule is Present or Absent + +.PARAMETER InstallAccount + Write - String + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + diff --git a/Modules/SharePointDsc/en-US/about_SPSecurityTokenServiceConfig.help.txt b/Modules/SharePointDsc/en-US/about_SPSecurityTokenServiceConfig.help.txt new file mode 100644 index 000000000..c6ef7dff7 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSecurityTokenServiceConfig.help.txt @@ -0,0 +1,66 @@ +.NAME + SPSecurityTokenServiceConfig + +# Description + + This resource is responsible for configuring the Security Token Service within + the local SharePoint farm. Using Ensure equals to Absent is not supported. + This resource can only apply configuration, not ensure they don't exist. + +.PARAMETER Name + Key - string + The name of the security token service + +.PARAMETER NameIdentifier + Write - string + The identifier for the security token service + +.PARAMETER UseSessionCookies + Write - Boolean + True set the security token service to use cookies + +.PARAMETER AllowOAuthOverHttp + Write - Boolean + True set the security token service to allow OAuth over HTTP + +.PARAMETER AllowMetadataOverHttp + Write - Boolean + True set the security token service to allow metadata exchange over HTTP + +.PARAMETER Ensure + Write - string + Allowed values: Present, Absent + Present ensures the configurations are applied + +.PARAMETER InstallAccount + Write - String + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + +.EXAMPLE + This example configures the Security Token Service + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSecurityTokenServiceConfig SecurityTokenService + { + Name = "SPSecurityTokenService" + NameIdentifier = "00000003-0000-0ff1-ce00-000000000000@9f11c5ea-2df9-4950-8dcf-da8cd7aa4eff" + UseSessionCookies = $false + AllowOAuthOverHttp = $false + AllowMetadataOverHttp = $false + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPServiceIdentity.help.txt b/Modules/SharePointDsc/en-US/about_SPServiceIdentity.help.txt index a0c4ccdb2..01ee465b2 100644 --- a/Modules/SharePointDsc/en-US/about_SPServiceIdentity.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPServiceIdentity.help.txt @@ -4,6 +4,7 @@ # Description This resource is used to specify a managed account to be used to run a service instance. + You can also specify LocalService, LocalSystem or NetworkService as ManagedAccount. The name is the typename of the service as shown in the Central Admin website. This resource only needs to be run on one server in the farm, as the process identity update method will apply the settings to all instances of the service. @@ -14,7 +15,7 @@ .PARAMETER ManagedAccount Required - string - The user name of a managed account that will be used to run the service + The user name of a managed account, LocalService, LocalSystem or NetworkService that will be used to run the service .PARAMETER InstallAccount Write - String diff --git a/Modules/SharePointDsc/en-US/about_SPSite.help.txt b/Modules/SharePointDsc/en-US/about_SPSite.help.txt index fe3bb4a3b..2fce6342c 100644 --- a/Modules/SharePointDsc/en-US/about_SPSite.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPSite.help.txt @@ -11,7 +11,8 @@ 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 + 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. diff --git a/Modules/SharePointDsc/en-US/about_SPTimerJobState.help.txt b/Modules/SharePointDsc/en-US/about_SPTimerJobState.help.txt index a338d8a43..9e3360bf0 100644 --- a/Modules/SharePointDsc/en-US/about_SPTimerJobState.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPTimerJobState.help.txt @@ -19,7 +19,8 @@ - Monthly at 15 15:00:00 - Yearly at Jan 1 15:00:00 - NOTE: Make sure you use the typename timer job name, not the display name! Use + NOTE: + Make sure you use the typename timer job name, not the display name! Use "Get-SPTimerJob | Where-Object { $_.Title -eq "\" } | Select typename" to find the typename for each Timer Job. diff --git a/Modules/SharePointDsc/en-US/about_SPUserProfileServiceAppPermissions.help.txt b/Modules/SharePointDsc/en-US/about_SPUserProfileServiceAppPermissions.help.txt index 7730af844..d37c2e2f5 100644 --- a/Modules/SharePointDsc/en-US/about_SPUserProfileServiceAppPermissions.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPUserProfileServiceAppPermissions.help.txt @@ -14,15 +14,15 @@ The name of the proxy that is attached to the user profile service you wish to set permissions for .PARAMETER CreatePersonalSite - Required - string + Write - string A list of user principals that will have the Create personal site permission .PARAMETER FollowAndEditProfile - Required - string + Write - string A list of user principals that will have the Follow users and edit profile permission .PARAMETER UseTagsAndNotes - Required - string + Write - string A list of user principals that will have the Use tags and notes permission .PARAMETER InstallAccount diff --git a/Modules/SharePointDsc/en-US/about_SPWebAppAuthentication.help.txt b/Modules/SharePointDsc/en-US/about_SPWebAppAuthentication.help.txt index 1f2ef6aab..49fa25bb7 100644 --- a/Modules/SharePointDsc/en-US/about_SPWebAppAuthentication.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPWebAppAuthentication.help.txt @@ -8,10 +8,12 @@ configure the five available zones (if they exist) separately and each zone can have multiple authentication methods configured. - NOTE: This resource cannot be used to convert a Classic web application + NOTE: + This resource cannot be used to convert a Classic web application to Claims mode. You have to run Convert-SPWebApplication manually for that. - NOTE 2: Updating the configuration can take a long time, up to five minutes. + NOTE 2: + Updating the configuration can take a long time, up to five minutes. The Set-SPWebApplication cmdlet sometimes requires several minutes to complete its action. This is not a SharePointDsc issue. diff --git a/Modules/SharePointDsc/en-US/about_SPWebApplication.help.txt b/Modules/SharePointDsc/en-US/about_SPWebApplication.help.txt index 793e1fb2d..497a8c23f 100644 --- a/Modules/SharePointDsc/en-US/about_SPWebApplication.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPWebApplication.help.txt @@ -11,7 +11,8 @@ 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 + 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. diff --git a/Modules/SharePointDsc/en-US/about_SPWorkManagementServiceApp.help.txt b/Modules/SharePointDsc/en-US/about_SPWorkManagementServiceApp.help.txt index 979c2cf81..af5397081 100644 --- a/Modules/SharePointDsc/en-US/about_SPWorkManagementServiceApp.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPWorkManagementServiceApp.help.txt @@ -19,6 +19,12 @@ The default value for the Ensure parameter is Present. When not specifying this parameter, the service application is provisioned. + NOTE: + You cannot use this resource with SharePoint 2016, since the Work + Management functionality has been removed in SharePoint 2016. + More information: + https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx + .PARAMETER Name Key - string The name of the work management service application diff --git a/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 b/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 index dddfc94e4..e42d38a24 100644 --- a/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 +++ b/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 @@ -5,7 +5,7 @@ for SharePointDsc or to run integration tests against .DESCRIPTION The New-SPDscAzureLab cmdlet will deploy a new resource group in to your current Azure subscription -that will contain storage, network and virtual machines that are configured to be able to begin +that will contain storage, network and virtual machines that are configured to be able to begin development. Appropriate development tools are also installed on the SharePoint server. .PARAMETER ResourceGroupName @@ -21,7 +21,7 @@ This is the name of the storage account that will be created for the deployment. contain VHD images, scripts and DSC configurations .PARAMETER SoftwareStorageAccountName -This is the name of a storage account that will contain the binaries for SharePoint Server +This is the name of a storage account that will contain the binaries for SharePoint Server (either 2013 or 2016). .PARAMETER SoftwareStorageAccountContainer @@ -34,7 +34,7 @@ A valid product key for the version of SharePoint you wish to install .PARAMETER PublicDNSLabel The name of the public DNS label to assign to the public IP address of the SharePoint server. -This will automatically be suffixed with the Azure location name and azure DNS suffix +This will automatically be suffixed with the Azure location name and azure DNS suffix .PARAMETER AdminCredential The username and password to use as the local administrator on all machines. The password @@ -61,7 +61,7 @@ function New-SPDscAzureLab [Parameter(Mandatory = $true)] [string] $ResourceGroupName, - + [Parameter(Mandatory = $true)] [string] $Location, @@ -89,7 +89,11 @@ function New-SPDscAzureLab [Parameter(Mandatory = $true)] [PSCredential] $AdminCredential - ) + ) + + # Get the Azure environment + $azureEnvironment = ( Get-AzureRmSubscription | Select-Object -ExpandProperty ExtendedProperties ).Environment | + Select-Object -Unique # Create the RG and storage account New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location @@ -133,6 +137,7 @@ function New-SPDscAzureLab $parameters = @{} + $parameters.Add("azureEnvironment", $azureEnvironment) $parameters.Add("storageAccountName", $StorageAccountName) $parameters.Add("storageAccountKey", $mainKeys[0].Value) $parameters.Add("softwareStorageAccount", $SoftwareStorageAccountName) diff --git a/Tests/Integration/Azure/DscConfigs/SQLServer.ps1 b/Tests/Integration/Azure/DscConfigs/SQLServer.ps1 index 2bcf7a6fa..8740c5e1c 100644 --- a/Tests/Integration/Azure/DscConfigs/SQLServer.ps1 +++ b/Tests/Integration/Azure/DscConfigs/SQLServer.ps1 @@ -1,30 +1,30 @@ Configuration SQLServer { param( - [Parameter(Mandatory=$true)] - [ValidateNotNullorEmpty()] - [PSCredential] + [Parameter(Mandatory=$true)] + [ValidateNotNullorEmpty()] + [PSCredential] $DomainAdminCredential, - [Parameter(Mandatory=$true)] - [ValidateNotNullorEmpty()] - [PSCredential] + [Parameter(Mandatory=$true)] + [ValidateNotNullorEmpty()] + [PSCredential] $SqlServiceAccount ) Import-DscResource -ModuleName xCredSSP -ModuleVersion 1.0.1 Import-DscResource -ModuleName xComputerManagement -ModuleVersion 1.9.0.0 Import-DscResource -ModuleName xNetworking -ModuleVersion 3.2.0.0 - Import-DscResource -ModuleName xSQLServer -ModuleVersion 5.0.0.0 + Import-DscResource -ModuleName SqlServerDsc -ModuleVersion 10.0.0.0 node localhost { - Registry DisableIPv6 + Registry DisableIPv6 { - Key = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" - ValueName = "DisabledComponents" - ValueData = "ff" - ValueType = "Dword" + Key = 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' + ValueName = 'DisabledComponents' + ValueData = 'ff' + ValueType = 'Dword' Hex = $true Ensure = 'Present' } @@ -32,81 +32,71 @@ Configuration SQLServer xComputer DomainJoin { Name = $env:COMPUTERNAME - DomainName = "demo.lab" + DomainName = 'demo.lab' Credential = $DomainAdminCredential - DependsOn = "[Registry]DisableIPv6" + DependsOn = '[Registry]DisableIPv6' } - xCredSSP CredSSPServer + xCredSSP CredSSPServer { - Ensure = "Present" - Role = "Server" - } - - xCredSSP CredSSPClient - { - Ensure = "Present" - Role = "Client" - DelegateComputers = "*.demo.lab" + Ensure = 'Present' + Role = 'Server' } - xFirewall SQLEngineFirewallRule + xCredSSP CredSSPClient { - Name = "SQLDatabaseEngine" - DisplayName = "SQL Server Database Engine" - Group = "SQL Server Rules" - Ensure = "Present" - Action = "Allow" - Enabled = "True" - Profile = ("Domain", "Private") - Direction = "Inbound" - LocalPort = ("1433", "1434") - Protocol = "TCP" - Description = "SQL Database engine exception" + Ensure = 'Present' + Role = 'Client' + DelegateComputers = '*.demo.lab' } - xSQLServerLogin DomainAdminLogin + xFirewall SQLEngineFirewallRule { - Name = "DEMO\Domain Admins" - LoginType = "WindowsGroup" - SQLServer = $env:COMPUTERNAME - SQLInstanceName = "MSSQLSERVER" - DependsOn = "[xComputer]DomainJoin" + Name = 'SQLDatabaseEngine' + DisplayName = 'SQL Server Database Engine' + Group = 'SQL Server Rules' + Ensure = 'Present' + Action = 'Allow' + Enabled = 'True' + Profile = ('Domain', 'Private') + Direction = 'Inbound' + LocalPort = ('1433', '1434') + Protocol = 'TCP' + Description = 'SQL Database engine exception' } - xSQLServerRole DomainAdminsAdmin + SqlServerLogin DomainAdminLogin { - Name = "DEMO\Domain Admins" - Ensure = "Present" - ServerRole = "sysadmin" - SQLServer = $env:COMPUTERNAME - SQLInstanceName = "MSSQLSERVER" - DependsOn = "[xSQLServerLogin]DomainAdminLogin" + Name = 'DEMO\Domain Admins' + LoginType = 'WindowsGroup' + ServerName = $env:COMPUTERNAME + InstanceName = 'MSSQLSERVER' + DependsOn = '[xComputer]DomainJoin' } - xSQLServerLogin SPSetupLogin + SqlServerLogin SPSetupLogin { - Name = "DEMO\svcSPSetup" - LoginType = "WindowsUser" - SQLServer = $env:COMPUTERNAME - SQLInstanceName = "MSSQLSERVER" - DependsOn = "[xComputer]DomainJoin" + Name = 'DEMO\svcSPSetup' + LoginType = 'WindowsUser' + ServerName = $env:COMPUTERNAME + InstanceName = 'MSSQLSERVER' + DependsOn = '[xComputer]DomainJoin' } - xSQLServerRole SPSetupAdmin + SqlServerRole sysadmin { - Name = "DEMO\svcSPSetup" - Ensure = "Present" - SQLServer = $env:COMPUTERNAME - SQLInstanceName = "MSSQLSERVER" - ServerRole = "sysadmin" - DependsOn = "[xSQLServerLogin]SPSetupLogin" + MembersToInclude = @('DEMO\svcSPSetup','DEMO\Domain Admins') + Ensure = 'Present' + ServerName = $env:COMPUTERNAME + InstanceName = 'MSSQLSERVER' + ServerRoleName = 'sysadmin' + DependsOn = '[SqlServerLogin]DomainAdminLogin','[SqlServerLogin]SPSetupLogin' } LocalConfigurationManager { RebootNodeIfNeeded = $true - ActionAfterReboot = "ContinueConfiguration" + ActionAfterReboot = 'ContinueConfiguration' } } } diff --git a/Tests/Integration/Azure/DscConfigs/SharePointPrep.ps1 b/Tests/Integration/Azure/DscConfigs/SharePointPrep.ps1 index 2a1ee4ba0..4580ceb49 100644 --- a/Tests/Integration/Azure/DscConfigs/SharePointPrep.ps1 +++ b/Tests/Integration/Azure/DscConfigs/SharePointPrep.ps1 @@ -1,14 +1,14 @@ Configuration SharePointPrep { param( - [Parameter(Mandatory=$true)] - [ValidateNotNullorEmpty()] - [PSCredential] + [Parameter(Mandatory=$true)] + [ValidateNotNullorEmpty()] + [PSCredential] $DomainAdminCredential, - [Parameter(Mandatory=$true)] - [ValidateNotNullorEmpty()] - [PSCredential] + [Parameter(Mandatory=$true)] + [ValidateNotNullorEmpty()] + [PSCredential] $SPSetupCredential, [Parameter(Mandatory=$true)] @@ -16,6 +16,11 @@ Configuration SharePointPrep [string] $SPProductKey, + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + $AzureEnvironment, + [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] @@ -39,7 +44,7 @@ Configuration SharePointPrep node localhost { - Registry DisableIPv6 + Registry DisableIPv6 { Key = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" ValueName = "DisabledComponents" @@ -80,14 +85,15 @@ Configuration SharePointPrep } } Import-Module -Name Azure.Storage - $context = New-AzureStorageContext -StorageAccountName $using:SoftwareStorageAccount ` + $context = New-AzureStorageContext -Environment $using:AzureEnvironment ` + -StorageAccountName $using:SoftwareStorageAccount ` -StorageAccountKey $using:SoftwareStorageKey $blobs = Get-AzureStorageBlob -Container $using:SoftwareStorageContainer ` -Context $context New-Item -Path C:\Binaries\SharePoint -ItemType Directory - + $blobs | ForEach-Object -Process { Get-AzureStorageBlobContent -Blob $_.Name ` -Container $using:SoftwareStorageContainer ` @@ -101,11 +107,11 @@ Configuration SharePointPrep Ensure = "Present" OnlineMode = $true InstallerPath = "C:\Binaries\SharePoint\prerequisiteinstaller.exe" - DependsOn = @("[Script]DownloadBinaries", "[Group]LocalAdministrators") + DependsOn = @("[Script]DownloadBinaries", "[Group]LocalAdministrators") } - xWebAppPool RemoveDotNet2Pool { Name = ".NET v2.0" - Ensure = "Absent" + xWebAppPool RemoveDotNet2Pool { Name = ".NET v2.0" + Ensure = "Absent" DependsOn = "[SPInstallPrereqs]InstallPrereqs" } xWebAppPool RemoveDotNet2ClassicPool { Name = ".NET v2.0 Classic" Ensure = "Absent" @@ -127,7 +133,7 @@ Configuration SharePointPrep PhysicalPath = "C:\inetpub\wwwroot" DependsOn = "[SPInstallPrereqs]InstallPrereqs" } - SPInstall InstallSharePoint + SPInstall InstallSharePoint { Ensure = "Present" BinaryDir = "C:\Binaries\SharePoint" diff --git a/Tests/Integration/Azure/template.json b/Tests/Integration/Azure/template.json index 8fef2e83c..fa213106f 100644 --- a/Tests/Integration/Azure/template.json +++ b/Tests/Integration/Azure/template.json @@ -2,6 +2,12 @@ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { + "azureEnvironment": { + "type": "string", + "metadata": { + "description": "The Azure environment" + } + }, "storageAccountName": { "type": "string", "metadata": { @@ -76,7 +82,7 @@ "spVmName": "[concat(resourceGroup().Name, '-sp')]", "spDisk1Name": "[concat(resourceGroup().Name, '-sp-disk-c')]" }, - "resources": [ + "resources": [ { "apiVersion": "2015-05-01-preview", "type": "Microsoft.Network/virtualNetworks", @@ -160,7 +166,7 @@ "caching": "ReadWrite", "createOption": "FromImage", "vhd": { - "uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/vhds/', variables('dcDisk1Name'),'.vhd')]" + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'vhds/', variables('dcDisk1Name'),'.vhd')]" } } }, @@ -188,7 +194,7 @@ "autoUpgradeMinorVersion": true, "settings": { "configuration": { - "url": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/windows-powershell-dsc/DomainController.ps1.zip')]", + "url": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'windows-powershell-dsc/DomainController.ps1.zip')]", "script": "DomainController.ps1", "function": "DomainController" }, @@ -269,7 +275,7 @@ "caching": "ReadWrite", "createOption": "FromImage", "vhd": { - "uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/vhds/', variables('sqlDisk1Name'),'.vhd')]" + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'vhds/', variables('sqlDisk1Name'),'.vhd')]" } } }, @@ -298,7 +304,7 @@ "autoUpgradeMinorVersion": true, "settings": { "configuration": { - "url": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/windows-powershell-dsc/SQLServer.ps1.zip')]", + "url": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'windows-powershell-dsc/SQLServer.ps1.zip')]", "script": "SQLServer.ps1", "function": "SQLServer" }, @@ -391,7 +397,7 @@ "caching": "ReadWrite", "createOption": "FromImage", "vhd": { - "uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/vhds/', variables('spDisk1Name'),'.vhd')]" + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'vhds/', variables('spDisk1Name'),'.vhd')]" } } }, @@ -420,7 +426,7 @@ "autoUpgradeMinorVersion": true, "settings": { "configuration": { - "url": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/windows-powershell-dsc/SharePointPrep.ps1.zip')]", + "url": "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'windows-powershell-dsc/SharePointPrep.ps1.zip')]", "script": "SharePointPrep.ps1", "function": "SharePointPrep" }, @@ -437,6 +443,7 @@ "UserName": "DEMO\\svcSPSetup", "Password": "[parameters('adminPassword')]" }, + "AzureEnvironment": "[parameters('azureEnvironment')]", "SoftwareStorageKey": "[parameters('softwareStorageKey')]", "SoftwareStorageAccount": "[parameters('softwareStorageAccount')]", "SPProductKey": "[parameters('spProductKey')]", @@ -460,7 +467,7 @@ "autoUpgradeMinorVersion": true, "settings": { "fileUris": [ - "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/scripts/DevSetup.ps1')]" + "[concat(reference(concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountName')), '2017-10-01').primaryEndpoints.blob,'scripts/DevSetup.ps1')]" ] }, "protectedSettings": { diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 index 0b24b2f78..d11e4f166 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -22,7 +22,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName New-SPAlternateURL {} Mock -CommandName Set-SPAlternateURL {} Mock -CommandName Remove-SPAlternateURL {} - + # Test contexts Context -Name "Specified web application does not exist" -Fixture { $testParams = @{ @@ -45,13 +45,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @() } - It "Should call the new function in the set method" { + It "Should throw exception in the set method" { { Set-TargetResource @testParams } | Should Throw "Web application was not found. Please check WebAppName parameter!" } } @@ -77,16 +77,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Absent in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + (Get-TargetResource @testParams).Ensure | Should Be "Absent" } It "Should return false from the test method" { @@ -114,16 +114,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPAlternateUrl -MockWith { return @() - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Absent in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + (Get-TargetResource @testParams).Ensure | Should Be "Absent" } It "Should return false from the test method" { @@ -135,7 +135,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled New-SPAlternateURL } } - + Context -Name "The internal alternate URL exists for the specified zone and web app, and should be" -Fixture { $testParams = @{ WebAppName = "SharePoint - www.domain.com80" @@ -151,7 +151,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PublicUrl = "http://www.domain.com" IncomingUrl = "http://something.contoso.local" Zone = "Internet" - } + } ) } -ParameterFilter { $Identity -eq $testParams.Url } @@ -163,16 +163,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -195,22 +195,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PublicUrl = "http://www.otherdomain.com" IncomingUrl = "http://something.contoso.local" Zone = "Default" - } + } ) } -ParameterFilter { $Identity -eq $testParams.Url } Mock -CommandName Get-SPAlternateUrl -MockWith { return @() - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -237,7 +237,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PublicUrl = "http://www.otherdomain.com" IncomingUrl = "http://something.contoso.local" Zone = "Default" - } + } ) } -ParameterFilter { $Identity -eq $testParams.Url } @@ -249,16 +249,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Internet" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -300,9 +300,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PublicUrl = "http://www.domain.com" IncomingUrl = "http://something.contoso.local" Zone = "Default" - } + } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ @@ -311,7 +311,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -345,16 +345,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Absent in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + (Get-TargetResource @testParams).Ensure | Should Be "Absent" } It "Should return false from the test method" { @@ -382,7 +382,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PublicUrl = "http://www.domain.com" IncomingUrl = "http://www.newdomain.com" Zone = "Default" - } + } ) } -ParameterFilter { $Identity -eq $testParams.Url } @@ -399,16 +399,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -448,23 +448,23 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return true from the test method" { Test-targetResource @testParams | Should Be $true } } - + Context -Name "A URL exists for the specified zone and web app, and it should not" -Fixture { $testParams = @{ WebAppName = "SharePoint - www.domain.com80" @@ -492,16 +492,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Zone = "Default" } ) - } -ParameterFilter { $WebApplication -eq $testParams.WebAppName } + } -ParameterFilter { $WebApplication.DisplayName -eq $testParams.WebAppName } Mock -CommandName Get-SPWebApplication -MockWith { return @{ - Name = $testParams.WebAppName + DisplayName = $testParams.WebAppName } } It "Should return Ensure=Present in the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" + (Get-TargetResource @testParams).Ensure | Should Be "Present" } It "Should return false from the test method" { @@ -513,7 +513,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Remove-SPAlternateURL } } - } + } } Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 new file mode 100644 index 000000000..62a63d6a5 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 @@ -0,0 +1,94 @@ +[CmdletBinding()] +param( + [Parameter()] + [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 "SPDiagnosticsProvider" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Mock -CommandName Get-SPDiagnosticsProvider -MockWith { + return @{ + Name = "job-diagnostics-blocking-query-provider" + MaxTotalSizeInBytes = 100000 + Retention = 14 + Enabled = $true + }| Add-Member ScriptMethod Update { + } -PassThru + } + + Context -Name "When the Diagnostics Provider passed doesn't exist" -Fixture { + + $testParams = @{ + Name = "MyFakeProvider" + Retention = 13 + MaxTotalSizeInBytes = 10000 + Enabled = $true + Ensure = "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an error about a non-existing provider" { + { Set-TargetResource @testParams } | Should throw "The specified Diagnostic Provider {MyFakeProvider} could not be found." + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should be "Absent" + } + } + + Context -Name "When the Diagnostics Provider exists" -Fixture { + + $testParams = @{ + Name = "job-diagnostics-blocking-query-provider" + Retention = 13 + MaxTotalSizeInBytes = 10000 + Enabled = $true + Ensure = "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should properly configure the provider" { + Set-TargetResource @testParams + } + + It "Should return a Retention period of 14 from the Get method" { + (Get-TargetResource @testParams).Retention | Should be 14 + } + } + + Context -Name "When using Ensure is Absent" -Fixture { + + $testParams = @{ + Name = "job-diagnostics-blocking-query-provider" + Retention = 13 + MaxTotalSizeInBytes = 10000 + Enabled = $true + Ensure = "Absent" + } + + It "Should properly configure the provider" { + { Set-TargetResource @testParams } | Should throw "This resource cannot remove Diagnostics Provider. Please use ensure equals Present." + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 new file mode 100644 index 000000000..88602e985 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 @@ -0,0 +1,125 @@ +[CmdletBinding()] +param( + [Parameter()] + [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 "SPInfoPathFormsServiceConfig" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Mock -CommandName Get-SPInfoPathFormsService -MockWith { + return @{ + Ensure = "Present" + AllowUserFormBrowserEnabling = $true + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4194304 + }| Add-Member ScriptMethod Update { + } -PassThru + } + + Context -Name "When the InfoPath Form Services is null" -Fixture { + Mock -CommandName Get-SPInfoPathFormsService -MockWith { + return $null + } + + $testParams = @{ + Ensure = "Present" + AllowUserFormBrowserEnabling = $false + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4096 + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When trying to remove configurations" -Fixture { + $testParams = @{ + Ensure = "Absent" + AllowUserFormBrowserEnabling = $false + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4096 + } + + It "Should return false when the Test method is called" { + { Set-TargetResource @testParams } | Should throw "This resource cannot undo InfoPath Forms Service Configuration changes. " ` + "Please set Ensure to Present or omit the resource" + } + } + + Context -Name "When the InfoPath Form Services is properly configured" -Fixture { + $testParams = @{ + Ensure = "Present" + AllowUserFormBrowserEnabling = $true + AllowUserFormBrowserRendering = $true + MaxDataConnectionTimeout = 20000 + DefaultDataConnectionTimeout = 10000 + MaxDataConnectionResponseSize = 1500 + RequireSslForDataConnections = $true + AllowEmbeddedSqlForDataConnections = $false + AllowUdcAuthenticationForDataConnections = $false + AllowUserFormCrossDomainDataConnections = $false + MaxPostbacksPerSession = 75 + MaxUserActionsPerPostback = 200 + ActiveSessionsTimeout = 1440 + MaxSizeOfUserFormState = 4096 + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should return the proper MaxSizeOfUserFormState value" { + (Get-TargetResource @testParams).MaxSizeOfUserFormState | Should be 4096 + } + + It "Should properly configure the InfoPath Forms Service" { + Set-TargetResource @testParams + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 new file mode 100644 index 000000000..59fafdeaa --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 @@ -0,0 +1,69 @@ +[CmdletBinding()] +param( + [Parameter()] + [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 "SPSecurityTokenServiceConfig" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Context -Name "When the Security Token Service is null" -Fixture { + Mock -CommandName Get-SPSecurityTokenServiceConfig -MockWith { + return $null + } + + $testParams = @{ + Name = "Security Token Service" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When setting the configurations for the Security Token Service" { + $params = @{ + Name = "New name" + Ensure = "Present" + } + Mock -CommandName Get-SPSecurityTokenServiceConfig -MockWith { + return @{ + Name = "Security Token Service" + NameIdentifier = "12345-12345-12345-12345@12345-12345" + UseSessionCookies = $false + AllowOAuthOverHttp = $false + AllowMetadataOverHttp = $false + }| Add-Member ScriptMethod Update { + $Global:UpdatedCalled = $true + } -PassThru + } + + It "Should properly configure the security token service" { + Set-TargetResource @params + } + + It "Should return ensure equals Present" { + (Get-TargetResource @params).Ensure | Should be "Present" + } + + It "Should throw an error when trying to set to Absent" { + $params.Ensure = "Absent" + { Set-TargetResource @params } | Should throw "This resource cannot undo Security " ` + "Token Service Configuration changes. Please set Ensure to Present or omit the resource" + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 index 7c891ed72..175468a52 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -20,30 +20,30 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { #Initialize tests Add-Type -TypeDefinition @" - namespace Microsoft.SharePoint.Administration + namespace Microsoft.SharePoint.Administration { public class IdentityType { - public string SpecificUser { get; set; } + public string SpecificUser { get; set; } } } "@ # Mocks for all contexts - Mock -CommandName Get-SPManagedAccount -MockWith { + Mock -CommandName Get-SPManagedAccount -MockWith { return "CONTOSO\svc.c2wts" } # Test contexts Context -Name "Service is set to use the specified identity" -Fixture { - + $testParams = @{ Name = "Claims to Windows Token Service" ManagedAccount = "CONTOSO\svc.c2wts" } - Mock -CommandName Get-SPServiceInstance -MockWith { + Mock -CommandName Get-SPServiceInstance -MockWith { $ProcessIdentity = @{ username = $testParams.ManagedAccount } @@ -61,13 +61,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { processidentity = $ProcessIdentity } } - + return $ServiceIdentity } - - It "Should return the current identity from the get method" { + + It "Should return the current identity from the get method" { (Get-TargetResource @testParams).ManagedAccount | Should Not BeNullOrEmpty - + } It "Should return true for the test method" { @@ -76,13 +76,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Context -Name "Service is not set to use the specified identity" -Fixture { - $testParams = @{ Name = "Claims to Windows Token Service" ManagedAccount = "CONTOSO\svc.c2wts" } - Mock -CommandName Get-SPServiceInstance -MockWith { + Mock -CommandName Get-SPServiceInstance -MockWith { $ProcessIdentity = @{ username = "NT AUTHORITY\SYSTEM" } @@ -100,11 +99,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { processidentity = $ProcessIdentity } } - + return $ServiceIdentity } - - It "Should return the current identity from the get method" { + + It "Should return the current identity from the get method" { (Get-TargetResource @testParams).ManagedAccount | Should Not BeNullOrEmpty } @@ -115,25 +114,110 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPDscSPServiceInstanceUpdateCalled = $false It "Should call the SPServiceInstance update method" { Set-TargetResource @testParams - $Global:SPDscSPServiceInstanceUpdateCalled | Should Be $true + $Global:SPDscSPServiceInstanceUpdateCalled | Should Be $true + } + } + + Context -Name "Search Service is not set to use the specified identity" -Fixture { + $testParams = @{ + Name = "SharePoint Server Search" + ManagedAccount = "CONTOSO\svc.search" + } + + Mock -CommandName Get-SPEnterpriseSearchService -MockWith { + $EnterpriseSearchService = @{} + + $EnterpriseSearchService = $EnterpriseSearchService | Add-Member -MemberType ScriptMethod -Name get_ProcessIdentity -Value { + $ProcessIdentity = @{ + CurrentIdentityType = "account" + Username = "CONTOSO\wrong_account" + } + + $ProcessIdentity = $ProcessIdentity | Add-Member -MemberType ScriptMethod -Name Update -Value { + $Global:SPDscSPServiceInstanceUpdateCalled = $true + } -PassThru + + $ProcessIdentity = $ProcessIdentity | Add-Member -MemberType ScriptMethod -Name Deploy -Value { + } -PassThru + + return $ProcessIdentity + } -PassThru + + return $EnterpriseSearchService + } + + It "Should return the current identity from the get method" { + (Get-TargetResource @testParams).ManagedAccount | Should Not BeNullOrEmpty + } + + It "Should return false for the test method" { + Test-TargetResource @testParams | Should Be $false } + $Global:SPDscSPServiceInstanceUpdateCalled = $false + It "Should call the SPServiceInstance update method" { + Set-TargetResource @testParams + $Global:SPDscSPServiceInstanceUpdateCalled | Should Be $true + } + } + + Context -Name "Search Service is not set to use the LocalSystem" -Fixture { + $testParams = @{ + Name = "SharePoint Server Search" + ManagedAccount = "LocalSystem" + } + + Mock -CommandName Get-SPEnterpriseSearchService -MockWith { + $EnterpriseSearchService = @{} + + $EnterpriseSearchService = $EnterpriseSearchService | Add-Member -MemberType ScriptMethod -Name get_ProcessIdentity -Value { + $ProcessIdentity = @{ + CurrentIdentityType = "LocalService" + Username = "CONTOSO\wrong_account" + } + + $ProcessIdentity = $ProcessIdentity | Add-Member -MemberType ScriptMethod -Name Update -Value { + $Global:SPDscSPServiceInstanceUpdateCalled = $true + } -PassThru + + $ProcessIdentity = $ProcessIdentity | Add-Member -MemberType ScriptMethod -Name Deploy -Value { + } -PassThru + + return $ProcessIdentity + } -PassThru + + return $EnterpriseSearchService + } + + It "Should return the current identity from the get method" { + (Get-TargetResource @testParams).ManagedAccount | Should Not BeNullOrEmpty + } + + It "Should return false for the test method" { + Test-TargetResource @testParams | Should Be $false + } + + $Global:SPDscSPServiceInstanceUpdateCalled = $false + It "Should call the SPServiceInstance update method" { + Set-TargetResource @testParams + $Global:SPDscSPServiceInstanceUpdateCalled | Should Be $true + } } Context -Name "Invalid Service Specified" -Fixture { - + $testParams = @{ Name = "No Such Windows Token Service" ManagedAccount = "CONTOSO\svc.c2wts" } - Mock -CommandName Get-SPServiceInstance -MockWith { + Mock -CommandName Get-SPServiceInstance -MockWith { return $null } - - It "Should return null from the get method" { + + It "Should return null from the get method" { (Get-TargetResource @testParams).ManagedAccount | Should BeNullOrEmpty - + } It "Should return false for the test method" { @@ -146,7 +230,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Context -Name "Invalid managed account specified" -Fixture { - + $testParams = @{ Name = "Claims to Windows Token Service" ManagedAccount = "CONTOSO\svc.badAccount" @@ -156,7 +240,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $null } - Mock -CommandName Get-SPServiceInstance -MockWith { + Mock -CommandName Get-SPServiceInstance -MockWith { $ProcessIdentity = @{ username = "CONTOSO\svc.c2wts" } @@ -174,13 +258,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { processidentity = $ProcessIdentity } } - + return $ServiceIdentity } - - It "Should return the current identity from the get method" { + + It "Should return the current identity from the get method" { (Get-TargetResource @testParams).ManagedAccount | Should Not BeNullOrEmpty - + } It "Should return false for the test method" { @@ -193,7 +277,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Context -Name "Service does not support setting process identity" -Fixture { - + $testParams = @{ Name = "Machine Translation Service" ManagedAccount = "CONTOSO\svc.mts" @@ -202,19 +286,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPManagedAccount -MockWith { return $null } - - Mock -CommandName Get-SPServiceInstance -MockWith { + + Mock -CommandName Get-SPServiceInstance -MockWith { $ServiceIdentity = @{ TypeName = $testParams.Name Service = @{ TypeName = $testParams.Name } } - + return $ServiceIdentity } - - It "Should return null for the current identity from the get method" { + + It "Should return null for the current identity from the get method" { (Get-TargetResource @testParams).ManagedAccount | Should BeNullOrEmpty } @@ -223,7 +307,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should throw an error for the set method" { - Mock -CommandName Get-SPManagedAccount -MockWith { + Mock -CommandName Get-SPManagedAccount -MockWith { return "CONTOSO\svc.mts" } {Set-TargetResource @testParams} | Should throw "Service $($testParams.name) does not support setting the process identity" diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 index eeb90b4ea..8c6eb1d09 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 @@ -2,7 +2,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -33,23 +33,23 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { UserProfileService = "User Profile Service Application" DisplayName = "WorkEmailNew" Type = "String (Single Value)" - Description = "" + Description = "" PolicySetting = "Mandatory" PrivacySetting = "Public" MappingConnectionName = "contoso" MappingPropertyName = "department" MappingDirection = "Import" Length = 30 - DisplayOrder = 5496 + DisplayOrder = 5496 IsEventLog =$false IsVisibleOnEditor=$true IsVisibleOnViewer = $true IsUserEditable = $true IsAlias = $false - IsSearchable = $false + IsSearchable = $false TermStore = "Managed Metadata service" TermGroup = "People" - TermSet = "Department" + TermSet = "Department" UserOverridePrivacy = $false } @@ -71,26 +71,26 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsVisibleOnEditor=$True IsVisibleOnViewer = $true IsUserEditable = $true - IsAlias = $true - IsSearchable = $true + IsAlias = $true + IsSearchable = $true TermStore = "Managed Metadata service" TermGroup = "People" - TermSet = "Location" + TermSet = "Location" UserOverridePrivacy = $false } - + try { [Microsoft.Office.Server.UserProfiles] } catch { Add-Type @" namespace Microsoft.Office.Server.UserProfiles { public enum ConnectionType { ActiveDirectory, BusinessDataCatalog }; public enum ProfileType { User}; - } + } "@ -ErrorAction SilentlyContinue - } - - $corePropertyUpdate = @{ - DisplayName = "WorkEmailUpdate" + } + + $corePropertyUpdate = @{ + DisplayName = "WorkEmailUpdate" Name = "WorkEmailUpdate" IsMultiValued=$false Type = "String (Single Value)" @@ -123,18 +123,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPCoreRemovePropertyByNameCalled = $true } -PassThru | Add-Member ScriptMethod Add { $Global:SPUPCoreAddCalled = $true - } -PassThru -Force - - # $coreProperties.Add($coreProperty) + } -PassThru -Force + $typePropertyUpdate = @{ IsVisibleOnViewer=$true IsVisibleOnEditor=$true IsEventLog=$true }| Add-Member ScriptMethod Commit { $Global:SPUPPropertyCommitCalled = $true - } -PassThru - - #$typeProperties.Add($typeProperty) + } -PassThru + $subTypePropertyUpdate = @{ Name= "WorkEmailUpdate" DisplayName="WorkEmailUpdate" @@ -149,10 +147,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { UserOverridePrivacy=$false; }| Add-Member ScriptMethod Commit { $Global:SPUPPropertyCommitCalled = $true - } -PassThru + } -PassThru - $coreProperty = @{ + $coreProperty = @{ DisplayName = $testParamsNewProperty.DisplayName Name = $testParamsNewProperty.Name IsMultiValued=$testParamsNewProperty.Type -eq "String (Multi Value)" @@ -174,13 +172,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsEventLog=$testParamsNewProperty.IsEventLog }| Add-Member ScriptMethod Commit { $Global:SPUPPropertyCommitCalled = $true - } -PassThru + } -PassThru $subTypeProperty = @{ Name= $testParamsNewProperty.Name DisplayName= $testParamsNewProperty.DisplayName Description = $testParamsNewProperty.Description - PrivacyPolicy = $testParamsNewProperty.PolicySetting + PrivacyPolicy = $testParamsNewProperty.PolicySetting DefaultPrivacy = $testParamsNewProperty.PrivateSetting DisplayOrder =$testParamsNewProperty.DisplayOrder IsUserEditable= $testParamsNewProperty.IsUserEditable @@ -190,7 +188,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { AllowPolicyOverride=$true; }| Add-Member ScriptMethod Commit { $Global:SPUPPropertyCommitCalled = $true - } -PassThru + } -PassThru $userProfileSubTypePropertiesNoProperty = @{} | Add-Member ScriptMethod Create { $Global:SPUPSubTypeCreateCalled = $true } -PassThru | Add-Member ScriptMethod GetPropertyByName { @@ -202,7 +200,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $result } -PassThru| Add-Member ScriptMethod Add { $Global:SPUPSubTypeAddCalled = $true - } -PassThru -Force + } -PassThru -Force $userProfileSubTypePropertiesUpdateProperty = @{"WorkEmailUpdate" = $subTypePropertyUpdate } | Add-Member ScriptMethod Create { $Global:SPUPSubTypeCreateCalled = $true @@ -219,11 +217,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesNoProperty } - } -PassThru + } -PassThru return $result } - + Mock -CommandName Get-SPWebApplication -MockWith { return @( @@ -231,51 +229,51 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsAdministrationWebApplication=$true Url ="caURL" }) - } + } #IncludeCentralAdministration $TermSets =@{Department = @{Name="Department" } Location = @{Name="Location" - } - } - + } + } + $TermGroups = @{People = @{Name="People" - TermSets = $TermSets + TermSets = $TermSets }} $TermStoresList = @{"Managed Metadata service" = @{Name="Managed Metadata service" - Groups = $TermGroups - }} + Groups = $TermGroups + }} Mock -CommandName New-Object -MockWith { return (@{ TermStores = $TermStoresList }) - } -ParameterFilter { $TypeName -eq "Microsoft.SharePoint.Taxonomy.TaxonomySession" } + } -ParameterFilter { $TypeName -eq "Microsoft.SharePoint.Taxonomy.TaxonomySession" } Mock -CommandName New-Object -MockWith { return (@{ Properties = @{} | Add-Member ScriptMethod SetDisplayOrderByPropertyName { $Global:UpsSetDisplayOrderByPropertyNameCalled=$true; - return $false; + return $false; } -PassThru | Add-Member ScriptMethod CommitDisplayOrder { $Global:UpsSetDisplayOrderByPropertyNameCalled=$true; - return $false; + return $false; } -PassThru }) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileManager" } - Mock Invoke-SPDSCCommand { + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileManager" } + Mock Invoke-SPDSCCommand { return Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments -NoNewScope } - - + + $propertyMappingItem = @{ DataSourcePropertyName="mail" IsImport=$true IsExport=$false } | Add-Member ScriptMethod Delete { $Global:UpsMappingDeleteCalled=$true; - return $true; + return $true; } -PassThru $propertyMapping = @{}| Add-Member ScriptMethod Item { @@ -285,13 +283,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $propertyMappingItem} } -PassThru -force | Add-Member ScriptMethod AddNewExportMapping { $Global:UpsMappingAddNewExportCalled=$true; - return $true; + return $true; } -PassThru | Add-Member ScriptMethod AddNewMapping { $Global:UpsMappingAddNewMappingCalled=$true; - return $true; - } -PassThru - $connection = @{ - DisplayName = "Contoso" + return $true; + } -PassThru + $connection = @{ + DisplayName = "Contoso" Server = "contoso.com" AccountDomain = "Contoso" AccountUsername = "TestAccount" @@ -305,7 +303,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPSSyncConnectionAddPropertyMappingCalled = $true } -PassThru - + $ConnnectionManager = @($connection) | Add-Member ScriptMethod AddActiveDirectoryConnection{ ` param([Microsoft.Office.Server.UserProfiles.ConnectionType] $connectionType, ` $name, ` @@ -316,54 +314,63 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $namingContext, ` $p1, $p2 ` ) - + $Global:SPUPSAddActiveDirectoryConnectionCalled =$true } -PassThru - - + + Mock -CommandName New-Object -MockWith { $ProfilePropertyManager = @{"Contoso" = $connection} | Add-Member ScriptMethod GetCoreProperties { $Global:UpsConfigManagerGetCorePropertiesCalled=$true; - return ($coreProperties); + return ($coreProperties); } -PassThru | Add-Member ScriptMethod GetProfileTypeProperties { $Global:UpsConfigManagerGetProfileTypePropertiesCalled=$true; - return $userProfileSubTypePropertiesUpdateProperty; - } -PassThru + return $userProfileSubTypePropertiesUpdateProperty; + } -PassThru return (@{ ProfilePropertyManager = $ProfilePropertyManager - ConnectionManager = $ConnnectionManager + ConnectionManager = $ConnnectionManager } | Add-Member ScriptMethod IsSynchronizationRunning { $Global:UpsSyncIsSynchronizationRunning=$true; - return $false; + return $false; } -PassThru ) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } - + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + $userProfileServiceValidConnection = @{ Name = "User Profile Service Application" TypeName = "User Profile Service Application" ApplicationPool = "SharePoint Service Applications" - FarmAccount = $farmAccount + FarmAccount = $farmAccount ServiceApplicationProxyGroup = "Proxy Group" - ConnectionManager= @($connection) + ConnectionManager= @($connection) + } + + Context -Name "Non-Existing User Profile Service Application" { + Mock -CommandName Get-SPServiceApplication { return $null } + It "Should return Ensure = Absent" { + $Global:SPUPGetProfileSubtypeCalled = $false + $Global:SPUPGetPropertyByNameCalled = $false + $Global:SPUPSMappingItemCalled = $false + (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" + } } Mock -CommandName Get-SPServiceApplication { return $userProfileServiceValidConnection } - Context -Name "When property doesn't exist" { - + It "Should return null from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsNewProperty | Should Be $false @@ -372,11 +379,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "creates a new user profile property in the set method" { $Global:SPUPGetProfileSubtypeCalled = $false - + $Global:SPUPSMappingItemCalled = $false Set-TargetResource @testParamsNewProperty $Global:SPUPGetProfileSubtypeCalled | Should be $true - + $Global:SPUPSMappingItemCalled | Should be $true } @@ -388,31 +395,31 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $ProfilePropertyManager = @{"Contoso" = $connection} | Add-Member ScriptMethod GetCoreProperties { $Global:UpsConfigManagerGetCorePropertiesCalled=$true; - return ($coreProperties); + return ($coreProperties); } -PassThru | Add-Member ScriptMethod GetProfileTypeProperties { $Global:UpsConfigManagerGetProfileTypePropertiesCalled=$true; - return $userProfileSubTypePropertiesUpdateProperty; - } -PassThru + return $userProfileSubTypePropertiesUpdateProperty; + } -PassThru return (@{ ProfilePropertyManager = $ProfilePropertyManager - ConnectionManager = $() + ConnectionManager = $() } | Add-Member ScriptMethod IsSynchronizationRunning { $Global:UpsSyncIsSynchronizationRunning=$true; - return $false; + return $false; } -PassThru ) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } It "Should return null from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsNewProperty | Should Be $false @@ -431,14 +438,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPSMappingItemCalled | Should be $false } - - - - } Context -Name "When property doesn't exist, term set doesn't exist" { - $termSet = $testParamsNewProperty.TermSet + $termSet = $testParamsNewProperty.TermSet $testParamsNewProperty.TermSet = "Invalid" It "Should return null from the Get method" { @@ -446,12 +449,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsNewProperty | Should Be $false @@ -469,7 +472,61 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $testParamsNewProperty.TermSet = $termSet + } + Context -Name "When required values are not all passed" { + $testParamsNewProperty.TermGroup = $null + It "Should throw error from Set method" { + { Set-TargetResource @testParamsNewProperty } | Should throw "Term Group not found" + } + } + + Context -Name "When ConfigurationManager is null" { + Mock -CommandName New-Object -MockWith { + $ProfilePropertyManager = @{"Contoso" = $connection} | Add-Member ScriptMethod GetCoreProperties { + $Global:UpsConfigManagerGetCorePropertiesCalled=$true; + + return ($coreProperties); + } -PassThru | Add-Member ScriptMethod GetProfileTypeProperties { + $Global:UpsConfigManagerGetProfileTypePropertiesCalled=$true; + return $userProfileSubTypePropertiesUpdateProperty; + } -PassThru + return (@{ + ProfilePropertyManager = $ProfilePropertyManager + ConnectionManager = $null + } | Add-Member ScriptMethod IsSynchronizationRunning { + $Global:UpsSyncIsSynchronizationRunning=$true; + return $false; + } -PassThru ) + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + + It "Should return Ensure = Absent from the Get method"{ + (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" + } + } + + Context -Name "When Sync Connection is set to Export" { + Mock -CommandName New-Object -MockWith { + $ProfilePropertyManager = @{"Contoso" = $connection} | Add-Member ScriptMethod GetCoreProperties { + $Global:UpsConfigManagerGetCorePropertiesCalled=$true; + + return ($coreProperties); + } -PassThru | Add-Member ScriptMethod GetProfileTypeProperties { + $Global:UpsConfigManagerGetProfileTypePropertiesCalled=$true; + return $userProfileSubTypePropertiesUpdateProperty; + } -PassThru + return (@{ + ProfilePropertyManager = $ProfilePropertyManager + ConnectionManager = $null + } | Add-Member ScriptMethod IsSynchronizationRunning { + $Global:UpsSyncIsSynchronizationRunning=$true; + return $false; + } -PassThru ) + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + + It "Should return Ensure = Absent from the Get method"{ + (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" + } } Context -Name "When property doesn't exist, term group doesn't exist" { @@ -481,12 +538,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsNewProperty | Should Be $false @@ -504,7 +561,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $testParamsNewProperty.TermGroup = $termGroup - } Context -Name "When property doesn't exist, term store doesn't exist" { @@ -516,12 +572,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsNewProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsNewProperty | Should Be $false @@ -539,11 +595,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $testParamsNewProperty.TermStore = $termStore - - } - Context -Name "When property exists and all properties match" { Mock -CommandName Get-SPDSCUserProfileSubTypeManager -MockWith { $result = @{}| Add-Member ScriptMethod GetProfileSubtype { @@ -551,22 +604,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesUpdateProperty } - } -PassThru + } -PassThru return $result } - + It "Should return valid value from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Present" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $true } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsUpdateProperty | Should Be $true @@ -579,10 +632,17 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Set-TargetResource @testParamsUpdateProperty $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $true - } + It "Should throw an error if the MappingDirection is set to Export" { + $testParamsExport = $testParamsUpdateProperty + $connection.Type = "ActiveDirectoryImport" + $testParamsExport.MappingDirection = "Export" + $propertyMappingItem.IsImport = $true + { Set-TargetResource @testParamsExport } | Should throw "not implemented" + $connection.Type = "ActiveDirectory" + } } Context -Name "When property exists and type is different - throws exception" { @@ -594,22 +654,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesUpdateProperty } - } -PassThru + } -PassThru return $result } - + It "Should return valid value from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Present" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $true } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsUpdateProperty | Should Be $false @@ -628,11 +688,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPSMappingItemCalled | Should be $false } $testParamsUpdateProperty.Type = $currentType - } Context -Name "When property exists and mapping exists, mapping config does not match" { - + $propertyMappingItem.DataSourcePropertyName = "property" Mock -CommandName Get-SPDSCUserProfileSubTypeManager -MockWith { @@ -641,22 +700,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesUpdateProperty } - } -PassThru + } -PassThru return $result } - + It "Should return valid value from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Present" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $true } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsUpdateProperty | Should Be $false @@ -675,7 +734,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPSMappingItemCalled | Should be $true } } - Context -Name "When property exists and mapping does not " { + Context -Name "When property exists and mapping does not exist" { $propertyMappingItem=$null Mock -CommandName Get-SPDSCUserProfileSubTypeManager -MockWith { $result = @{}| Add-Member ScriptMethod GetProfileSubtype { @@ -683,22 +742,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesUpdateProperty } - } -PassThru + } -PassThru return $result } - + It "Should return valid value from the Get method" { $Global:SPUPGetProfileSubtypeCalled = $false $Global:SPUPGetPropertyByNameCalled = $false $Global:SPUPSMappingItemCalled = $false (Get-TargetResource @testParamsNewProperty).Ensure | Should Be "Present" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParamsUpdateProperty.UserProfileService } $Global:SPUPGetProfileSubtypeCalled | Should be $true $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $true } - + It "Should return false when the Test method is called" { $Global:SPUPGetPropertyByNameCalled = $false Test-TargetResource @testParamsUpdateProperty | Should Be $false @@ -725,7 +784,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesUpdateProperty } - } -PassThru + } -PassThru return $result } @@ -742,7 +801,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPUPGetPropertyByNameCalled | Should be $true $Global:SPUPSMappingItemCalled | Should be $false $Global:SPUPCoreRemovePropertyByNameCalled | Should be $true - } + } } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 index 5acdfa36d..362b5e65b 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -22,21 +22,26 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Name = "PersonalInformation" UserProfileService = "User Profile Service Application" DisplayName = "Personal Information" - DisplayOrder = 5000 + DisplayOrder = 5000 } - + try { [Microsoft.Office.Server.UserProfiles] } catch { - Add-Type -TypeDefinition @" + try { + Add-Type -TypeDefinition @" namespace Microsoft.Office.Server.UserProfiles { public enum ConnectionType { ActiveDirectory, BusinessDataCatalog }; public enum ProfileType { User}; - } + } "@ -ErrorAction SilentlyContinue - } + } + catch { + Write-Verbose -Message "The Type was already added." + } + } + - - $coreProperty = @{ + $coreProperty = @{ DisplayName = $testParams.DisplayName Name = $testParams.Name } | Add-Member -MemberType ScriptMethod Commit { @@ -64,7 +69,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return $result } -PassThru| Add-Member -MemberType ScriptMethod -Name Add -Value { $Global:SPUPSubTypeAddCalled = $true - } -PassThru -Force + } -PassThru -Force $coreProperties = @{ProfileInformation = $coreProperty} $userProfileSubTypePropertiesProperty = @{"ProfileInformation" = $subTypeProperty } | Add-Member -MemberType ScriptMethod Create { $Global:SPUPSubTypeCreateCalled = $true @@ -77,11 +82,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesNoProperty } - } -PassThru + } -PassThru return $result } - + Mock -CommandName Set-SPDscObjectPropertyIfValuePresent -MockWith {return ;} Mock -CommandName Get-SPWebApplication -MockWith { return @( @@ -89,13 +94,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsAdministrationWebApplication=$true Url ="caURL" }) - } - + } + Mock -CommandName New-Object -MockWith { - $ProfilePropertyManager = @{"Contoso" = $connection} + $ProfilePropertyManager = @{"Contoso" = $connection} return (@{ ProfilePropertyManager = $ProfilePropertyManager - ConnectionManager = $ConnnectionManager + ConnectionManager = $ConnnectionManager } | Add-Member -MemberType ScriptMethod GetPropertiesWithSection { $Global:UpsConfigManagerGetPropertiesWithSectionCalled=$true; @@ -116,24 +121,24 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $Global:UpsConfigManagerGetSectionByNameCalled=$true return $result - return $userProfileSubTypePropertiesUpdateProperty; + return $userProfileSubTypePropertiesUpdateProperty; } -PassThru | Add-Member -MemberType ScriptMethod SetDisplayOrderBySectionName { $Global:UpsConfigManagerSetDisplayOrderBySectionNameCalled=$true; - return $userProfileSubTypePropertiesUpdateProperty; + return $userProfileSubTypePropertiesUpdateProperty; } -PassThru | Add-Member -MemberType ScriptMethod CommitDisplayOrder { $Global:UpsConfigManagerCommitDisplayOrderCalled=$true; - return $userProfileSubTypePropertiesUpdateProperty; + return $userProfileSubTypePropertiesUpdateProperty; } -PassThru| Add-Member -MemberType ScriptMethod RemoveSectionByName { $Global:UpsConfigManagerRemoveSectionByNameCalled=$true; - return ($coreProperties); - } -PassThru + return ($coreProperties); + } -PassThru -) +) return $result } -PassThru ) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } - + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + $userProfileService = @{ Name = "User Profile Service Application" TypeName = "User Profile Service Application" @@ -143,16 +148,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPServiceApplication -MockWith { return $userProfileService } - + Context -Name "When section doesn't exist" { - + It "Should return null from the Get method" { $Global:UpsConfigManagerGetSectionByNameCalled = $false (Get-TargetResource @testParams).Ensure | Should Be "Absent" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } $Global:UpsConfigManagerGetSectionByNameCalled | Should be $true } - + It "Should return false when the Test method is called" { $Global:UpsConfigManagerGetSectionByNameCalled = $false Test-TargetResource @testParams | Should Be $false @@ -166,7 +171,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Set-TargetResource @testParams $Global:SPUPSubTypeCreateCalled | should be $false - $Global:SPUPSPropertyCommitCalled|should be $true + $Global:SPUPSPropertyCommitCalled|should be $true $Global:UpsConfigManagerSetDisplayOrderBySectionNameCalled | Should be $true } @@ -174,11 +179,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Context -Name "When section exists and all properties match" { It "Should return valid value from the Get method" { $Global:UpsConfigManagerGetSectionByNameCalled = $true - - (Get-TargetResource @testParams).Ensure | Should Be "Present" + + (Get-TargetResource @testParams).Ensure | Should Be "Present" $Global:UpsConfigManagerGetSectionByNameCalled | Should be $true } - + It "Should return true when the Test method is called" { Test-TargetResource @testParams | Should Be $true } @@ -190,7 +195,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:UpsConfigManagerSetDisplayOrderBySectionNameCalled | Should be $true } } - + Context -Name "When section exists and ensure equals Absent" { Mock -CommandName Get-SPDSCUserProfileSubTypeManager -MockWith { $result = @{}| Add-Member -MemberType ScriptMethod GetProfileSubtype { @@ -198,7 +203,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesProperty } - } -PassThru + } -PassThru return $result } @@ -214,9 +219,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "deletes an user profile property in the set method" { $Global:UpsConfigManagerGetSectionByNameCalled = $true $Global:UpsConfigManagerRemoveSectionByNameCalled=$false - Set-TargetResource @testParams + Set-TargetResource @testParams $Global:UpsConfigManagerRemoveSectionByNameCalled | Should be $true - } + } } @@ -227,7 +232,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { return @{ Properties = $userProfileSubTypePropertiesProperty } - } -PassThru + } -PassThru return $result } $testParams.Ensure = "Present" @@ -236,11 +241,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should return valid value from the Get method" { $Global:SPUPGetSectionByNameCalled = $true - $currentValues = Get-TargetResource @testParams + $currentValues = Get-TargetResource @testParams $currentValues.Ensure | Should Be "Present" - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } } - + It "Should return false when the Test method is called" { $Global:SPUPGetSectionByNameCalled = $true Test-TargetResource @testParams | Should Be $false diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 index b78afb412..7c7c56e07 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -20,18 +20,18 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Initialize tests - # Mocks for all contexts - Mock -CommandName New-SPClaimsPrincipal -MockWith { + # Mocks for all contexts + Mock -CommandName New-SPClaimsPrincipal -MockWith { return @{ Value = $Identity -replace "i:0#.w\|" } } -ParameterFilter { $IdentityType -eq "EncodedClaim" } - Mock -CommandName New-SPClaimsPrincipal -MockWith { + Mock -CommandName New-SPClaimsPrincipal -MockWith { $Global:SPDscClaimsPrincipalUser = $Identity return ( - New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ToEncodedString { - return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" + New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ToEncodedString { + return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" } -PassThru ) } -ParameterFilter { $IdentityType -eq "WindowsSamAccountName" } @@ -275,6 +275,39 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Set-SPProfileServiceApplicationSecurity } } + + Context -Name "Passing empty values for non-mandatory parameters" -Fixture { + $testParams = @{ + ProxyName = "User Profile Service App Proxy" + } + + Mock -CommandName Get-SPProfileServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "i:0#.w|DEMO\User2" + AllowedRights = "CreatePersonalSite,UseMicrobloggingAndFollowing" + }, + @{ + Name = "i:0#.w|DEMO\User1" + AllowedRights = "CreatePersonalSite,UseMicrobloggingAndFollowing" + }, + @{ + Name = "c:0(.s|true" + AllowedRights = "UsePersonalFeatures" + } + ) + } + } + + It "Should return the current permissions correctly" { + Get-TargetResource @testParams + } + + It "Should return true in the test method" { + Test-TargetResource @testParams | Should Be $true + } + } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 index b6be408af..a205af4ef 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 @@ -2,7 +2,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -26,16 +26,23 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { try { [Microsoft.Office.Server.UserProfiles] } catch { - Add-Type -TypeDefinition @" + try { + Add-Type -TypeDefinition @" namespace Microsoft.Office.Server.UserProfiles { public enum ConnectionType { ActiveDirectory, BusinessDataCatalog }; public enum ProfileType { User}; - } -"@ -ErrorAction SilentlyContinue + } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose "The Type Microsoft.Office.Server.UserProfile was already added." + } + } try { [Microsoft.Office.Server.UserProfiles.DirectoryServiceNamingContext] } catch { - Add-Type -TypeDefinition @" + try { + Add-Type -TypeDefinition @" namespace Microsoft.Office.Server.UserProfiles { public class DirectoryServiceNamingContext { public DirectoryServiceNamingContext(System.Object a, System.Object b, System.Object c, System.Object d, System.Object e, System.Object f, System.Object g, System.Object h) @@ -44,44 +51,54 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } } -"@ - } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose -Message "The Type Microsoft.Office.Server.UserProfiles.DirectoryServiceNamingContext was already added." + } + + } try { [Microsoft.Office.Server.UserProfiles.ActiveDirectoryImportConnection] } catch { - Add-Type -TypeDefinition @" + try { + Add-Type -TypeDefinition @" namespace Microsoft.Office.Server.UserProfiles{ public class ActiveDirectoryImportConnection{ public ActiveDirectoryImportConnection(){ - + } public static System.Object GetMethod(System.Object a, System.Object b) - {return new ActiveDirectoryImportConnection();} - + {return new ActiveDirectoryImportConnection();} + public System.Object Invoke(System.Object a, System.Object b) {return "";} } - } -"@ -ErrorAction SilentlyContinue + } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose -Message "The Type Microsoft.Office.Server.UserProfiles.ActiveDirectoryImportConnection was already added." + } } - # Mocks for all contexts + # Mocks for all contexts Mock -CommandName Add-SPProfileSyncConnection -MockWith { $Global:SPDscUPSAddActiveDirectoryConnectionCalled = $true } - Mock -CommandName Get-SPDSCServiceContext -MockWith { - return @{} + Mock -CommandName Get-SPDSCServiceContext -MockWith { + return @{} } Mock -CommandName Start-Sleep -MockWith { } - - Mock -CommandName Get-SPWebapplication -MockWith { + + Mock -CommandName Get-SPWebapplication -MockWith { return @{ Url = "http://ca" IsAdministrationWebApplication = $true } } - $connection = @{ - DisplayName = "Contoso" + $connection = @{ + DisplayName = "Contoso" Server = "contoso.com" NamingContexts = New-Object -TypeName System.Collections.ArrayList AccountDomain = "Contoso" @@ -92,7 +109,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Name RefreshSchema ` -Value { $Global:SPDscUPSSyncConnectionRefreshSchemaCalled = $true - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { @@ -103,55 +120,55 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Value { param($userAccount,$securePassword) $Global:SPDscUPSSyncConnectionSetCredentialsCalled = $true - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod ` -Name Delete ` -Value { $Global:SPDscUPSSyncConnectionDeleteCalled = $true } -PassThru - $namingContext =@{ - ContainersIncluded = New-Object -TypeName System.Collections.ArrayList - ContainersExcluded = New-Object -TypeName System.Collections.ArrayList - DisplayName = "Contoso" + $namingContext =@{ + ContainersIncluded = New-Object -TypeName System.Collections.ArrayList + ContainersExcluded = New-Object -TypeName System.Collections.ArrayList + DisplayName = "Contoso" PreferredDomainControllers = $null } $namingContext.ContainersIncluded.Add("OU=com, OU=Contoso, OU=Included") $namingContext.ContainersExcluded.Add("OU=com, OU=Contoso, OU=Excluded") $connection.NamingContexts.Add($namingContext); - - $ConnnectionManager = New-Object -TypeName System.Collections.ArrayList | + + $ConnnectionManager = New-Object -TypeName System.Collections.ArrayList | Add-Member -MemberType ScriptMethod ` -Name AddActiveDirectoryConnection ` - -Value { + -Value { param( - [Microsoft.Office.Server.UserProfiles.ConnectionType] - $connectionType, - $name, - $forest, - $useSSL, - $userName, - $securePassword, - $namingContext, - $p1, - $p2 + [Microsoft.Office.Server.UserProfiles.ConnectionType] + $connectionType, + $name, + $forest, + $useSSL, + $userName, + $securePassword, + $namingContext, + $p1, + $p2 ) $Global:SPDscUPSAddActiveDirectoryConnectionCalled = $true } -PassThru - + Mock -CommandName New-Object -MockWith { return (@{ - ConnectionManager = $ConnnectionManager + ConnectionManager = $ConnnectionManager } | Add-Member -MemberType ScriptMethod ` -Name IsSynchronizationRunning ` -Value { $Global:SPDscUpsSyncIsSynchronizationRunning = $true return $false } -PassThru - )} -ParameterFilter { - $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" - } - + )} -ParameterFilter { + $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" + } + $userProfileServiceValidConnection = @{ Name = "User Profile Service Application" TypeName = "User Profile Service Application" @@ -161,7 +178,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ConnectionManager= New-Object -TypeName System.Collections.ArrayList } $userProfileServiceValidConnection.ConnectionManager.Add($connection) - + Mock -CommandName Get-SPDSCADSIObject -MockWith { return @{ distinguishedName = "DC=Contoso,DC=Com" @@ -169,8 +186,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Mock -CommandName Import-Module {} -ParameterFilter { - $_.Name -eq $ModuleName + Mock -CommandName Import-Module {} -ParameterFilter { + $_.Name -eq $ModuleName } # Test contexts @@ -185,7 +202,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IncludedOUs = @("OU=SharePoint Users,DC=Contoso,DC=com") ConnectionType = "ActiveDirectory" } - + $userProfileServiceNoConnections = @{ Name = "User Profile Service Application" ApplicationPool = "SharePoint Service Applications" @@ -195,12 +212,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPServiceApplication -MockWith { return $userProfileServiceNoConnections } - + It "Should return null from the Get method" { Get-TargetResource @testParams | Should BeNullOrEmpty - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } } - + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } @@ -224,17 +241,17 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ConnectionType = "ActiveDirectory" } - Mock -CommandName Get-SPServiceApplication -MockWith { - return $userProfileServiceValidConnection + Mock -CommandName Get-SPServiceApplication -MockWith { + return $userProfileServiceValidConnection } - + $ConnnectionManager.Add($connection) - + It "Should return service instance from the Get method" { Get-TargetResource @testParams | Should Not BeNullOrEmpty - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } } - + It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } @@ -247,7 +264,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPDscUPSSyncConnectionRefreshSchemaCalled | Should be $true } } - + Context -Name "When connection exists and forest is different" -Fixture { $testParams = @{ UserProfileService = "User Profile Service Application" @@ -261,7 +278,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $litWareconnection = @{ - DisplayName = "Contoso" + DisplayName = "Contoso" Server = "litware.net" NamingContexts= New-Object -TypeName System.Collections.ArrayList AccountDomain = "Contoso" @@ -284,8 +301,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $userProfileServiceValidConnection.ConnectionManager.Add($litWareconnection); - Mock -CommandName Get-SPServiceApplication -MockWith { - return $userProfileServiceValidConnection + Mock -CommandName Get-SPServiceApplication -MockWith { + return $userProfileServiceValidConnection } $litwareConnnectionManager = New-Object -TypeName System.Collections.ArrayList | Add-Member -MemberType ScriptMethod AddActiveDirectoryConnection{ ` param([Microsoft.Office.Server.UserProfiles.ConnectionType] $connectionType, ` @@ -299,19 +316,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) $Global:SPDscUPSAddActiveDirectoryConnectionCalled =$true - } -PassThru + } -PassThru $litwareConnnectionManager.Add($litWareconnection) Mock -CommandName New-Object -MockWith { return (@{} | Add-Member -MemberType ScriptMethod IsSynchronizationRunning { $Global:SPDscUpsSyncIsSynchronizationRunning=$true; - return $false; + return $false; } -PassThru | Add-Member ConnectionManager $litwareConnnectionManager -PassThru ) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } - + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + It "Should return service instance from the Get method" { Get-TargetResource @testParams | Should Not BeNullOrEmpty - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } } It "Should return false when the Test method is called" { @@ -335,11 +352,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IncludedOUs = @("OU=SharePoint Users,DC=Contoso,DC=com") ConnectionType = "ActiveDirectory" } - + It "delete and create as force is specified" { $Global:SPDscUPSSyncConnectionDeleteCalled=$false $Global:SPDscUPSAddActiveDirectoryConnectionCalled =$false - Set-TargetResource @forceTestParams + Set-TargetResource @forceTestParams $Global:SPDscUPSSyncConnectionDeleteCalled | Should be $true $Global:SPDscUPSAddActiveDirectoryConnectionCalled | Should be $true } @@ -357,15 +374,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ConnectionType = "ActiveDirectory" } - Mock -CommandName Get-SPServiceApplication -MockWith { + Mock -CommandName Get-SPServiceApplication -MockWith { return @( New-Object -TypeName "Object" | Add-Member -MemberType NoteProperty ` -Name ServiceApplicationProxyGroup ` -Value "Proxy Group" ` - -PassThru + -PassThru ) } - + Mock -CommandName New-Object -MockWith { return (@{} | Add-Member -MemberType ScriptMethod ` -Name IsSynchronizationRunning ` @@ -373,21 +390,21 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $Global:SPDscUpsSyncIsSynchronizationRunning=$true; return $true } -PassThru) - } -ParameterFilter { - $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" - } + } -ParameterFilter { + $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" + } It "attempts to execute method but synchronization is running" { $Global:SPDscUpsSyncIsSynchronizationRunning=$false $Global:SPDscUPSAddActiveDirectoryConnectionCalled =$false { Set-TargetResource @testParams }| Should throw Assert-MockCalled Get-SPServiceApplication - Assert-MockCalled New-Object -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + Assert-MockCalled New-Object -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } $Global:SPDscUpsSyncIsSynchronizationRunning| Should be $true; $Global:SPDscUPSAddActiveDirectoryConnectionCalled | Should be $false; } } - + Context -Name "When connection exists and Excluded and Included OUs are different. force parameter provided" -Fixture { $testParams = @{ UserProfileService = "User Profile Service Application" @@ -421,8 +438,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } -PassThru -Force } -PassThru -Force $userProfileServiceValidConnection.ConnectionManager.Add($connection); - Mock -CommandName Get-SPServiceApplication -MockWith { - return $userProfileServiceValidConnection + Mock -CommandName Get-SPServiceApplication -MockWith { + return $userProfileServiceValidConnection } $difOUsTestParams = @{ @@ -440,7 +457,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should return values from the get method" { Get-TargetResource @difOUsTestParams | Should Not BeNullOrEmpty - Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } + Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.UserProfileService } } It "Should return false when the Test method is called" { @@ -471,14 +488,14 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $litWareconnection = @{ - DisplayName = "Contoso" + DisplayName = "Contoso" Server = "litware.net" NamingContexts= New-Object -TypeName System.Collections.ArrayList AccountDomain = "Contoso" AccountUsername = "TestAccount" Type= "ActiveDirectory" } - + $userProfileServiceValidConnection = @{ Name = "User Profile Service Application" TypeName = "User Profile Service Application" @@ -489,8 +506,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } $userProfileServiceValidConnection.ConnectionManager.Add($litWareconnection); - Mock -CommandName Get-SPServiceApplication -MockWith { - return $userProfileServiceValidConnection + Mock -CommandName Get-SPServiceApplication -MockWith { + return $userProfileServiceValidConnection } $litwareConnnectionManager = New-Object -TypeName System.Collections.ArrayList | Add-Member -MemberType ScriptMethod AddActiveDirectoryConnection{ ` param([Microsoft.Office.Server.UserProfiles.ConnectionType] $connectionType, ` @@ -504,21 +521,21 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) $Global:SPDscUPSAddActiveDirectoryConnectionCalled =$true - } -PassThru + } -PassThru $litwareConnnectionManager.Add($litWareconnection) Mock -CommandName New-Object -MockWith { return (@{} | Add-Member -MemberType ScriptMethod IsSynchronizationRunning { $Global:SPDscUpsSyncIsSynchronizationRunning=$true; - return $false; + return $false; } -PassThru | Add-Member ConnectionManager $litwareConnnectionManager -PassThru ) - } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } - - + } -ParameterFilter { $TypeName -eq "Microsoft.Office.Server.UserProfiles.UserProfileConfigManager" } + + It "Should return values from the get method" { Get-TargetResource @testParams | Should Not BeNullOrEmpty - } + } } } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 index 00c5862ad..b2fd14d1e 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -21,189 +21,220 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Initialize tests $getTypeFullName = "Microsoft.Office.Server.WorkManagement.WorkManagementServiceApplication" - # Mocks for all contexts + # Mocks for all contexts Mock -CommandName Remove-SPServiceApplication -MockWith { } Mock -CommandName New-SPWorkManagementServiceApplication -MockWith { } Mock -CommandName New-SPWorkManagementServiceApplicationProxy -MockWith { } # Test contexts - Context -Name "When a service application exists and Ensure equals 'Absent'" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - Ensure = "Absent" - } + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Context -Name "When a service application exists and Ensure equals 'Absent'" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + Ensure = "Absent" + } - Mock -CommandName Get-SPServiceApplication { - $spServiceApp = [pscustomobject]@{ - DisplayName = $testParams.Name - ApplicationPool = @{ Name = "Wrong App Pool Name" } + Mock -CommandName Get-SPServiceApplication { + $spServiceApp = [pscustomobject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = "Wrong App Pool Name" } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = $getTypeFullName } + } -PassThru -Force + return $spServiceApp } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } - } -PassThru -Force - return $spServiceApp - } - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } - It "Should call the remove service app cmdlet from the set method" { - Set-TargetResource @testParams - Assert-MockCalled Remove-SPServiceApplication + It "Should call the remove service app cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + } } - } - Context -Name "When Ensure=Present and ApplicationPool parameter is missing" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - Ensure = "Present" - } + Context -Name "When Ensure=Present and ApplicationPool parameter is missing" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + Ensure = "Present" + } - Mock -CommandName Get-SPServiceApplication { return $null } + Mock -CommandName Get-SPServiceApplication { return $null } - It "Should throw an exception in the set method" { - { Set-TargetResource @testParams } | Should throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" + It "Should throw an exception in the set method" { + { Set-TargetResource @testParams } | Should throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" + } } - } - Context -Name "When no service applications exist in the current farm" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - ApplicationPool = "Test App Pool" - ProxyName = "Test Work Management App Proxy" - } + Context -Name "When no service applications exist in the current farm" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + ApplicationPool = "Test App Pool" + ProxyName = "Test Work Management App Proxy" + } - Mock -CommandName Get-SPServiceApplication { return $null } - - It "Should return null from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } + Mock -CommandName Get-SPServiceApplication { return $null } - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } + It "Should return null from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } - It "Should create a new service application in the set method" { - Set-TargetResource @testParams - Assert-MockCalled New-SPWorkManagementServiceApplication - } - } - - Context -Name "When service applications exist in the current farm but the specific Work Management app does not" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - ApplicationPool = "Test App Pool" - } - - Mock -CommandName Get-SPServiceApplication { - $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 false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPWorkManagementServiceApplication + } } - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } + Context -Name "When service applications exist in the current farm but the specific Work Management app does not" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + ApplicationPool = "Test App Pool" + } - It "Should create a new service application in the set method" { - Set-TargetResource @testParams - Assert-MockCalled New-SPWorkManagementServiceApplication - } - } + Mock -CommandName Get-SPServiceApplication { + $spServiceApp = [pscustomobject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = "Microsoft.Office.UnKnownWebServiceApplication" } + } -PassThru -Force + return $spServiceApp + } - Context -Name "When a service application exists and is configured correctly" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - ApplicationPool = "Test App Pool" - MinimumTimeBetweenEwsSyncSubscriptionSearches =10 - MinimumTimeBetweenProviderRefreshes=10 - MinimumTimeBetweenSearchQueries=10 - NumberOfSubscriptionSyncsPerEwsSyncRun=10 - NumberOfUsersEwsSyncWillProcessAtOnce=10 - NumberOfUsersPerEwsSyncBatch=10 + 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-SPWorkManagementServiceApplication + } } - Mock -CommandName Get-SPServiceApplication { - $spServiceApp = [pscustomobject]@{ - DisplayName = $testParams.Name - ApplicationPool = @{ Name = $testParams.ApplicationPool } - AdminSettings = @{ - MinimumTimeBetweenEwsSyncSubscriptionSearches = (new-timespan -minutes 10) - MinimumTimeBetweenProviderRefreshes= (new-timespan -minutes 10) - MinimumTimeBetweenSearchQueries= (new-timespan -minutes 10) - NumberOfSubscriptionSyncsPerEwsSyncRun=10 - NumberOfUsersEwsSyncWillProcessAtOnce= 10 - NumberOfUsersPerEwsSyncBatch= 10 + Context -Name "When a service application exists and is configured correctly" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + ApplicationPool = "Test App Pool" + MinimumTimeBetweenEwsSyncSubscriptionSearches =10 + MinimumTimeBetweenProviderRefreshes=10 + MinimumTimeBetweenSearchQueries=10 + NumberOfSubscriptionSyncsPerEwsSyncRun=10 + NumberOfUsersEwsSyncWillProcessAtOnce=10 + NumberOfUsersPerEwsSyncBatch=10 + } + + Mock -CommandName Get-SPServiceApplication { + $spServiceApp = [pscustomobject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = $testParams.ApplicationPool } + AdminSettings = @{ + MinimumTimeBetweenEwsSyncSubscriptionSearches = (new-timespan -minutes 10) + MinimumTimeBetweenProviderRefreshes= (new-timespan -minutes 10) + MinimumTimeBetweenSearchQueries= (new-timespan -minutes 10) + NumberOfSubscriptionSyncsPerEwsSyncRun=10 + NumberOfUsersEwsSyncWillProcessAtOnce= 10 + NumberOfUsersPerEwsSyncBatch= 10 + } } + $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = $getTypeFullName } + } -PassThru -Force + return $spServiceApp } - $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } - } -PassThru -Force - return $spServiceApp - } - It "Should return values from the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" - } + It "Should return values 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 return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } } - } - Context -Name "When a service application exists and is not configured correctly" -Fixture { - $testParams = @{ - Name = "Test Work Management App" - ApplicationPool = "Test App Pool" - MinimumTimeBetweenEwsSyncSubscriptionSearches =20 - MinimumTimeBetweenProviderRefreshes=20 - MinimumTimeBetweenSearchQueries=20 - NumberOfSubscriptionSyncsPerEwsSyncRun=20 - NumberOfUsersEwsSyncWillProcessAtOnce=20 - NumberOfUsersPerEwsSyncBatch=20 - } - - Mock -CommandName Get-SPServiceApplication { - $spServiceApp = [pscustomobject]@{ - DisplayName = $testParams.Name - ApplicationPool = @{ Name = "Wrong App Pool Name" } - AdminSettings = @{ - MinimumTimeBetweenEwsSyncSubscriptionSearches = (new-timespan -minutes 10) - MinimumTimeBetweenProviderRefreshes= (new-timespan -minutes 10) - MinimumTimeBetweenSearchQueries= (new-timespan -minutes 10) - NumberOfSubscriptionSyncsPerEwsSyncRun=10 - NumberOfUsersEwsSyncWillProcessAtOnce= 10 - NumberOfUsersPerEwsSyncBatch= 10 + Context -Name "When a service application exists and is not configured correctly" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + ApplicationPool = "Test App Pool" + MinimumTimeBetweenEwsSyncSubscriptionSearches =20 + MinimumTimeBetweenProviderRefreshes=20 + MinimumTimeBetweenSearchQueries=20 + NumberOfSubscriptionSyncsPerEwsSyncRun=20 + NumberOfUsersEwsSyncWillProcessAtOnce=20 + NumberOfUsersPerEwsSyncBatch=20 + } + + Mock -CommandName Get-SPServiceApplication { + $spServiceApp = [pscustomobject]@{ + DisplayName = $testParams.Name + ApplicationPool = @{ Name = "Wrong App Pool Name" } + AdminSettings = @{ + MinimumTimeBetweenEwsSyncSubscriptionSearches = (new-timespan -minutes 10) + MinimumTimeBetweenProviderRefreshes= (new-timespan -minutes 10) + MinimumTimeBetweenSearchQueries= (new-timespan -minutes 10) + NumberOfSubscriptionSyncsPerEwsSyncRun=10 + NumberOfUsersEwsSyncWillProcessAtOnce= 10 + NumberOfUsersPerEwsSyncBatch= 10 + } } + $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return @{ FullName = $getTypeFullName } + } -PassThru -Force + return $spServiceApp } - $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return @{ FullName = $getTypeFullName } - } -PassThru -Force - return $spServiceApp - } - Mock -CommandName Set-SPWorkManagementServiceApplication { } + Mock -CommandName Set-SPWorkManagementServiceApplication { } - It "Should return values from the get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" - } + It "Should return values from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false + 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-SPWorkManagementServiceApplication + Assert-MockCalled Get-SPServiceApplication + } } + } - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams - Assert-MockCalled Set-SPWorkManagementServiceApplication - Assert-MockCalled Get-SPServiceApplication + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Context -Name "Trying to use SPWorkManagementServiceApp in SP2016, not available" -Fixture { + $testParams = @{ + Name = "Test Work Management App" + ApplicationPool = "Test App Pool" + MinimumTimeBetweenEwsSyncSubscriptionSearches =20 + MinimumTimeBetweenProviderRefreshes=20 + MinimumTimeBetweenSearchQueries=20 + NumberOfSubscriptionSyncsPerEwsSyncRun=20 + NumberOfUsersEwsSyncWillProcessAtOnce=20 + NumberOfUsersPerEwsSyncBatch=20 + } + + It "Should throw an exception in the Get method" { + { Get-TargetResource @testParams } | Should throw "Work Management Service Application is no longer available in SharePoint 2016" + } + + It "Should throw an exception in the Test method" { + { Test-TargetResource @testParams } | Should throw "Work Management Service Application is no longer available in SharePoint 2016" + } + + It "Should throw an exception in the Set method" { + { Set-TargetResource @testParams } | Should throw "Work Management Service Application is no longer available in SharePoint 2016" + } } } } diff --git a/appveyor.yml b/appveyor.yml index 0705763f5..5a37fd3b4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,17 +1,17 @@ -version: 1.8.0.{build} +version: 2.1.0.{build} image: WMF 5 install: - git clone https://github.com/PowerShell/DscResource.Tests - - npm --silent install + - npm --silent install - ps: | $moduleName = 'SharePointDsc' $mainModuleFolder = "Modules\$moduleName" Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" Invoke-AppveyorInstallTask - + build: off test_script: