diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c12898f..c68108640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- SharePointDsc + - Added logging to the event log when the code throws an exception + ## [4.3.0] - 2020-09-30 ### Added diff --git a/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 b/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 index 0d591144f..946b8d81f 100644 --- a/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPAlternateUrl/MSFT_SPAlternateUrl.psm1 @@ -108,9 +108,10 @@ function Set-TargetResource if ($Ensure -eq "Present") { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $webapp = Get-SPWebApplication -IncludeCentralAdministration | Where-Object -FilterScript { $_.DisplayName -eq $params.WebAppName @@ -118,7 +119,12 @@ function Set-TargetResource if ($null -eq $webapp) { - throw "Web application was not found. Please check WebAppName parameter!" + $message = "Web application was not found. Please check WebAppName parameter!" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $urlAam = Get-SPAlternateURL -Identity $params.Url ` @@ -147,8 +153,13 @@ function Set-TargetResource } else { - throw ("Specified URL found on different WebApp/Zone: WebApp " + ` + $message = ("Specified URL found on different WebApp/Zone: WebApp " + ` "$($urlAam.PublicUrl) in zone $($urlAam.Zone)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -190,8 +201,13 @@ function Set-TargetResource } else { - throw ("Specified URL ($($params.Url)) found on different WebApp/Zone: " + ` + $message = ("Specified URL ($($params.Url)) found on different WebApp/Zone: " + ` "WebApp $($urlAam.PublicUrl) in zone $($urlAam.Zone)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -205,8 +221,13 @@ function Set-TargetResource } else { - throw ("Specified URL found on different WebApp/Zone: WebApp " + ` + $message = ("Specified URL found on different WebApp/Zone: WebApp " + ` "$($urlAam.PublicUrl) in zone $($urlAam.Zone)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else diff --git a/SharePointDsc/DSCResources/MSFT_SPAntivirusSettings/MSFT_SPAntivirusSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPAntivirusSettings/MSFT_SPAntivirusSettings.psm1 index e6f79d6ff..d70d00c3d 100644 --- a/SharePointDsc/DSCResources/MSFT_SPAntivirusSettings/MSFT_SPAntivirusSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPAntivirusSettings/MSFT_SPAntivirusSettings.psm1 @@ -124,9 +124,10 @@ function Set-TargetResource Write-Verbose -Message "Setting antivirus configuration settings" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -134,8 +135,12 @@ function Set-TargetResource } catch { - throw "No local SharePoint farm was detected. Antivirus settings will not be applied" - return + $message = "No local SharePoint farm was detected. Antivirus settings will not be applied" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Start update" diff --git a/SharePointDsc/DSCResources/MSFT_SPAppCatalog/MSFT_SPAppCatalog.psm1 b/SharePointDsc/DSCResources/MSFT_SPAppCatalog/MSFT_SPAppCatalog.psm1 index 39783bcfa..c1d91f87c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPAppCatalog/MSFT_SPAppCatalog.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPAppCatalog/MSFT_SPAppCatalog.psm1 @@ -79,9 +79,14 @@ function Set-TargetResource # InstallAccount used if ($InstallAccount.UserName -eq $farmAccount.UserName) { - throw ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` + $message = ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -93,16 +98,26 @@ function Set-TargetResource $localaccount = "$($Env:USERDOMAIN)\$($Env:USERNAME)" if ($localaccount -eq $farmAccount.UserName) { - throw ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` + $message = ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` "Account. Make sure the specified PSDSCRunAsCredential isn't the " + ` "Farm Account and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } } else { - throw ("Unable to retrieve the Farm Account. Check if the farm exists.") + $message = "Unable to retrieve the Farm Account. Check if the farm exists." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Add the FarmAccount to the local Administrators group, if it's not already there @@ -121,18 +136,25 @@ function Set-TargetResource } Invoke-SPDscCommand -Credential $farmAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + try { Update-SPAppCatalogConfiguration -Site $params.SiteUrl -Confirm:$false } catch [System.UnauthorizedAccessException] { - throw ("This resource must be run as the farm account (not a setup account). " + ` + $message = ("This resource must be run as the farm account (not a setup account). " + ` "Please ensure either the PsDscRunAsCredential or InstallAccount " + ` "credentials are set to the farm account and run this resource again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } | Out-Null diff --git a/SharePointDsc/DSCResources/MSFT_SPAppStoreSettings/MSFT_SPAppStoreSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPAppStoreSettings/MSFT_SPAppStoreSettings.psm1 index 788ae4793..eb112688a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPAppStoreSettings/MSFT_SPAppStoreSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPAppStoreSettings/MSFT_SPAppStoreSettings.psm1 @@ -77,14 +77,20 @@ function Set-TargetResource Write-Verbose -Message "Setting app store settings of $WebAppUrl" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters,$MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw ("Specified web application does not exist.") + $message = "Specified web application does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("AllowAppPurchases")) diff --git a/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/MSFT_SPBCSServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/MSFT_SPBCSServiceApp.psm1 index 8b53f59fb..7df39a259 100644 --- a/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/MSFT_SPBCSServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPBCSServiceApp/MSFT_SPBCSServiceApp.psm1 @@ -146,7 +146,12 @@ function Set-TargetResource ($PSBoundParameters.ContainsKey("DatabaseName") -eq $false -or $PSBoundParameters.ContainsKey("DatabaseServer") -eq $false)) { - throw "Parameter DatabaseName and DatabaseServer are required when Ensure=Present" + $message = "Parameter DatabaseName and DatabaseServer are required when Ensure=Present" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 index f398c6f23..8edeaecd9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPBlobCacheSettings/MSFT_SPBlobCacheSettings.psm1 @@ -41,9 +41,10 @@ function Get-TargetResource Write-Verbose -Message "Getting blob cache settings for $WebAppUrl" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $webappsi = Get-SPServiceInstance -Server $env:COMPUTERNAME ` -ErrorAction SilentlyContinue ` @@ -109,7 +110,12 @@ function Get-TargetResource } catch { - throw "Error: $($_.Exception.Message)" + $message = "Error: $($_.Exception.Message)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } try @@ -122,7 +128,12 @@ function Get-TargetResource } catch { - throw "Error: $($_.Exception.Message)" + $message = "Error: $($_.Exception.Message)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $returnval = @{ @@ -229,10 +240,11 @@ function Set-TargetResource { ## Perform changes Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $changes) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $changes) ` -ScriptBlock { $params = $args[0] - $changes = $args[1] + $eventSource = $args[1] + $changes = $args[2] $webappsi = Get-SPServiceInstance -Server $env:COMPUTERNAME ` -ErrorAction SilentlyContinue ` @@ -243,14 +255,24 @@ function Set-TargetResource if ($null -eq $webappsi) { - throw "Server isn't running the Web Application role" + $message = "Server isn't running the Web Application role" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Specified web application could not be found." + $message = "Specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Processing changes" @@ -305,11 +327,21 @@ function Set-TargetResource } catch [DriveNotFoundException] { - throw "Specified drive does not exist" + $message = "Specified drive does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } catch { - throw "Error creating Blob Cache folder: $($_.Exception.Message)" + $message = "Error creating Blob Cache folder: $($_.Exception.Message)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 b/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 index ea4378665..5a2c6f46d 100644 --- a/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPCacheAccounts/MSFT_SPCacheAccounts.psm1 @@ -166,13 +166,21 @@ function Set-TargetResource $PSBoundParameters.SetWebAppPolicy = $SetWebAppPolicy - Invoke-SPDscCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { + Invoke-SPDscCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` + -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw [Exception] "The web applications $($params.WebAppUrl) can not be found to set cache accounts" + $message = "The web applications $($params.WebAppUrl) can not be found to set cache accounts" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($wa.UseClaimsAuthentication -eq $true) diff --git a/SharePointDsc/DSCResources/MSFT_SPConfigWizard/MSFT_SPConfigWizard.psm1 b/SharePointDsc/DSCResources/MSFT_SPConfigWizard/MSFT_SPConfigWizard.psm1 index bbd098e75..fab968773 100644 --- a/SharePointDsc/DSCResources/MSFT_SPConfigWizard/MSFT_SPConfigWizard.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPConfigWizard/MSFT_SPConfigWizard.psm1 @@ -171,23 +171,43 @@ function Set-TargetResource if ($upgradeTimes.Count -ne 3) { - throw "Time window incorrectly formatted." + $message = "Time window incorrectly formatted." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { if ([datetime]::TryParse($upgradeTimes[0], [ref]$starttime) -ne $true) { - throw "Error converting start time" + $message = "Error converting start time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ([datetime]::TryParse($upgradeTimes[2], [ref]$endtime) -ne $true) { - throw "Error converting end time" + $message = "Error converting end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($starttime -gt $endtime) { - throw "Error: Start time cannot be larger than end time" + $message = "Error: Start time cannot be larger than end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -262,9 +282,14 @@ function Set-TargetResource } Default { - throw ("SharePoint Post Setup Configuration Wizard failed, " + ` + $message = ("SharePoint Post Setup Configuration Wizard failed, " + ` "exit code was $result. Error codes can be found at " + ` "https://aka.ms/installerrorcodes") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 b/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 index 54097b18e..60308b1f5 100644 --- a/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPContentDatabase/MSFT_SPContentDatabase.psm1 @@ -152,9 +152,10 @@ function Set-TargetResource $PSBoundParameters.Ensure = $Ensure Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] # Use Get-SPDatabase instead of Get-SPContentDatabase because the Get-SPContentDatabase # does not return disabled databases. @@ -172,7 +173,12 @@ function Set-TargetResource if ($null -eq $webapp) { - throw "Specified web application does not exist." + $message = "Specified web application does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Check if database exists @@ -180,9 +186,14 @@ function Set-TargetResource { if ($params.ContainsKey('DatabaseServer') -and $params.DatabaseServer -ne $null -and $cdb.Server -ne $params.DatabaseServer) { - throw ("Specified database server does not match the actual database " + ` + $message = ("Specified database server does not match the actual database " + ` "server. This resource cannot move the database to a different " + ` "SQL instance.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Check and change attached web application. @@ -218,9 +229,14 @@ function Set-TargetResource } catch { - throw ("Error occurred while mounting content database. " + ` + $message = ("Error occurred while mounting content database. " + ` "Content database is not mounted. " + ` "Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($cdb.Status -eq "Online") @@ -314,9 +330,14 @@ function Set-TargetResource } catch { - throw ("Error occurred while mounting content database. " + ` + $message = ("Error occurred while mounting content database. " + ` "Content database is not mounted. " + ` "Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($cdb.Status -eq "Online") diff --git a/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/MSFT_SPDatabaseAAG.psm1 b/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/MSFT_SPDatabaseAAG.psm1 index f288d0a13..69a213c70 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/MSFT_SPDatabaseAAG.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDatabaseAAG/MSFT_SPDatabaseAAG.psm1 @@ -32,9 +32,14 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -eq 15 ` -and (Get-SPDscInstalledProductVersion).FileBuildPart -lt 4605) { - throw [Exception] ("Adding databases to SQL Always-On Availability Groups " + ` + $message = ("Adding databases to SQL Always-On Availability Groups " + ` "require the SharePoint 2013 April 2014 CU to be installed. " + ` "http://support.microsoft.com/kb/2880551") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Ensure -eq "Present") @@ -158,18 +163,24 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -eq 15 ` -and (Get-SPDscInstalledProductVersion).FileBuildPart -lt 4605) { - throw [Exception] ("Adding databases to SQL Always-On Availability Groups " + ` + $message = ("Adding databases to SQL Always-On Availability Groups " + ` "require the SharePoint 2013 April 2014 CU to be installed. " + ` "http://support.microsoft.com/kb/2880551") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Ensure -eq "Present") { Write-Verbose -Message "Checking AAG settings for $DatabaseName" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments ($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $databases = Get-SPDatabase | Where-Object -FilterScript { $_.Name -like $params.DatabaseName @@ -218,7 +229,12 @@ function Set-TargetResource } else { - throw "Specified database(s) not found." + $message = "Specified database(s) not found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -226,9 +242,10 @@ function Set-TargetResource { Write-Verbose -Message "Removing $DatabaseName from $AGName" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $databases = Get-SPDatabase | Where-Object -FilterScript { $_.Name -like $params.DatabaseName @@ -245,7 +262,12 @@ function Set-TargetResource } else { - throw "Specified database(s) not found." + $message = "Specified database(s) not found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 index 2fb038e05..e86d53af9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDesignerSettings/MSFT_SPDesignerSettings.psm1 @@ -174,9 +174,14 @@ function Get-TargetResource } else { - throw ("A known issue exists that prevents these settings from being managed " + ` + $message = ("A known issue exists that prevents these settings from being managed " + ` "when InstallAccount is used instead of PsDscRunAsAccount. See " + ` - "http://aka.ms/xSharePointRemoteIssues for details.") + "http://aka.ms/SharePointDscRemoteIssues for details.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -238,9 +243,10 @@ function Set-TargetResource "WebApplication" { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -248,9 +254,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. SharePoint " + ` + $message = ("No local SharePoint farm was detected. SharePoint " + ` "Designer settings will not be applied") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Start update SPD web application settings" @@ -261,9 +271,13 @@ function Set-TargetResource } if ($null -eq $webapp) { - throw ("Web application not found. SharePoint Designer settings " + ` + $message = ("Web application not found. SharePoint Designer settings " + ` "will not be applied") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { @@ -308,9 +322,10 @@ function Set-TargetResource if ((Test-SPDscRunAsCredential -Credential $InstallAccount) -eq $true) { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -318,9 +333,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. SharePoint Designer " + ` + $message = ("No local SharePoint farm was detected. SharePoint Designer " + ` "settings will not be applied") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Start update SPD site collection settings" @@ -329,9 +348,13 @@ function Set-TargetResource $site = Get-SPSite -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $site) { - throw ("Site collection not found. SharePoint Designer settings " + ` + $message = ("Site collection not found. SharePoint Designer settings " + ` "will not be applied") - return $null + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { @@ -372,9 +395,14 @@ function Set-TargetResource } else { - throw ("A known issue exists that prevents these settings from being " + ` + $message = ("A known issue exists that prevents these settings from being " + ` "managed when InstallAccount is used instead of PsDscRunAsAccount. " + ` - "See http://aka.ms/xSharePointRemoteIssues for details.") + "See http://aka.ms/SharePointDscRemoteIssues for details.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 b/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 index 297c9e468..ffcac5d87 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDiagnosticsProvider/MSFT_SPDiagnosticsProvider.psm1 @@ -96,18 +96,30 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw "This resource cannot remove Diagnostics Provider. Please use ensure equals Present." + $message = "This resource cannot remove Diagnostics Provider. Please use ensure equals Present." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + $diagnosticProvider = Get-SPDiagnosticsProvider | Where-Object { $_.Name -eq $params.Name } if ($null -eq $diagnosticProvider) { - throw "The specified Diagnostic Provider {" + $params.Name + "} could not be found." + $message = "The specified Diagnostic Provider {" + $params.Name + "} could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $newParams = @{ diff --git a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 index 0e0200c4e..7461dd126 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 @@ -215,12 +215,17 @@ function Get-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -eq 15) { - throw ("The following parameters are only supported in SharePoint 2016 and above: " + ` + $message = ("The following parameters are only supported in SharePoint 2016 and above: " + ` "DFLTCMaxConnectionsToServer, DFLTCRequestTimeout, DFLTCChannelOpenTimeOut, " + ` "DSWUCMaxConnectionsToServer, DSWUCRequestTimeout, DSWUCChannelOpenTimeOut, " + ` "DUGCMaxConnectionsToServer, DUGCRequestTimeout, DUGCChannelOpenTimeOut, " + ` "DRTCMaxConnectionsToServer, DRTCRequestTimeout, DRTCChannelOpenTimeOut, " + ` "DHSCMaxConnectionsToServer, DHSCRequestTimeout and DHSCChannelOpenTimeOut") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -571,12 +576,17 @@ function Set-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -eq 15) { - throw ("The following parameters are only supported in SharePoint 2016 and above: " + ` + $message = ("The following parameters are only supported in SharePoint 2016 and above: " + ` "DFLTCMaxConnectionsToServer, DFLTCRequestTimeout, DFLTCChannelOpenTimeOut, " + ` "DSWUCMaxConnectionsToServer, DSWUCRequestTimeout, DSWUCChannelOpenTimeOut, " + ` "DUGCMaxConnectionsToServer, DUGCRequestTimeout, DUGCChannelOpenTimeOut, " + ` "DRTCMaxConnectionsToServer, DRTCRequestTimeout, DRTCChannelOpenTimeOut, " + ` "DHSCMaxConnectionsToServer, DHSCRequestTimeout and DHSCChannelOpenTimeOut") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 index fd3c7ee9a..a65e164c9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheService/MSFT_SPDistributedCacheService.psm1 @@ -168,9 +168,10 @@ function Set-TargetResource { Write-Verbose -Message "Enabling distributed cache service" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.ContainsKey("ServerProvisionOrder")) { @@ -235,9 +236,16 @@ function Set-TargetResource if ($ServerCount -ge $params.ServerProvisionOrder.Length) { - throw ("The server $($env:COMPUTERNAME) was not found in the " + ` + $message = ("The server $($env:COMPUTERNAME) was not found in the " + ` "ServerProvisionOrder array of Distributed Cache server(s). " + ` - "The server must be included in ServerProvisionOrder or Ensure equal to Absent.") + "The server must be included in ServerProvisionOrder or Ensure " + ` + "equal to Absent.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message + } $currentServer = $params.ServerProvisionOrder[$serverCount] } @@ -334,7 +342,7 @@ function Set-TargetResource { if ($CurrentState.ServiceAccount -ne $ServiceAccount.UserName) { - Invoke-SPDSCCommand -Credential $InstallAccount ` + Invoke-SPDscCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] @@ -366,7 +374,7 @@ function Set-TargetResource if ($CurrentState.CacheSizeInMB -ne $CacheSizeInMB) { Write-Verbose -Message "Updating distributed cache service cache size" - Invoke-SPDSCCommand -Credential $InstallAccount ` + Invoke-SPDscCommand -Credential $InstallAccount ` -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] diff --git a/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 index ea53f22f7..4c674ee77 100644 --- a/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPExcelServiceApp/MSFT_SPExcelServiceApp.psm1 @@ -122,11 +122,16 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + $message = ("Only SharePoint 2013 is supported to deploy Excel Services " + ` "service applications via DSC, as SharePoint 2016 and SharePoint 2019 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -311,11 +316,16 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applications via DSC, as SharePoint 2016 and SharePoint 2019 have deprecated " + ` + $message = ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + "service applications via DSC, as SharePoint 2016 and SharePoint 2019 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters @@ -569,11 +579,16 @@ function Test-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy Excel Services " + ` - "service applications via DSC, as SharePoint 2016 and SharePoint 2019 have deprecated " + ` + $message = ("Only SharePoint 2013 is supported to deploy Excel Services " + ` + "service applications via DSC, as SharePoint 2016 and SharePoint 2019 deprecated " + ` "this service. See " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx " + ` "for more info.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index 637287a55..7546e5f89 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -96,7 +96,13 @@ function Get-TargetResource if ($Ensure -eq "Absent") { - throw "SharePointDsc does not support removing a server from a farm, please set the ensure property to 'present'" + $message = "SharePointDsc does not support removing a server from a farm, please set " + ` + "the ensure property to 'present'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $supportsSettingApplicationCredentialKey = $false @@ -111,7 +117,13 @@ function Get-TargetResource { if ($DeveloperDashboard -eq "OnDemand") { - throw "The DeveloperDashboard value 'OnDemand' is not allowed in SharePoint 2016 and 2019" + $message = "The DeveloperDashboard value 'OnDemand' is not allowed in SharePoint " + ` + "2016 and 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($DeveloperDashboard -eq "On") @@ -134,22 +146,37 @@ function Get-TargetResource } default { - throw ("Detected an unsupported major version of SharePoint. SharePointDsc only " + + $message = ("Detected an unsupported major version of SharePoint. SharePointDsc only " + "supports SharePoint 2013, 2016 or 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } if ($PSBoundParameters.ContainsKey("ApplicationCredentialKey") -and -not $supportsSettingApplicationCredentialKey) { - throw [Exception] ("Specifying ApplicationCredentialKey is only supported " + + $message = ("Specifying ApplicationCredentialKey is only supported " + "on SharePoint 2019") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and $installedVersion.FileMajorPart -ne 16) { - throw [Exception] "Server role is only supported in SharePoint 2016 and 2019." + $message = "Server role is only supported in SharePoint 2016 and 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and @@ -158,10 +185,15 @@ function Get-TargetResource ($ServerRole -eq "ApplicationWithSearch" -or $ServerRole -eq "WebFrontEndWithDistributedCache")) { - throw [Exception] ("ServerRole values of 'ApplicationWithSearch' or " + + $message = ("ServerRole values of 'ApplicationWithSearch' or " + "'WebFrontEndWithDistributedCache' require the SharePoint 2016 " + "Feature Pack 1 to be installed. See " + "https://support.microsoft.com/en-us/kb/3127940") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } @@ -423,8 +455,13 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw ("SharePointDsc does not support removing a server from a farm, please set the " + + $message = ("SharePointDsc does not support removing a server from a farm, please set the " + "ensure property to 'present'") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("CentralAdministrationUrl")) @@ -438,15 +475,27 @@ function Set-TargetResource $uri = $CentralAdministrationUrl -as [System.Uri] if ($null -eq $uri.AbsoluteUri -or $uri.scheme -notin ('http', 'https')) { - throw "CentralAdministrationUrl is not a valid URI. It should include the scheme (http/https) and address." + $message = "CentralAdministrationUrl is not a valid URI. It should include the " + ` + "scheme (http/https) and address." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("CentralAdministrationPort")) { if ($uri.Port -ne $CentralAdministrationPort) { - throw ("CentralAdministrationPort does not match port number specified in CentralAdministrationUrl. " + - "Either make the values match or don't specify CentralAdministrationPort.") + $message = ("CentralAdministrationPort does not match port number specified in " + ` + "CentralAdministrationUrl. Either make the values match or don't specify " + ` + "CentralAdministrationPort.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -484,9 +533,10 @@ function Set-TargetResource if ($CurrentValues.RunCentralAdmin -ne $RunCentralAdmin) { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] # Provision central administration if ($params.RunCentralAdmin -eq $true) @@ -510,7 +560,12 @@ function Set-TargetResource if ($null -eq $serviceInstance) { - throw [Exception] "Unable to locate Central Admin service instance on this server" + $message = "Unable to locate Central Admin service instance on this server" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Start-SPServiceInstance -Identity $serviceInstance } @@ -535,7 +590,12 @@ function Set-TargetResource if ($null -eq $serviceInstance) { - throw "Unable to locate Central Admin service instance on this server" + $message = "Unable to locate Central Admin service instance on this server" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Stop-SPServiceInstance -Identity $serviceInstance } @@ -685,10 +745,11 @@ function Set-TargetResource Write-Verbose -Message "Server not part of farm, creating or joining farm" $actionResult = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] + $eventSource = $args[1] + $scriptRoot = $args[2] $modulePath = "..\..\Modules\SharePointDsc.Farm\SPFarm.psm1" Import-Module -Name (Join-Path -Path $scriptRoot -ChildPath $modulePath -Resolve) @@ -709,7 +770,12 @@ function Set-TargetResource if ($sqlInstanceStatus.MaxDOPCorrect -ne $true) { - throw "The MaxDOP setting is incorrect. Please correct before continuing." + $message = "The MaxDOP setting is incorrect. Please correct before continuing." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $dbStatus = Get-SPDscConfigDBStatus -SQLServer $params.DatabaseServer ` @@ -729,7 +795,12 @@ function Set-TargetResource if ($dbStatus.ValidPermissions -eq $false) { - throw "The current user does not have sufficient permissions to SQL Server" + $message = "The current user does not have sufficient permissions to SQL Server" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $executeArgs = @{ @@ -795,17 +866,27 @@ function Set-TargetResource } Default { - throw [Exception] ("An unknown version of SharePoint (Major version $_) " + + $message = ("An unknown version of SharePoint (Major version $_) " + "was detected. Only versions 15 (SharePoint 2013) and" + "16 (SharePoint 2016 or SharePoint 2019) are supported.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } if ($params.ContainsKey("ApplicationCredentialKey") -and -not $supportsSettingApplicationCredentialKey) { - throw [Exception] ("Specifying ApplicationCredentialKey is only supported " + + $message = ("Specifying ApplicationCredentialKey is only supported " + "on SharePoint 2019") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($dbStatus.DatabaseExists -eq $true) @@ -901,7 +982,12 @@ function Set-TargetResource if ($connectedToFarm -eq $false) { Write-Verbose -Message ("Unable to join config database. Throwing exception.") - throw $lastException + $message = $lastException + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $farmAction = "JoinedFarm" } @@ -1049,7 +1135,12 @@ function Set-TargetResource if ($null -eq $serviceInstance) { - throw [Exception] "Unable to locate Central Admin service instance on this server" + $message = "Unable to locate Central Admin service instance on this server" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Start-SPServiceInstance -Identity $serviceInstance } @@ -1189,16 +1280,27 @@ function Test-TargetResource $uri = $CentralAdministrationUrl -as [System.Uri] if ($null -eq $uri.AbsoluteUri) { - throw ("CentralAdministrationUrl is not a valid URI. It should " + + $message = ("CentralAdministrationUrl is not a valid URI. It should " + "include the scheme (http/https) and address.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("CentralAdministrationPort")) { if ($uri.Port -ne $CentralAdministrationPort) { - throw ("CentralAdministrationPort does not match port number specified in CentralAdministrationUrl. " + - "Either make the values match or don't specify CentralAdministrationPort.") + $message = ("CentralAdministrationPort does not match port number specified " + ` + "in CentralAdministrationUrl. Either make the values match or don't " + ` + "specify CentralAdministrationPort.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPFarmAdministrators/MSFT_SPFarmAdministrators.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarmAdministrators/MSFT_SPFarmAdministrators.psm1 index fb2d32f82..8aff34c01 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarmAdministrators/MSFT_SPFarmAdministrators.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarmAdministrators/MSFT_SPFarmAdministrators.psm1 @@ -30,14 +30,24 @@ function Get-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the " + ` + $message = ("Cannot use the Members parameter together with the " + ` "MembersToInclude or MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "Members, MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -108,20 +118,35 @@ function Set-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the " + ` + $message = ("Cannot use the Members parameter together with the " + ` "MembersToInclude or MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "Members, MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters if ($null -eq $CurrentValues.Members) { - throw "Unable to locate central administration website" + $message = "Unable to locate central administration website" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $changeUsers = @{ } @@ -269,14 +294,24 @@ function Test-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the " + ` + $message = ("Cannot use the Members parameter together with the " + ` "MembersToInclude or MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "Members, MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters @@ -376,9 +411,10 @@ function Merge-SPDscFarmAdminList ) $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $changeUsers ` + -Arguments @($changeUsers, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $changeUsers = $args[0] + $eventSource = $args[1] $webApps = Get-SPWebApplication -IncludeCentralAdministration $caWebapp = $webApps | Where-Object -FilterScript { @@ -386,7 +422,12 @@ function Merge-SPDscFarmAdminList } if ($null -eq $caWebapp) { - throw "Unable to locate central administration website" + $message = "Unable to locate central administration website" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $caWeb = Get-SPWeb($caWebapp.Url) $farmAdminGroup = $caWeb.AssociatedOwnerGroup diff --git a/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/MSFT_SPFarmPropertyBag.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/MSFT_SPFarmPropertyBag.psm1 index 1b784d63f..60f1174c2 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/MSFT_SPFarmPropertyBag.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarmPropertyBag/MSFT_SPFarmPropertyBag.psm1 @@ -100,9 +100,10 @@ function Set-TargetResource() Write-Verbose -Message "Setting SPFarm property '$Name'" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -110,7 +111,12 @@ function Set-TargetResource() } catch { - throw "No local SharePoint farm was detected." + $message = "No local SharePoint farm was detected." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.Ensure -eq 'Present') diff --git a/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 b/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 index 965b002e7..678fbea4a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPHealthAnalyzerRuleState/MSFT_SPHealthAnalyzerRuleState.psm1 @@ -155,9 +155,10 @@ function Set-TargetResource Write-Verbose -Message "Setting Health Analyzer Rule configuration settings" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -165,8 +166,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. Health Analyzer Rule " + ` + $message = ("No local SharePoint farm was detected. Health Analyzer Rule " + ` "settings will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $caWebapp = Get-SPwebapplication -IncludeCentralAdministration ` @@ -176,8 +182,13 @@ function Set-TargetResource if ($null -eq $caWebapp) { - throw ("No Central Admin web application was found. Health Analyzer Rule " + ` + $message = ("No Central Admin web application was found. Health Analyzer Rule " + ` "settings will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Get Central Admin SPWeb @@ -215,15 +226,25 @@ function Set-TargetResource } else { - throw ("Could not find specified Health Analyzer Rule. Health Analyzer Rule " + ` + $message = ("Could not find specified Health Analyzer Rule. Health Analyzer Rule " + ` "settings will not be applied. Make sure any related service " + ` "applications exists") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else { - throw ("Could not find Health Analyzer Rules list. Health Analyzer Rule settings " + ` + $message = ("Could not find Health Analyzer Rules list. Health Analyzer Rule settings " + ` "will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPIncomingEmailSettings/MSFT_SPIncomingEmailSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPIncomingEmailSettings/MSFT_SPIncomingEmailSettings.psm1 index f0761d96e..7da154121 100644 --- a/SharePointDsc/DSCResources/MSFT_SPIncomingEmailSettings/MSFT_SPIncomingEmailSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPIncomingEmailSettings/MSFT_SPIncomingEmailSettings.psm1 @@ -200,35 +200,61 @@ function Set-TargetResource { if (-not $PSBoundParameters.containskey("UseAutomaticSettings")) { - throw "UseAutomaticSettings parameter must be specified when enabling incoming email." + $message = "UseAutomaticSettings parameter must be specified when enabling incoming email." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (-not $PSBoundParameters.containskey("ServerDisplayAddress")) { - throw "ServerDisplayAddress parameter must be specified when enabling incoming email" + $message = "ServerDisplayAddress parameter must be specified when enabling incoming email" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($PSBoundParameters.UseDirectoryManagementService -eq 'Remote' -and $null -eq $PSBoundParameters.RemoteDirectoryManagementURL) ` -or ($PSBoundParameters.containskey('RemoteDirectoryManagementURL') -and $PSBoundParameters.UseDirectoryManagementService -ne 'Remote')) { - throw "RemoteDirectoryManagementURL must be specified only when UseDirectoryManagementService is set to 'Remote'" + $message = "RemoteDirectoryManagementURL must be specified only when UseDirectoryManagementService is set to 'Remote'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.UseAutomaticSettings -eq $true -and $PSBoundParameters.containskey("DropFolder")) { - throw "DropFolder parameter is not valid when using Automatic Mode" + $message = "DropFolder parameter is not valid when using Automatic Mode" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.UseAutomaticSettings -eq $false -and (-not $PSBoundParameters.containskey("DropFolder"))) { - throw "DropFolder parameter must be specified when not using Automatic Mode" + $message = "DropFolder parameter must be specified when not using Automatic Mode" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $spEmailServiceInstance = (Get-SPServiceInstance | Where-Object { $_.GetType().FullName -eq "Microsoft.SharePoint.Administration.SPIncomingEmailServiceInstance" }) | Select-Object -First 1 $spEmailService = $spEmailServiceInstance.service @@ -236,7 +262,12 @@ function Set-TargetResource #some simple error checking, just incase we didn't capture the service for some reason if ($null -eq $spEmailService) { - throw "Error getting the SharePoint Incoming Email Service" + $message = "Error getting the SharePoint Incoming Email Service" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.Ensure -eq "Absent") diff --git a/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 b/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 index 16cb3db2b..794b8065e 100644 --- a/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPInfoPathFormsServiceConfig/MSFT_SPInfoPathFormsServiceConfig.psm1 @@ -208,8 +208,13 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw ("This resource cannot undo InfoPath Forms Service Configuration changes. " + ` + $message = ("This resource cannot undo InfoPath Forms Service Configuration changes. " + ` "Please set Ensure to Present or omit the resource") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPInstall/MSFT_SPInstall.psm1 b/SharePointDsc/DSCResources/MSFT_SPInstall/MSFT_SPInstall.psm1 index 758374256..38747c7ca 100644 --- a/SharePointDsc/DSCResources/MSFT_SPInstall/MSFT_SPInstall.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPInstall/MSFT_SPInstall.psm1 @@ -36,13 +36,23 @@ function Get-TargetResource Write-Verbose -Message "Check if Binary folder exists" if (-not(Test-Path -Path $BinaryDir)) { - throw "Specified path cannot be found: {$BinaryDir}" + $message = "Specified path cannot be found: {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $InstallerPath = Join-Path -Path $BinaryDir -ChildPath "setup.exe" if (-not(Test-Path -Path $InstallerPath)) { - throw "Setup.exe cannot be found in {$BinaryDir}" + $message = "Setup.exe cannot be found in {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $InstallerPath" @@ -84,8 +94,13 @@ function Get-TargetResource } if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $InstallerPath' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $InstallerPath' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -165,20 +180,35 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint or " + ` "its prerequisites. Please remove this manually.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Check if Binary folder exists" if (-not(Test-Path -Path $BinaryDir)) { - throw "Specified path cannot be found: {$BinaryDir}" + $message = "Specified path cannot be found: {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $InstallerPath = Join-Path -Path $BinaryDir -ChildPath "setup.exe" if (-not(Test-Path -Path $InstallerPath)) { - throw "Setup.exe cannot be found in {$BinaryDir}" + $message = "Setup.exe cannot be found in {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $majorVersion = (Get-SPDscAssemblyVersion -PathToAssembly $InstallerPath) @@ -215,10 +245,14 @@ function Set-TargetResource if ($dotNet46Installed -eq $true) { - throw [Exception] ("A known issue prevents installation of SharePoint 2013 on " + ` + $message = ("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 + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -262,8 +296,13 @@ function Set-TargetResource } if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $InstallerPath' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $InstallerPath' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -283,7 +322,12 @@ function Set-TargetResource } else { - throw "Cannot extract servername from UNC path. Check if it is in the correct format." + $message = "Cannot extract servername from UNC path. Check if it is in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Set-SPDscZoneMap -Server $serverName @@ -373,13 +417,23 @@ function Set-TargetResource } else { - throw ("SharePoint installation has failed due to an issue with prerequisites " + ` + $message = ("SharePoint installation has failed due to an issue with prerequisites " + ` "not being installed correctly. Please review the setup logs.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } Default { - throw "SharePoint install failed, exit code was $($setup.ExitCode)" + $message = "SharePoint install failed, exit code was $($setup.ExitCode)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -424,8 +478,13 @@ function Test-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint or " + ` "its prerequisites. Please remove this manually.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 b/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 index 775ea2bfa..a4f70c882 100644 --- a/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPInstallLanguagePack/MSFT_SPInstallLanguagePack.psm1 @@ -32,14 +32,24 @@ function Get-TargetResource Write-Verbose -Message "Check if Binary folder exists" if (-not(Test-Path -Path $BinaryDir)) { - throw "Specified path cannot be found: {$BinaryDir}" + $message = "Specified path cannot be found: {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of setup.exe" $setupExe = Join-Path -Path $BinaryDir -ChildPath "setup.exe" if (-not(Test-Path -Path $setupExe)) { - throw "Setup.exe cannot be found in {$BinaryDir}" + $message = "Setup.exe cannot be found in {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $setupExe" @@ -81,8 +91,13 @@ function Get-TargetResource } if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $setupExe' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $setupExe' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -92,7 +107,12 @@ function Get-TargetResource if ($osrvFolder.Count -ne 1) { - throw "Unknown folder structure" + $message = "Unknown folder structure" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $products = Get-SPDscRegProductsInfo @@ -160,7 +180,12 @@ function Get-TargetResource } else { - throw "Update does not contain the language code in the correct format." + $message = "Update does not contain the language code in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } try @@ -170,13 +195,23 @@ function Get-TargetResource } catch { - throw "Error while converting language information: $language" + $message = "Error while converting language information: $language" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # try/catch is required for some versions of Windows, other version use the LCID value of 4096 if ($cultureInfo.LCID -eq 4096) { - throw "Error while converting language information: $language" + $message = "Error while converting language information: $language" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Extract English name of the language code" @@ -287,22 +322,36 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint " + ` "Language Packs. Please remove this manually.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Check if Binary folder exists" if (-not(Test-Path -Path $BinaryDir)) { - throw "Specified path cannot be found: {$BinaryDir}" + $message = "Specified path cannot be found: {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of setup.exe" $setupExe = Join-Path -Path $BinaryDir -ChildPath "setup.exe" if (-not(Test-Path -Path $setupExe)) { - throw "Setup.exe cannot be found in {$BinaryDir}" + $message = "Setup.exe cannot be found in {$BinaryDir}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $setupExe" @@ -344,8 +393,13 @@ function Set-TargetResource } if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $setupExe' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $setupExe' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -384,23 +438,43 @@ function Set-TargetResource if ($upgradeTimes.Count -ne 3) { - throw "Time window incorrectly formatted." + $message = "Time window incorrectly formatted." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { if ([datetime]::TryParse($upgradeTimes[0], [ref]$starttime) -ne $true) { - throw "Error converting start time" + $message = "Error converting start time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ([datetime]::TryParse($upgradeTimes[2], [ref]$endtime) -ne $true) { - throw "Error converting end time" + $message = "Error converting end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($starttime -gt $endtime) { - throw "Error: Start time cannot be larger than end time" + $message = "Error: Start time cannot be larger than end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -436,7 +510,12 @@ function Set-TargetResource } else { - throw "Cannot extract servername from UNC path. Check if it is in the correct format." + $message = "Cannot extract servername from UNC path. Check if it is in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Set-SPDscZoneMap -Server $serverName @@ -500,7 +579,12 @@ function Set-TargetResource } Default { - throw "SharePoint Language Pack install failed, exit code was $($setup.ExitCode)" + $message = "SharePoint Language Pack install failed, exit code was $($setup.ExitCode)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -541,9 +625,13 @@ function Test-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint " + ` "Language Packs. Please remove this manually.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 b/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 index b22fd489f..faa57697d 100644 --- a/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPInstallPrereqs/MSFT_SPInstallPrereqs.psm1 @@ -199,7 +199,12 @@ function Get-TargetResource Write-Verbose -Message "Check if InstallerPath folder exists" if (-not(Test-Path -Path $InstallerPath)) { - throw "PrerequisitesInstaller cannot be found: {$InstallerPath}" + $message = "PrerequisitesInstaller cannot be found: {$InstallerPath}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $InstallerPath" @@ -241,8 +246,13 @@ function Get-TargetResource } if ($null -ne $zone) { - throw ("PrerequisitesInstaller is blocked! Please use 'Unblock-File -Path " + ` + $message = ("PrerequisitesInstaller is blocked! Please use 'Unblock-File -Path " + ` "$InstallerPath' to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -272,7 +282,12 @@ function Get-TargetResource { if ($osVersion.Major -ne 6) { - throw "SharePoint 2013 only supports Windows Server 2012 R2 and below" + $message = "SharePoint 2013 only supports Windows Server 2012 R2 and below" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $WindowsFeatures = Get-WindowsFeature -Name $Script:SP2013Features @@ -301,7 +316,12 @@ function Get-TargetResource } else { - throw "SharePoint 2016 only supports Windows Server 2019, 2016 or 2012 R2" + $message = "SharePoint 2016 only supports Windows Server 2019, 2016 or 2012 R2" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } # SharePoint 2019 @@ -322,7 +342,12 @@ function Get-TargetResource } else { - throw "SharePoint 2019 only supports Windows Server 2016 or Windows Server 2019" + $message = "SharePoint 2019 only supports Windows Server 2016 or Windows Server 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -607,14 +632,24 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or its " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint or its " + ` "prerequisites. Please remove this manually.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Check if InstallerPath folder exists" if (-not(Test-Path -Path $InstallerPath)) { - throw "PrerequisitesInstaller cannot be found: {$InstallerPath}" + $message = "PrerequisitesInstaller cannot be found: {$InstallerPath}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $InstallerPath" @@ -656,8 +691,13 @@ function Set-TargetResource } if ($null -ne $zone) { - throw ("PrerequisitesInstaller is blocked! Please use 'Unblock-File -Path " + ` + $message = ("PrerequisitesInstaller is blocked! Please use 'Unblock-File -Path " + ` "$InstallerPath' to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -707,7 +747,12 @@ function Set-TargetResource { if ($osVersion.Major -ne 6) { - throw "SharePoint 2013 only supports Windows Server 2012 R2 and below" + $message = "SharePoint 2013 only supports Windows Server 2012 R2 and below" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $BinaryDir = Split-Path -Path $InstallerPath @@ -742,9 +787,14 @@ function Set-TargetResource if ($dotNet46Installed -eq $true) { - throw [Exception] ("A known issue prevents installation of SharePoint 2013 on " + ` + $message = ("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") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -780,7 +830,12 @@ function Set-TargetResource } else { - throw "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" + $message = "SharePoint 2016 only supports Windows Server 2016 or 2012 R2" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } # SharePoint 2019 @@ -805,7 +860,12 @@ function Set-TargetResource } else { - throw "SharePoint 2019 only supports Windows Server 2016 or Windows Server 2019" + $message = "SharePoint 2019 only supports Windows Server 2016 or Windows Server 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -827,7 +887,12 @@ function Set-TargetResource } if ($installResult.Success -ne $true) { - throw "Error installing $($feature.name)" + $message = "Error installing $($feature.name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -847,12 +912,22 @@ function Set-TargetResource -and [string]::IsNullOrEmpty($PSBoundParameters.$_)) ` -or (-not $PSBoundParameters.ContainsKey($_))) { - throw "In offline mode for version $majorVersion parameter $_ is required" + $message = "In offline mode for version $majorVersion parameter $_ is required" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ((Test-Path -Path $PSBoundParameters.$_) -eq $false) { - throw ("The $_ parameter has been passed but the file cannot be found at the " + ` + $message = ("The $_ parameter has been passed but the file cannot be found at the " + ` "path supplied: `"$($PSBoundParameters.$_)`"") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } $requiredParams | ForEach-Object -Process { @@ -875,7 +950,12 @@ function Set-TargetResource } else { - throw "Cannot extract servername from UNC path. Check if it is in the correct format." + $message = "Cannot extract servername from UNC path. Check if it is in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Set-SPDscZoneMap -Server $serverName @@ -900,11 +980,21 @@ function Set-TargetResource } 1 { - throw "Another instance of the prerequisite installer is already running" + $message = "Another instance of the prerequisite installer is already running" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } 2 { - throw "Invalid command line parameters passed to the prerequisite installer" + $message = "Invalid command line parameters passed to the prerequisite installer" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } 1001 { @@ -920,8 +1010,13 @@ function Set-TargetResource } default { - throw ("The prerequisite installer ran with the following unknown " + ` + $message = ("The prerequisite installer ran with the following unknown " + ` "exit code $($process.ExitCode)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -1054,8 +1149,13 @@ function Test-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] ("SharePointDsc does not support uninstalling SharePoint or its " + ` + $message = ("SharePointDsc does not support uninstalling SharePoint or its " + ` "prerequisites. Please remove this manually.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters @@ -1164,8 +1264,13 @@ function Test-SPDscPrereqInstallStatus } Default { - throw ("Unable to search for a prereq with mode '$($itemToCheck.SearchType)'. " + ` + $message = ("Unable to search for a prereq with mode '$($itemToCheck.SearchType)'. " + ` "please use either 'Equals', 'Like' or 'Match', or 'BundleUpgradeCode'") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPIrmSettings/MSFT_SPIrmSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPIrmSettings/MSFT_SPIrmSettings.psm1 index 80b410b06..e241d5473 100644 --- a/SharePointDsc/DSCResources/MSFT_SPIrmSettings/MSFT_SPIrmSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPIrmSettings/MSFT_SPIrmSettings.psm1 @@ -104,9 +104,10 @@ function Set-TargetResource Write-Verbose "Setting SharePoint IRM Settings" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -114,15 +115,24 @@ function Set-TargetResource } catch { - throw "No local SharePoint farm was detected. IRM settings will not be applied" - return + $message = "No local SharePoint farm was detected. IRM settings will not be applied" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $admService = Get-SPDscContentService if ($params.UseADRMS -and ($null -ne $params.RMSserver)) { - throw "Cannot specify both an RMSserver and set UseADRMS to True" + $message = "Cannot specify both an RMSserver and set UseADRMS to True" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.UseADRMS -ne $true) diff --git a/SharePointDsc/DSCResources/MSFT_SPLogLevel/MSFT_SPLogLevel.psm1 b/SharePointDsc/DSCResources/MSFT_SPLogLevel/MSFT_SPLogLevel.psm1 index 46b9a3d4b..028c489d1 100644 --- a/SharePointDsc/DSCResources/MSFT_SPLogLevel/MSFT_SPLogLevel.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPLogLevel/MSFT_SPLogLevel.psm1 @@ -181,36 +181,62 @@ function Set-TargetResource { if ((($DesiredSetting.Area) | Measure-Object).Count -ne 1 -or ($DesiredSetting.Area).contains(",") ) { - throw "Exactly one log area, or the wildcard character '*' must be provided for each log item" + $message = "Exactly one log area, or the wildcard character '*' must be provided for each log item" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ((($DesiredSetting.Name) | Measure-Object).Count -ne 1 -or ($DesiredSetting.Name).contains(",") ) { - throw "Exactly one log name, or the wildcard character '*' must be provided for each log item" + $message = "Exactly one log name, or the wildcard character '*' must be provided for each log item" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -eq $DesiredSetting.TraceLevel -and $null -eq $DesiredSetting.EventLevel) { - throw "TraceLevel and / or EventLevel must be provided for each Area" + $message = "TraceLevel and / or EventLevel must be provided for each Area" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -ne $DesiredSetting.TraceLevel -and @("None", "Unexpected", "Monitorable", "High", "Medium", "Verbose", "VerboseEx", "Default") -notcontains $DesiredSetting.TraceLevel) { - throw "TraceLevel $($DesiredSetting.TraceLevel) is not valid, must specify exactly one of None,Unexpected,Monitorable,High,Medium,Verbose,VerboseEx, or Default" + $message = "TraceLevel $($DesiredSetting.TraceLevel) is not valid, must specify exactly one of None,Unexpected,Monitorable,High,Medium,Verbose,VerboseEx, or Default" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -ne $DesiredSetting.EventLevel -and @("None", "ErrorCritical", "Error", "Warning", "Information", "Verbose", "Default") -notcontains $DesiredSetting.EventLevel) { - throw "EventLevel $($DesiredSetting.EventLevel) is not valid, must specify exactly one of None,ErrorCritical,Error,Warning,Information,Verbose, or Default" + $message = "EventLevel $($DesiredSetting.EventLevel) is not valid, must specify exactly one of None,ErrorCritical,Error,Warning,Information,Verbose, or Default" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } Write-Verbose -Message "Setting SP Log Level settings for the provided areas" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] foreach ($DesiredSetting in $params.SPLogLevelSetting) { @@ -221,7 +247,12 @@ function Set-TargetResource #Validate valid log area/name specified. if ($null -eq $AllSettings) { - throw "Invalid SP Log Area/Name $($DesiredSetting.Area):$($DesiredSetting.Name)" + $message = "Invalid SP Log Area/Name $($DesiredSetting.Area):$($DesiredSetting.Name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -ne $DesiredSetting.TraceLevel) diff --git a/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 b/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 index 54505e325..e40a8159c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPManagedAccount/MSFT_SPManagedAccount.psm1 @@ -107,9 +107,13 @@ function Set-TargetResource if ($Ensure -eq "Present" -and $null -eq $Account) { - throw ("You must specify the 'Account' property as a PSCredential to create a " + ` + $message = ("You must specify the 'Account' property as a PSCredential to create a " + ` "managed account") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $currentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index 0e35c8b45..b3e17bc20 100644 --- a/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -69,9 +69,10 @@ function Get-TargetResource Write-Verbose -Message "Getting managed metadata service application $Name" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApps = Get-SPServiceApplication -Name $params.Name ` -ErrorAction SilentlyContinue @@ -168,8 +169,13 @@ function Get-TargetResource } default { - throw ("Detected an unsupported major version of SharePoint. " + ` + $message = ("Detected an unsupported major version of SharePoint. " + ` "SharePointDsc only supports SharePoint 2013, 2016 or 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -467,12 +473,13 @@ function Set-TargetResource Write-Verbose -Message "Updating the term store administrators" # Update the term store administrators Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $result, $pName) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $result, $pName) ` -ScriptBlock { $params = $args[0] - $currentValues = $args[1] - $pName = $args[2] + $eventSource = $args[1] + $currentValues = $args[2] + $pName = $args[3] $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { @@ -483,7 +490,12 @@ function Set-TargetResource if ($null -eq $termStore) { - throw "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + $message = "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $changesToMake = Compare-Object -ReferenceObject $currentValues.TermStoreAdministrators ` @@ -514,7 +526,12 @@ function Set-TargetResource } default { - throw "An unknown side indicator was found." + $message = "An unknown side indicator was found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -529,11 +546,12 @@ function Set-TargetResource # The lanauge settings should be set to default Write-Verbose -Message "Updating the default language for Managed Metadata Service Application Proxy '$pName'" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $pName) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $pName) ` -ScriptBlock { $params = $args[0] - $pName = $args[1] + $eventSource = $args[1] + $pName = $args[2] $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { @@ -544,7 +562,12 @@ function Set-TargetResource if ($null -eq $termStore) { - throw "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + $message = "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $permissionResult = $termStore.TermStoreAdministrators.DoesUserHavePermissions([Microsoft.SharePoint.Taxonomy.TaxonomyRights]::ManageTermStore) @@ -573,12 +596,13 @@ function Set-TargetResource Write-Verbose -Message "Updating working languages for Managed Metadata Service Application Proxy '$pName'" # Update the term store working languages Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $result, $pName) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $result, $pName) ` -ScriptBlock { $params = $args[0] - $currentValues = $args[1] - $pName = $args[2] + $eventSource = $args[1] + $currentValues = $args[2] + $pName = $args[3] $centralAdminSite = Get-SPWebApplication -IncludeCentralAdministration ` | Where-Object -FilterScript { @@ -589,7 +613,12 @@ function Set-TargetResource if ($null -eq $termStore) { - throw "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + $message = "The name of the Managed Metadata Service Application Proxy '$pName' did not return any termstore." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $permissionResult = $termStore.TermStoreAdministrators.DoesUserHavePermissions([Microsoft.SharePoint.Taxonomy.TaxonomyRights]::ManageTermStore) @@ -619,7 +648,12 @@ function Set-TargetResource } default { - throw "An unknown side indicator was found." + $message = "An unknown side indicator was found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -639,10 +673,11 @@ function Set-TargetResource ) { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $pName) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $pName) ` -ScriptBlock { $params = $args[0] - $pName = $args[1] + $eventSource = $args[1] + $pName = $args[2] $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName if ($null -ne $proxy) @@ -652,7 +687,12 @@ function Set-TargetResource } else { - throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + $message = "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -662,10 +702,11 @@ function Set-TargetResource ) { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $pName) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $pName) ` -ScriptBlock { $params = $args[0] - $pName = $args[1] + $eventSource = $args[1] + $pName = $args[2] $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName if ($null -ne $proxy) @@ -675,7 +716,12 @@ function Set-TargetResource } else { - throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + $message = "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceAppDefault/MSFT_SPManagedMetadataServiceAppDefault.psm1 b/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceAppDefault/MSFT_SPManagedMetadataServiceAppDefault.psm1 index 7d22b6977..14c09eec2 100644 --- a/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceAppDefault/MSFT_SPManagedMetadataServiceAppDefault.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceAppDefault/MSFT_SPManagedMetadataServiceAppDefault.psm1 @@ -24,10 +24,12 @@ function Get-TargetResource Write-Verbose -Message "Getting the default site collection and keyword term store settings" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + if ($params.ServiceAppProxyGroup -eq 'default') { @@ -41,14 +43,24 @@ function Get-TargetResource if ($null -eq $serviceAppProxyGroup) { - throw "Specified ServiceAppProxyGroup $($params.ServiceAppProxyGroup) does not exist." + $message = "Specified ServiceAppProxyGroup $($params.ServiceAppProxyGroup) does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceAppProxies = $serviceAppProxyGroup.Proxies if ($null -eq $serviceAppProxies) { - throw "There are no Service Application Proxies available in the proxy group" + $message = "There are no Service Application Proxies available in the proxy group" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceAppProxies = $serviceAppProxies | Where-Object -FilterScript { @@ -57,7 +69,12 @@ function Get-TargetResource if ($null -eq $serviceAppProxies) { - throw "There are no Managed Metadata Service Application Proxies available in the proxy group" + $message = "There are no Managed Metadata Service Application Proxies available in the proxy group" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $defaultSiteCollectionProxyIsSet = $false @@ -128,10 +145,11 @@ function Set-TargetResource Write-Verbose -Message "Setting the default site collection and keyword term store settings" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.ServiceAppProxyGroup -eq 'default') { @@ -145,14 +163,24 @@ function Set-TargetResource if ($null -eq $serviceAppProxyGroup) { - throw "Specified ServiceAppProxyGroup $($params.ServiceAppProxyGroup) does not exist." + $message = "Specified ServiceAppProxyGroup $($params.ServiceAppProxyGroup) does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceAppProxies = $serviceAppProxyGroup.Proxies if ($null -eq $serviceAppProxies) { - throw "There are no Service Application Proxies available in the proxy group" + $message = "There are no Service Application Proxies available in the proxy group" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceAppProxies = $serviceAppProxies | Where-Object -FilterScript { @@ -161,7 +189,12 @@ function Set-TargetResource if ($null -eq $serviceAppProxies) { - throw "There are no Managed Metadata Service Application Proxies available in the proxy group" + $message = "There are no Managed Metadata Service Application Proxies available in the proxy group" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } foreach ($serviceAppProxy in $serviceAppProxies) diff --git a/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 b/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 index b28debc83..e9b59a942 100644 --- a/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPMinRoleCompliance/MSFT_SPMinRoleCompliance.psm1 @@ -24,7 +24,12 @@ function Get-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -ne 16) { - throw [Exception] "MinRole is only supported in SharePoint 2016 and 2019." + $message = "MinRole is only supported in SharePoint 2016 and 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -86,13 +91,23 @@ function Set-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -ne 16) { - throw [Exception] "MinRole is only supported in SharePoint 2016 and 2019." + $message = "MinRole is only supported in SharePoint 2016 and 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($State -eq "NonCompliant") { - throw ("State can only be configured to 'Compliant'. The 'NonCompliant' value is only " + ` + $message = ("State can only be configured to 'Compliant'. The 'NonCompliant' value is only " + ` "used to report when the farm is not compliant") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` @@ -149,8 +164,13 @@ function Test-TargetResource if ($State -eq "NonCompliant") { - throw ("State can only be configured to 'Compliant'. The 'NonCompliant' value is only " + ` + $message = ("State can only be configured to 'Compliant'. The 'NonCompliant' value is only " + ` "used to report when the farm is not compliant") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 index 9b9e821f5..be753e702 100644 --- a/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPOutgoingEmailSettings/MSFT_SPOutgoingEmailSettings.psm1 @@ -43,13 +43,23 @@ function Get-TargetResource if (($PSBoundParameters.ContainsKey("UseTLS") -eq $true) -and ` $installedVersion.FileMajorPart -ne 16) { - throw [Exception] "UseTLS is only supported in SharePoint 2016 and SharePoint 2019." + $message = "UseTLS is only supported in SharePoint 2016 and SharePoint 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($PSBoundParameters.ContainsKey("SMTPPort") -eq $true) -and ` $installedVersion.FileMajorPart -ne 16) { - throw [Exception] "SMTPPort is only supported in SharePoint 2016 and SharePoint 2019." + $message = "SMTPPort is only supported in SharePoint 2016 and SharePoint 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -137,19 +147,30 @@ function Set-TargetResource if (($PSBoundParameters.ContainsKey("UseTLS") -eq $true) -and ` $installedVersion.FileMajorPart -lt 16) { - throw [Exception] "UseTLS is only supported in SharePoint 2016 and SharePoint 2019." + $message = "UseTLS is only supported in SharePoint 2016 and SharePoint 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($PSBoundParameters.ContainsKey("SMTPPort") -eq $true) -and ` $installedVersion.FileMajorPart -lt 16) { - throw [Exception] "SMTPPort is only supported in SharePoint 2016 and SharePoint 2019." + $message = "SMTPPort is only supported in SharePoint 2016 and SharePoint 2019." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $webApp = $null Write-Verbose -Message "Retrieving $($params.WebAppUrl) settings" @@ -157,7 +178,12 @@ function Set-TargetResource $webApp = Get-SPWebApplication $params.WebAppUrl -IncludeCentralAdministration if ($null -eq $webApp) { - throw "Web Application $webAppUrl not found" + $message = "Web Application $webAppUrl not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $installedVersion = Get-SPDscInstalledProductVersion @@ -199,8 +225,13 @@ function Set-TargetResource } default { - throw ("Detected an unsupported major version of SharePoint. SharePointDsc only " + ` + $message = ("Detected an unsupported major version of SharePoint. SharePointDsc only " + ` "supports SharePoint 2013, 2016 or 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 index 92baaf973..39ec73679 100644 --- a/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPPowerPointAutomationServiceApp/MSFT_SPPowerPointAutomationServiceApp.psm1 @@ -56,13 +56,23 @@ function Get-TargetResource -or $WorkerProcessCount ` -or $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and -not $ApplicationPool) { - throw ("An Application Pool is required to configure the PowerPoint " + ` + $message = ("An Application Pool is required to configure the PowerPoint " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -178,12 +188,22 @@ function Set-TargetResource -or $WorkerProcessCount ` -or $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and -not $ApplicationPool) { - throw ("An Application Pool is required to configure the PowerPoint " + ` + $message = ("An Application Pool is required to configure the PowerPoint " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters @@ -191,9 +211,10 @@ function Set-TargetResource { Write-Verbose -Message "Creating PowerPoint Automation Service Application $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $proxyName = $params.ProxyName if ($null -eq $proxyName) @@ -231,7 +252,12 @@ function Set-TargetResource } else { - throw "Specified application pool does not exist" + $message = "Specified application pool does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -239,16 +265,22 @@ function Set-TargetResource { Write-Verbose -Message "Updating PowerPoint Automation Service Application $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters, $result ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $result) ` -ScriptBlock { $params = $args[0] - $result = $args[1] + $eventSource = $args[1] + $result = $args[2] $serviceApps = Get-SPServiceApplication -Name $params.Name ` -ErrorAction SilentlyContinue if ($null -eq $serviceApps) { - throw "No Service applications are available in the farm." + $message = "No Service applications are available in the farm." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceApp = $serviceApps ` | Where-Object -FilterScript { @@ -256,7 +288,12 @@ function Set-TargetResource } if ($null -eq $serviceApp) { - throw "Unable to find specified service application." + $message = "Unable to find specified service application." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ([string]::IsNullOrEmpty($params.ApplicationPool) -eq $false ` -and $params.ApplicationPool -ne $result.ApplicationPool) @@ -264,7 +301,12 @@ function Set-TargetResource $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool if ($null -eq $appPool) { - throw "The specified App Pool does not exist" + $message = "The specified App Pool does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceApp.ApplicationPool = $appPool } @@ -392,13 +434,23 @@ function Test-TargetResource $WorkerProcessCount -or ` $WorkerTimeoutInSeconds) -and ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and -not $ApplicationPool) { - throw ("An Application Pool is required to configure the PowerPoint " + ` + $message = ("An Application Pool is required to configure the PowerPoint " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 b/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 index 23c47daad..1269a3463 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProductUpdate/MSFT_SPProductUpdate.psm1 @@ -33,8 +33,12 @@ function Get-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] "SharePoint does not support uninstalling updates." - return + $message = "SharePoint does not support uninstalling updates." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Getting install status of SP binaries" @@ -94,8 +98,13 @@ function Get-TargetResource if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $SetupFile' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $SetupFile' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -136,7 +145,12 @@ function Get-TargetResource } else { - throw "Update does not contain the language code in the correct format." + $message = "Update does not contain the language code in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } try @@ -145,13 +159,23 @@ function Get-TargetResource } catch { - throw "Error while converting language information: $language" + $message = "Error while converting language information: $language" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # try/catch is required for some versions of Windows, other version use the LCID value of 4096 if ($cultureInfo.LCID -eq 4096) { - throw "Error while converting language information: $language" + $message = "Error while converting language information: $language" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Extract English name of the language code @@ -184,7 +208,12 @@ function Get-TargetResource if ($versionInfo -eq $nullVersion) { - throw "Error: Product for language $language is not found." + $message = "Error: Product for language $language is not found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { @@ -277,14 +306,23 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] "SharePoint does not support uninstalling updates." - return + $message = "SharePoint does not support uninstalling updates." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Check if the setup file exists" if (-not(Test-Path -Path $SetupFile)) { - throw "Setup file cannot be found: {$SetupFile}" + $message = "Setup file cannot be found: {$SetupFile}" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Checking file status of $SetupFile" @@ -327,8 +365,13 @@ function Set-TargetResource if ($null -ne $zone) { - throw ("Setup file is blocked! Please use 'Unblock-File -Path $SetupFile' " + ` + $message = ("Setup file is blocked! Please use 'Unblock-File -Path $SetupFile' " + ` "to unblock the file before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "File not blocked, continuing." } @@ -368,23 +411,43 @@ function Set-TargetResource if ($upgradeTimes.Count -ne 3) { - throw "Time window incorrectly formatted." + $message = "Time window incorrectly formatted." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { if ([datetime]::TryParse($upgradeTimes[0], [ref]$starttime) -ne $true) { - throw "Error converting start time" + $message = "Error converting start time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ([datetime]::TryParse($upgradeTimes[2], [ref]$endtime) -ne $true) { - throw "Error converting end time" + $message = "Error converting end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($starttime -gt $endtime) { - throw "Error: Start time cannot be larger than end time" + $message = "Error: Start time cannot be larger than end time" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -498,9 +561,10 @@ function Set-TargetResource Write-Verbose -Message "Beginning installation of the SharePoint update" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $SetupFile ` + -Arguments @($SetupFile, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $setupFile = $args[0] + $eventSource = $args[1] Write-Verbose -Message "Checking if SetupFile is an UNC path" $uncInstall = $false @@ -516,7 +580,12 @@ function Set-TargetResource } else { - throw "Cannot extract servername from UNC path. Check if it is in the correct format." + $message = "Cannot extract servername from UNC path. Check if it is in the correct format." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Set-SPDscZoneMap -Server $serverName @@ -553,8 +622,13 @@ function Set-TargetResource } Default { - throw ("SharePoint update install failed, exit code was $($setup.ExitCode). " + ` + $message = ("SharePoint update install failed, exit code was $($setup.ExitCode). " + ` "Error codes can be found at https://aka.ms/installerrorcodes") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -653,7 +727,12 @@ function Test-TargetResource if ($Ensure -eq "Absent") { - throw [Exception] "SharePoint does not support uninstalling updates." + $message = "SharePoint does not support uninstalling updates." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters @@ -776,7 +855,12 @@ function Get-SPDscLocalVersionInfo } catch [Exception] { - throw [Exception] "An error occured during the collection of data about installed products in Get-SPDscLocalVersionInfo." + $message = "An error occured during the collection of data about installed products in Get-SPDscLocalVersionInfo." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/MSFT_SPProjectServerADResourcePoolSync.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/MSFT_SPProjectServerADResourcePoolSync.psm1 index 6dc0eb340..8151fcacd 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/MSFT_SPProjectServerADResourcePoolSync.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerADResourcePoolSync/MSFT_SPProjectServerADResourcePoolSync.psm1 @@ -30,8 +30,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -129,8 +134,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Ensure -eq "Present") diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerAdditionalSettings/MSFT_SPProjectServerAdditionalSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerAdditionalSettings/MSFT_SPProjectServerAdditionalSettings.psm1 index d8616ad48..d8e6c85d9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerAdditionalSettings/MSFT_SPProjectServerAdditionalSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerAdditionalSettings/MSFT_SPProjectServerAdditionalSettings.psm1 @@ -29,8 +29,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -99,8 +104,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerGlobalPermissions/MSFT_SPProjectServerGlobalPermissions.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerGlobalPermissions/MSFT_SPProjectServerGlobalPermissions.psm1 index d52b0fbcd..710f26cfe 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerGlobalPermissions/MSFT_SPProjectServerGlobalPermissions.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerGlobalPermissions/MSFT_SPProjectServerGlobalPermissions.psm1 @@ -34,20 +34,31 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] + $eventSource = $args[1] + $scriptRoot = $args[2] if ((Get-SPProjectPermissionMode -Url $params.Url) -ne "ProjectServer") { - throw [Exception] ("SPProjectServerGlobalPermissions is designed for Project Server " + ` + $message = ("SPProjectServerGlobalPermissions is designed for Project Server " + ` "permissions mode only, and this site is set to SharePoint mode") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $modulePath = "..\..\Modules\SharePointDsc.ProjectServerConnector\SharePointDsc.ProjectServerConnector.psm1" diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerGroup/MSFT_SPProjectServerGroup.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerGroup/MSFT_SPProjectServerGroup.psm1 index 12af94ed0..efa4ad9dc 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerGroup/MSFT_SPProjectServerGroup.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerGroup/MSFT_SPProjectServerGroup.psm1 @@ -46,8 +46,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("ADGroup") -eq $true -and ` @@ -55,28 +60,44 @@ function Get-TargetResource $PSBoundParameters.ContainsKey("MembersToInclude") -eq $true -or ` $PSBoundParameters.ContainsKey("MembersToExclude") -eq $true)) { - throw ("Property ADGroup can not be used at the same time as Members, " + ` + $message = ("Property ADGroup can not be used at the same time as Members, " + ` "MembersToInclude or MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("Members") -eq $true -and ` ($PSBoundParameters.ContainsKey("MembersToInclude") -eq $true -or ` $PSBoundParameters.ContainsKey("MembersToExclude") -eq $true)) { - throw ("Property Members can not be used at the same time as " + ` + $message = ("Property Members can not be used at the same time as " + ` "MembersToInclude or MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] + $eventSource = $args[1] + $scriptRoot = $args[2] if ((Get-SPProjectPermissionMode -Url $params.Url) -ne "ProjectServer") { - throw [Exception] ("SPProjectServerGroup is design for Project Server permissions " + ` + $message = ("SPProjectServerGroup is design for Project Server permissions " + ` "mode only, and this site is set to SharePoint mode") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $modulePath = "..\..\Modules\SharePointDsc.ProjectServerConnector\SharePointDsc.ProjectServerConnector.psm1" diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 index b3e6d442b..322f391be 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerLicense/MSFT_SPProjectServerLicense.psm1 @@ -27,8 +27,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -121,13 +126,23 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Ensure -eq "Present" -and $PSBoundParameters.ContainsKey("ProductKey") -eq $false) { - throw [Exception] "ProductKey is required when Ensure equals 'Present'" + $message = "ProductKey is required when Ensure equals 'Present'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $currentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerPermissionMode/MSFT_SPProjectServerPermissionMode.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerPermissionMode/MSFT_SPProjectServerPermissionMode.psm1 index 0bdd2f67f..ffd404b95 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerPermissionMode/MSFT_SPProjectServerPermissionMode.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerPermissionMode/MSFT_SPProjectServerPermissionMode.psm1 @@ -22,8 +22,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -71,8 +76,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerServiceApp/MSFT_SPProjectServerServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerServiceApp/MSFT_SPProjectServerServiceApp.psm1 index a18d04e26..d60945c48 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerServiceApp/MSFT_SPProjectServerServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerServiceApp/MSFT_SPProjectServerServiceApp.psm1 @@ -30,8 +30,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -115,8 +120,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerTimeSheetSettings/MSFT_SPProjectServerTimeSheetSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerTimeSheetSettings/MSFT_SPProjectServerTimeSheetSettings.psm1 index 5f9ff05dc..41fa53cb4 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerTimeSheetSettings/MSFT_SPProjectServerTimeSheetSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerTimeSheetSettings/MSFT_SPProjectServerTimeSheetSettings.psm1 @@ -97,8 +97,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -351,8 +356,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerUserSyncSettings/MSFT_SPProjectServerUserSyncSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerUserSyncSettings/MSFT_SPProjectServerUserSyncSettings.psm1 index 58e2ee625..9df4e658a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerUserSyncSettings/MSFT_SPProjectServerUserSyncSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerUserSyncSettings/MSFT_SPProjectServerUserSyncSettings.psm1 @@ -29,8 +29,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/MSFT_SPProjectServerWssSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/MSFT_SPProjectServerWssSettings.psm1 index c2185feb5..b18d2caf1 100644 --- a/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/MSFT_SPProjectServerWssSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPProjectServerWssSettings/MSFT_SPProjectServerWssSettings.psm1 @@ -22,8 +22,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -lt 16) { - throw [Exception] ("Support for Project Server in SharePointDsc is only valid for " + ` + $message = ("Support for Project Server in SharePointDsc is only valid for " + ` "SharePoint 2016 and 2019.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 index 0c3acdd43..7d3c40ab4 100644 --- a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 @@ -82,20 +82,31 @@ function Set-TargetResource Write-Verbose -Message "Setting service application publish status '$Name'" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApp = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue if ($null -eq $serviceApp) { - throw [Exception] ("The service application $Name does not exist") + $message = ("The service application $Name does not exist") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -eq $serviceApp.Uri) { - throw [Exception] ("Only Business Data Connectivity, Machine Translation, Managed Metadata, " + ` + $message = ("Only Business Data Connectivity, Machine Translation, Managed Metadata, " + ` "User Profile, Search, Secure Store are supported to be published via DSC.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($Ensure -eq "Present") diff --git a/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 b/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 index 2a05bfb18..1863a410c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPQuotaTemplate/MSFT_SPQuotaTemplate.psm1 @@ -38,13 +38,23 @@ function Get-TargetResource if ($StorageMaxInMB -lt $StorageWarningInMB) { - throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + $message = "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { - throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` + $message = ("MaximumUsagePointsSolutions must be equal to or larger than " + ` "WarningUsagePointsSolutions.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -137,13 +147,23 @@ function Set-TargetResource if ($StorageMaxInMB -lt $StorageWarningInMB) { - throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + $message = "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { - throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` + $message = ("MaximumUsagePointsSolutions must be equal to or larger than " + ` "WarningUsagePointsSolutions.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } switch ($Ensure) @@ -152,9 +172,10 @@ function Set-TargetResource { Write-Verbose "Ensure is set to Present - Add or update template" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -162,9 +183,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. Quota " + ` + $message = ("No local SharePoint farm was detected. Quota " + ` "template settings will not be applied") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Start update" @@ -229,9 +254,14 @@ function Set-TargetResource -or $MaximumUsagePointsSolutions ` -or $WarningUsagePointsSolutions) { - throw ("Do not use StorageMaxInMB, StorageWarningInMB, " + ` + $message = ("Do not use StorageMaxInMB, StorageWarningInMB, " + ` "MaximumUsagePointsSolutions or WarningUsagePointsSolutions " + ` "when Ensure is specified as Absent") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` @@ -302,13 +332,23 @@ function Test-TargetResource if ($StorageMaxInMB -lt $StorageWarningInMB) { - throw "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + $message = "StorageMaxInMB must be equal to or larger than StorageWarningInMB." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($MaximumUsagePointsSolutions -lt $WarningUsagePointsSolutions) { - throw ("MaximumUsagePointsSolutions must be equal to or larger than " + ` + $message = ("MaximumUsagePointsSolutions must be equal to or larger than " + ` "WarningUsagePointsSolutions.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters @@ -342,9 +382,14 @@ function Test-TargetResource $MaximumUsagePointsSolutions -or ` $WarningUsagePointsSolutions) { - throw ("Do not use StorageMaxInMB, StorageWarningInMB, " + ` + $message = ("Do not use StorageMaxInMB, StorageWarningInMB, " + ` "MaximumUsagePointsSolutions or WarningUsagePointsSolutions " + ` "when Ensure is specified as Absent") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($CurrentValues.Ensure -eq "Present") diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 index 24b1b0a1a..081290d91 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchAuthoritativePage/MSFT_SPSearchAuthoritativePage.psm1 @@ -144,9 +144,10 @@ function Set-TargetResource if ($CurrentResults.Ensure -eq "Absent" -and $Ensure -eq "Present") { $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa @@ -154,7 +155,12 @@ function Set-TargetResource if ($null -eq $serviceApp) { - throw "Search Service App was not available." + $message = "Search Service App was not available." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.Action -eq "Authoratative") { @@ -172,9 +178,10 @@ function Set-TargetResource if ($CurrentResults.Ensure -eq "Present" -and $Ensure -eq "Present") { $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa @@ -182,7 +189,12 @@ function Set-TargetResource if ($null -eq $serviceApp) { - throw "Search Service App was not available." + $message = "Search Service App was not available." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.Action -eq "Authoratative") @@ -197,9 +209,10 @@ function Set-TargetResource if ($Ensure -eq "Absent") { $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName $searchObjectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa @@ -207,7 +220,12 @@ function Set-TargetResource if ($null -eq $serviceApp) { - throw "Search Service App was not available." + $message = "Search Service App was not available." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.Action -eq "Authoratative") { diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 index 0687017cc..9f291dada 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 @@ -72,10 +72,11 @@ function Get-TargetResource Write-Verbose -Message "Getting Content Source Setting for '$Name'" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] + $eventSource = $args[1] + $ScriptRoot = $args[2] $relativePath = "..\..\Modules\SharePointDsc.Search\SPSearchContentSource.Schedules.psm1" $modulePath = Join-Path -Path $ScriptRoot ` @@ -211,8 +212,13 @@ function Get-TargetResource } Default { - throw ("SharePointDsc does not currently support '$($source.Type)' content " + ` + $message = ("SharePointDsc does not currently support '$($source.Type)' content " + ` "sources. Please use only 'SharePoint', 'FileShare', 'Website' or 'Business'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } return $result @@ -298,59 +304,114 @@ function Set-TargetResource { if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + $message = "Parameter LimitPageDepth is not valid for SharePoint content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for SharePoint content sources" + $message = "Parameter LimitServerHops is not valid for SharePoint content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($CrawlSetting -ne "CrawlVirtualServers" -and $CrawlSetting -ne "CrawlSites" ) { - throw ("Parameter CrawlSetting can only be set to CrawlVirtualServers or CrawlSites " + ` + $message = ("Parameter CrawlSetting can only be set to CrawlVirtualServers or CrawlSites " + ` "for SharePoint content sources") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "Website" { if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for Website content sources" + $message = "Parameter ContinuousCrawl is not valid for Website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for Website content sources" + $message = "Parameter LimitServerHops is not valid for Website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "FileShare" { if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for FileShare content sources" + $message = "Parameter LimitPageDepth is not valid for FileShare content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for FileShare content sources" + $message = "Parameter LimitServerHops is not valid for FileShare content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($CrawlSetting -eq "Custom") { - throw "Parameter CrawlSetting can only be set to custom for website content sources" + $message = "Parameter CrawlSetting can only be set to custom for website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "Business" { if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for Business content sources" + $message = "Parameter ContinuousCrawl is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for Business content sources" + $message = "Parameter LimitPageDepth is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for Business content sources" + $message = "Parameter LimitServerHops is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -359,11 +420,16 @@ function Set-TargetResource if ($ContentSourceType -ne $CurrentValues.ContentSourceType -and $Force -eq $false) { - throw ("The type of the a search content source can not be changed from " + ` + $message = ("The type of the a search content source can not be changed from " + ` "'$($CurrentValues.ContentSourceType)' to '$ContentSourceType' without " + ` "deleting and adding it again. Specify 'Force = `$true' in order to allow " + ` "DSC to do this, or manually remove the existing content source and re-run " + ` "the configuration.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ContentSourceType -ne $CurrentValues.ContentSourceType -and $Force -eq $true) ` @@ -384,9 +450,10 @@ function Set-TargetResource { # Create the new content source and then apply settings to it Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $OFS = "," $startAddresses = "$($params.Addresses)" @@ -447,8 +514,13 @@ function Set-TargetResource if ($null -eq $source) { - throw ("An error occurred during creation of the Content Source, " + ` + $message = ("An error occurred during creation of the Content Source, " + ` "please check if all parameters are correct.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -789,59 +861,114 @@ function Test-TargetResource { if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for SharePoint content sources" + $message = "Parameter LimitPageDepth is not valid for SharePoint content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for SharePoint content sources" + $message = "Parameter LimitServerHops is not valid for SharePoint content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($CrawlSetting -ne "CrawlVirtualServers" -and $CrawlSetting -ne "CrawlSites" ) { - throw ("Parameter CrawlSetting can only be set to CrawlVirtualServers or CrawlSites " + ` + $message = ("Parameter CrawlSetting can only be set to CrawlVirtualServers or CrawlSites " + ` "for SharePoint content sources") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "Website" { if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for Website content sources" + $message = "Parameter ContinuousCrawl is not valid for Website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for Website content sources" + $message = "Parameter LimitServerHops is not valid for Website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "FileShare" { if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for FileShare content sources" + $message = "Parameter LimitPageDepth is not valid for FileShare content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for FileShare content sources" + $message = "Parameter LimitServerHops is not valid for FileShare content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($CrawlSetting -eq "Custom") { - throw "Parameter CrawlSetting can only be set to custom for website content sources" + $message = "Parameter CrawlSetting can only be set to custom for website content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } "Business" { if ($PSBoundParameters.ContainsKey("ContinuousCrawl") -eq $true) { - throw "Parameter ContinuousCrawl is not valid for Business content sources" + $message = "Parameter ContinuousCrawl is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitPageDepth") -eq $true) { - throw "Parameter LimitPageDepth is not valid for Business content sources" + $message = "Parameter LimitPageDepth is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("LimitServerHops") -eq $true) { - throw "Parameter LimitServerHops is not valid for Business content sources" + $message = "Parameter LimitServerHops is not valid for Business content sources" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 index b40dffd83..81350d4c0 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlMapping/MSFT_SPSearchCrawlMapping.psm1 @@ -124,14 +124,20 @@ function Set-TargetResource Write-Verbose "Adding the Crawl Mapping '$Url'" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $searchApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $searchApp) { - throw [Exception] "The Search Service Application does not exist" + $message = "The Search Service Application does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.psm1 index f88766717..cfb819d5c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlRule/MSFT_SPSearchCrawlRule.psm1 @@ -58,15 +58,25 @@ function Get-TargetResource # AuthenticationType=CertificateName and CertificateRuleAccess parameters not specified if ($AuthenticationType -eq "CertificateRuleAccess" -and -not $CertificateName) { - throw ("When AuthenticationType=CertificateRuleAccess, the parameter " + ` + $message = ("When AuthenticationType=CertificateRuleAccess, the parameter " + ` "CertificateName is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationType=CertificateName and CertificateRuleAccess parameters not # specified correctly if ($AuthenticationType -ne "CertificateRuleAccess" -and $CertificateName) { - throw "When specifying CertificateName, the AuthenticationType parameter is required" + $message = "When specifying CertificateName, the AuthenticationType parameter is required" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationType=NTLMAccountRuleAccess and AuthenticationCredentialsparameters @@ -75,8 +85,13 @@ function Get-TargetResource -or $AuthenticationType -eq "BasicAccountRuleAccess") ` -and -not $AuthenticationCredentials) { - throw ("When AuthenticationType is NTLMAccountRuleAccess or BasicAccountRuleAccess, " + ` + $message = ("When AuthenticationType is NTLMAccountRuleAccess or BasicAccountRuleAccess, " + ` "the parameter AuthenticationCredentials is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationCredentials parameters, but AuthenticationType is not NTLMAccountRuleAccess @@ -85,8 +100,13 @@ function Get-TargetResource -and $AuthenticationType -ne "NTLMAccountRuleAccess" ` -and $AuthenticationType -ne "BasicAccountRuleAccess") { - throw ("When specifying AuthenticationCredentials, the AuthenticationType " + ` + $message = ("When specifying AuthenticationCredentials, the AuthenticationType " + ` "parameter is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # ExclusionRule only with CrawlConfigurationRules=CrawlComplexUrls @@ -94,8 +114,13 @@ function Get-TargetResource -and ($CrawlConfigurationRules -contains "CrawlAsHTTP" ` -or $CrawlConfigurationRules -contains "FollowLinksNoPageCrawl")) { - throw ("When RuleType=ExclusionRule, CrawlConfigurationRules cannot contain " + ` + $message = ("When RuleType=ExclusionRule, CrawlConfigurationRules cannot contain " + ` "the values FollowLinksNoPageCrawl or CrawlAsHTTP") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # ExclusionRule cannot be used with AuthenticationCredentials, CertificateName or @@ -103,8 +128,13 @@ function Get-TargetResource if ($RuleType -eq "ExclusionRule" ` -and ($AuthenticationCredentials -or $CertificateName -or $AuthenticationType)) { - throw ("When Type=ExclusionRule, parameters AuthenticationCredentials, " + ` + $message = ("When Type=ExclusionRule, parameters AuthenticationCredentials, " + ` "CertificateName or AuthenticationType are not allowed") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -283,15 +313,25 @@ function Set-TargetResource # AuthenticationType=CertificateName and CertificateRuleAccess parameters not specified if ($AuthenticationType -eq "CertificateRuleAccess" -and -not $CertificateName) { - throw ("When AuthenticationType=CertificateRuleAccess, the parameter " + ` + $message = ("When AuthenticationType=CertificateRuleAccess, the parameter " + ` "CertificateName is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationType=CertificateName and CertificateRuleAccess parameters not # specified correctly if ($AuthenticationType -ne "CertificateRuleAccess" -and $CertificateName) { - throw "When specifying CertificateName, the AuthenticationType parameter is required" + $message = "When specifying CertificateName, the AuthenticationType parameter is required" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationType=NTLMAccountRuleAccess and AuthenticationCredentialsparameters @@ -300,8 +340,13 @@ function Set-TargetResource -or $AuthenticationType -eq "BasicAccountRuleAccess") ` -and -not $AuthenticationCredentials) { - throw ("When AuthenticationType is NTLMAccountRuleAccess or BasicAccountRuleAccess, " + ` + $message = ("When AuthenticationType is NTLMAccountRuleAccess or BasicAccountRuleAccess, " + ` "the parameter AuthenticationCredentials is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # AuthenticationCredentials parameters, but AuthenticationType is not NTLMAccountRuleAccess @@ -310,8 +355,13 @@ function Set-TargetResource -and $AuthenticationType -ne "NTLMAccountRuleAccess" ` -and $AuthenticationType -ne "BasicAccountRuleAccess") { - throw ("When specifying AuthenticationCredentials, the AuthenticationType " + ` + $message = ("When specifying AuthenticationCredentials, the AuthenticationType " + ` "parameter is required") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # ExclusionRule only with CrawlConfigurationRules=CrawlComplexUrls @@ -319,8 +369,13 @@ function Set-TargetResource -and ($CrawlConfigurationRules -contains "CrawlAsHTTP" ` -or $CrawlConfigurationRules -contains "FollowLinksNoPageCrawl")) { - throw ("When RuleType=ExclusionRule, CrawlConfigurationRules cannot contain " + ` + $message = ("When RuleType=ExclusionRule, CrawlConfigurationRules cannot contain " + ` "the values FollowLinksNoPageCrawl or CrawlAsHTTP") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # ExclusionRule cannot be used with AuthenticationCredentials, CertificateName or @@ -328,8 +383,13 @@ function Set-TargetResource if ($RuleType -eq "ExclusionRule" ` -and ($AuthenticationCredentials -or $CertificateName -or $AuthenticationType)) { - throw ("When Type=ExclusionRule, parameters AuthenticationCredentials, " + ` + $message = ("When Type=ExclusionRule, parameters AuthenticationCredentials, " + ` "CertificateName or AuthenticationType are not allowed") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 index 46dc8ab9c..1a5618a53 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 @@ -34,7 +34,12 @@ function Get-TargetResource if (($RequestLimit -gt 0) -and ($WaitTime -gt 0)) { - throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + $message = "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -130,7 +135,12 @@ function Set-TargetResource if (($RequestLimit -gt 0) -and ($WaitTime -gt 0)) { - throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + $message = "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters @@ -139,9 +149,11 @@ function Set-TargetResource { Write-Verbose -Message "Creating Crawler Impact Rule $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + $behavior = "0" $hitRate = 0 if ($null -eq $params.RequestLimit) @@ -158,7 +170,12 @@ function Set-TargetResource $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $serviceApp) { - throw "The Search Service Application does not exist." + $message = "The Search Service Application does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } New-SPEnterpriseSearchSiteHitRule -Name $params.Name ` -Behavior $behavior ` @@ -170,9 +187,11 @@ function Set-TargetResource { Write-Verbose -Message "Updating Crawler Impact Rule $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + $behavior = "0" $hitRate = 0 if ($null -eq $params.RequestLimit) @@ -188,7 +207,12 @@ function Set-TargetResource $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $serviceApp) { - throw "The Search Service Application does not exist." + $message = "The Search Service Application does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Remove-SPEnterpriseSearchSiteHitRule -Identity $params.Name ` @@ -206,13 +230,20 @@ function Set-TargetResource { Write-Verbose -Message "Removing Crawler Impact Rule $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $serviceApp) { - throw "The Search Service Application does not exist." + $message = "The Search Service Application does not exist." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Remove-SPEnterpriseSearchSiteHitRule -Identity $params.Name ` -SearchService $serviceApp ` @@ -258,7 +289,12 @@ function Test-TargetResource if (($RequestLimit -gt 0) -and ($WaitTime -gt 0)) { - throw "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + $message = "Only one Crawler Impact Rule HitRate argument (RequestLimit, WaitTime) can be specified" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $behavior = "" diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.psm1 index e9e16d4ab..d4e5a68c6 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchFileType/MSFT_SPSearchFileType.psm1 @@ -149,7 +149,12 @@ function Set-TargetResource (-not($PSBoundParameters.ContainsKey("MimeType")) -or ` -not($PSBoundParameters.ContainsKey("Description")))) { - throw "Ensure is configured as Present, but MimeType and/or Description is missing" + $message = "Ensure is configured as Present, but MimeType and/or Description is missing" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $PSBoundParameters.Ensure = $Ensure @@ -158,16 +163,22 @@ function Set-TargetResource Write-Verbose -Message "Checking if Service Application '$ServiceAppName' exists" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApps = Get-SPServiceApplication -Name $params.ServiceAppName ` -ErrorAction SilentlyContinue if ($null -eq $serviceApps) { - throw "Service Application $($params.ServiceAppName) is not found" + $message = "Service Application $($params.ServiceAppName) is not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceApp = $serviceApps | Where-Object -FilterScript { @@ -176,7 +187,12 @@ function Set-TargetResource if ($null -eq $serviceApp) { - throw "Service Application $($params.ServiceAppName) is not a search service application" + $message = "Service Application $($params.ServiceAppName) is not a search service application" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index a22743d66..f0373edf6 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -78,15 +78,21 @@ function Get-TargetResource Write-Verbose -Message "Getting Managed Property Setting for '$Name'" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $ssa) { - throw ("The specified Search Service Application $($params.ServiceAppName) is " + ` + $message = ("The specified Search Service Application $($params.ServiceAppName) is " + ` "invalid. Please make sure you specify the name of an existing service application.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa | ` Where-Object { $_.Name -eq $params.Name } @@ -225,19 +231,24 @@ function Set-TargetResource # Validate that the specified crawled properties are all valid and existing Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, ` - $CurrentValues) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $CurrentValues) ` -ScriptBlock { $params = $args[0] - $CurrentValues = $args[1] + $eventSource = $args[1] + $CurrentValues = $args[2] #region Pre-Validation # Ensure that if we specified that we don't specify any crawled property mapping if we selected to include # them all. if ($params.IncludeAllCrawledProperties -and $params.CrawledProperties.Length -gt 0) { - throw ("You cannot specify values for CrawledProperties if the property " + ` + $message = ("You cannot specify values for CrawledProperties if the property " + ` "IncludeAllCrawledProperties is set to True.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Ensure that the specified crawled properties exist @@ -247,8 +258,13 @@ function Set-TargetResource -SearchApplication $params.ServiceAppName if (!$currentCrawlProperty) { - throw ("The specified crawled property $($mappedCrawlProperty) does not exist. " + ` + $message = ("The specified crawled property $($mappedCrawlProperty) does not exist. " + ` "Please make sure you specify valid existing crawl properties.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } #endregion diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchMetadataCategory/MSFT_SPSearchMetadataCategory.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchMetadataCategory/MSFT_SPSearchMetadataCategory.psm1 index e87a0201f..38ce02761 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchMetadataCategory/MSFT_SPSearchMetadataCategory.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchMetadataCategory/MSFT_SPSearchMetadataCategory.psm1 @@ -37,15 +37,21 @@ function Get-TargetResource Write-Verbose -Message "Getting Metadata Category Setting for '$Name'" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $ssa) { - throw ("The specified Search Service Application $($params.ServiceAppName) is ` - invalid. Please make sure you specify the name of an existing service application.") + $message = ("The specified Search Service Application $($params.ServiceAppName) is ` + invalid. Please make sure you specify the name of an existing service application.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $category = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $ssa | ` Where-Object { $_.Name -eq $params.Name } @@ -115,15 +121,21 @@ function Set-TargetResource # Validate that the specified crawled properties are all valid and existing Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $ssa) { - throw ("The specified Search Service Application $($params.ServiceAppName) is ` - invalid. Please make sure you specify the name of an existing service application.") + $message = ("The specified Search Service Application $($params.ServiceAppName) is ` + invalid. Please make sure you specify the name of an existing service application.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Set the specified properties on the Managed Property @@ -136,9 +148,14 @@ function Set-TargetResource # If the category we are trying to remove is not empty, throw an error if ($category.CrawledPropertyCount -gt 0) { - throw "Cannot delete Metadata Category $($param.Name) because it contains " + ` - "Crawled Properties. Please remove all associated Crawled Properties " + ` - "before attempting to delete this category." + $message = ("Cannot delete Metadata Category $($param.Name) because it contains " + ` + "Crawled Properties. Please remove all associated Crawled Properties " + ` + "before attempting to delete this category.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Remove-SPEnterpriseSearchMetadataCategory -Identity $params.Name ` -SearchApplication $params.ServiceAppName ` diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 index 27233f65f..8a2128662 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 @@ -175,25 +175,37 @@ function Set-TargetResource { Write-Verbose -Message "Creating search result source $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + [void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") $serviceApp = Get-SPEnterpriseSearchServiceApplication ` -Identity $params.SearchServiceAppName if ($null -eq $serviceApp) { - throw ("Specified Search service application $($params.SearchServiceAppName)" + ` + $message = ("Specified Search service application $($params.SearchServiceAppName)" + ` "does not exist.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($serviceApp) $providers = $fedManager.ListProviders() if ($providers.Keys -notcontains $params.ProviderType) { - throw ("Unknown ProviderType ($($params.ProviderType)) is used. Allowed " + ` + $message = ("Unknown ProviderType ($($params.ProviderType)) is used. Allowed " + ` "values are: '" + ($providers.Keys -join "', '") + "'") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $searchOwner = $null diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 index dd4037088..2f5aeddd8 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchServiceApp/MSFT_SPSearchServiceApp.psm1 @@ -224,14 +224,22 @@ function Set-TargetResource # Create the service app as it doesn't exist Write-Verbose -Message "Creating Search Service Application $Name" - Invoke-SPDscCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { + Invoke-SPDscCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` + -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceAppPool = Get-SPServiceApplicationPool $params.ApplicationPool if ($null -eq $serviceAppPool) { - throw ("Specified service application pool $($params.ApplicationPool) does not " + ` + $message = ("Specified service application pool $($params.ApplicationPool) does not " + ` "exist. Please make sure it exists before continuing.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $serviceInstance = Get-SPEnterpriseSearchServiceInstance -Local @@ -271,9 +279,14 @@ function Set-TargetResource } else { - throw ("Please install SharePoint 2019, 2016 or SharePoint 2013 with August " + ` + $message = ("Please install SharePoint 2019, 2016 or SharePoint 2013 with August " + ` "2015 CU or higher before attempting to create a cloud enabled " + ` "search service application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchServiceSettings/MSFT_SPSearchServiceSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchServiceSettings/MSFT_SPSearchServiceSettings.psm1 index afeea055a..55423ed90 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchServiceSettings/MSFT_SPSearchServiceSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchServiceSettings/MSFT_SPSearchServiceSettings.psm1 @@ -119,18 +119,24 @@ function Set-TargetResource $PSBoundParameters.ContainsKey("ContactEmail") -eq $false -and ` $PSBoundParameters.ContainsKey("WindowsServiceAccount") -eq $false) { - throw ("You have to specify at least one of the following parameters: " + ` + $message = ("You have to specify at least one of the following parameters: " + ` "PerformanceLevel, ContactEmail or WindowsServiceAccount") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters # Update the service app that already exists Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $result) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $result) ` -ScriptBlock { $params = $args[0] - $result = $args[1] + $eventSource = $args[1] + $result = $args[2] try { @@ -138,8 +144,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. Search service " + ` + $message = ("No local SharePoint farm was detected. Search service " + ` "settings will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $setParams = @{ } diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 index a489093fc..83c925bf1 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 @@ -237,11 +237,12 @@ function Set-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $CurrentValues) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $CurrentValues) ` -ScriptBlock { - $params = $args[0] - $CurrentValues = $args[1] + $eventSource = $args[1] + $CurrentValues = $args[2] + $ConfirmPreference = 'None' $AllSearchServers = @() @@ -343,7 +344,12 @@ function Set-TargetResource } if ($null -eq $serviceToAdd) { - throw "Unable to locate a search service instance on $serverName" + $message = "Unable to locate a search service instance on $serverName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $AllSearchServiceInstances.Add($server, $serviceToAdd) } @@ -352,8 +358,12 @@ function Set-TargetResource $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName if ($null -eq $ssa) { - throw "Search service applications '$($params.ServiceAppName)' was not found" - return + $message = "Search service applications '$($params.ServiceAppName)' was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $currentTopology = $ssa.ActiveTopology $newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa ` diff --git a/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 index 7a2d85786..55ac6f805 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSecureStoreServiceApp/MSFT_SPSecureStoreServiceApp.psm1 @@ -257,16 +257,26 @@ function Set-TargetResource ($result.DatabaseServer -ne $DatabaseServer) -and ` ($DatabaseServer -notlike "$($result.DatabaseServer).*")) { - throw ("Specified database server does not match the actual " + ` + $message = ("Specified database server does not match the actual " + ` "database server. This resource cannot move the database " + ` "to a different SQL instance.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("DatabaseName") -and ` ($result.DatabaseName -ne $DatabaseName)) { - throw ("Specified database name does not match the actual " + ` + $message = ("Specified database name does not match the actual " + ` "database name. This resource cannot rename the database.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false ` diff --git a/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 b/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 index ce4732af2..9a951dc66 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSecurityTokenServiceConfig/MSFT_SPSecurityTokenServiceConfig.psm1 @@ -118,8 +118,13 @@ function Set-TargetResource if ($Ensure -eq "Absent") { - throw ("This resource cannot undo Security Token Service Configuration changes. " + ` + $message = ("This resource cannot undo Security Token Service Configuration changes. " + ` "Please set Ensure to Present or omit the resource") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` diff --git a/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 b/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 index 998806a44..d9b758e62 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 @@ -70,17 +70,32 @@ function Get-TargetResource { if ($PSBoundParameters.ContainsKey("ManagedPath") -eq $true) { - throw "Parameter ManagedPath is only supported in SharePoint 2019" + $message = "Parameter ManagedPath is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("AlternateUrl") -eq $true) { - throw "Parameter AlternateUrl is only supported in SharePoint 2019" + $message = "Parameter AlternateUrl is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("UserExperienceVersion") -eq $true) { - throw "Parameter UserExperienceVersion is only supported in SharePoint 2019" + $message = "Parameter UserExperienceVersion is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -88,7 +103,12 @@ function Get-TargetResource if ($PSBoundParameters.ContainsKey("AlternateUrl") -eq $true -and $PSBoundParameters.ContainsKey("ManagedPath") -eq $true) { - throw "You cannot specify both AlternateUrl and ManagedPath. Please use just one of these." + $message = "You cannot specify both AlternateUrl and ManagedPath. Please use just one of these." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -236,17 +256,32 @@ function Set-TargetResource { if ($PSBoundParameters.ContainsKey("ManagedPath") -eq $true) { - throw "Parameter ManagedPath is only supported in SharePoint 2019" + $message = "Parameter ManagedPath is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("AlternateUrl") -eq $true) { - throw "Parameter AlternateUrl is only supported in SharePoint 2019" + $message = "Parameter AlternateUrl is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("UserExperienceVersion") -eq $true) { - throw "Parameter UserExperienceVersion is only supported in SharePoint 2019" + $message = "Parameter UserExperienceVersion is only supported in SharePoint 2019" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -254,7 +289,12 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey("AlternateUrl") -eq $true -and ` $PSBoundParameters.ContainsKey("ManagedPath") -eq $true) { - throw "You cannot specify both AlternateUrl and ManagedPath. Please use just one of these." + $message = "You cannot specify both AlternateUrl and ManagedPath. Please use just one of these." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("UserExperienceVersion") -eq $false) @@ -264,22 +304,33 @@ function Set-TargetResource } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.ContainsKey("AlternateUrl") -and ` $params.AlternateUrl.TrimEnd("/") -in (Get-SPWebApplication).Url.TrimEnd("/")) { - throw ("Specified AlternateUrl is unknown as web application URL. " + ` + $message = ("Specified AlternateUrl is unknown as web application URL. " + ` "Please specify an existing URL") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $webApplication = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $webApplication) { - throw "The specified web application could not be found." + $message = "The specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $webApplicationNeedsUpdate = $false @@ -290,7 +341,12 @@ function Set-TargetResource { if ($ShowStartASiteMenuItem -eq $true) { - throw ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + $message = ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -498,7 +554,12 @@ function Test-TargetResource { if ($ShowStartASiteMenuItem -eq $true) { - throw ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + $message = ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else diff --git a/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 b/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 index 6fbef49dc..242cae557 100644 --- a/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPServiceAppProxyGroup/MSFT_SPServiceAppProxyGroup.psm1 @@ -136,9 +136,14 @@ function Set-TargetResource $ServiceAppProxies -and ` (($ServiceAppProxiesToInclude) -or ($ServiceAppProxiesToExclude))) { - throw ("Cannot use the ServiceAppProxies parameter together " + ` + $message = ("Cannot use the ServiceAppProxies parameter together " + ` "with the ServiceAppProxiesToInclude or " + ` "ServiceAppProxiesToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and ` @@ -146,15 +151,21 @@ function Set-TargetResource !$ServiceAppProxiesToInclude -and ` !$ServiceAppProxiesToExclude) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "ServiceAppProxies, ServiceAppProxiesToInclude, " + ` "ServiceAppProxiesToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.Ensure -eq "Present") { @@ -200,7 +211,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Adding $ServiceProxyName to $($params.name) Proxy Group" @@ -217,7 +233,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Removing $ServiceProxyName from $($params.name) Proxy Group" @@ -236,7 +257,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Adding $ServiceProxyName to $($params.name) Proxy Group" @@ -270,7 +296,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Adding $ServiceProxyName to $($params.name) Proxy Group" @@ -291,7 +322,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose "Adding $ServiceProxyName to $($params.name) Proxy Group" @@ -310,7 +346,12 @@ function Set-TargetResource if ($null -eq $Differences) { - throw "Error comparing ServiceAppProxiesToExclude for Service Proxy Group $($params.name)" + $message = "Error comparing ServiceAppProxiesToExclude for Service Proxy Group $($params.name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { @@ -325,7 +366,12 @@ function Set-TargetResource if (!$ServiceProxy) { - throw "Invalid Service Application Proxy $ServiceProxyName" + $message = "Invalid Service Application Proxy $ServiceProxyName" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Removing $ServiceProxyName to $($params.name) Proxy Group" diff --git a/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 1636c438f..99de75351 100644 --- a/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -34,14 +34,24 @@ function Get-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the MembersToInclude or " + ` + $message = ("Cannot use the Members parameter together with the MembersToInclude or " + ` "MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -eq $Members -and $null -eq $MembersToInclude -and $null -eq $MembersToExclude) { - throw ("At least one of the following parameters must be specified: Members, " + ` + $message = ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -231,28 +241,44 @@ function Set-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the MembersToInclude or " + ` + $message = ("Cannot use the Members parameter together with the MembersToInclude or " + ` "MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -eq $Members -and $null -eq $MembersToInclude -and $null -eq $MembersToExclude) { - throw ("At least one of the following parameters must be specified: Members, " + ` + $message = ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $CurrentValues) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $CurrentValues) ` -ScriptBlock { $params = $args[0] - $CurrentValues = $args[1] + $eventSource = $args[1] + $CurrentValues = $args[2] $serviceApp = Get-SPServiceApplication -Name $params.ServiceAppName if ($null -eq $serviceApp) { - throw "Unable to locate service application $($params.ServiceAppName)" + $message = "Unable to locate service application $($params.ServiceAppName)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Checking if valid AccessLevels are used" @@ -285,8 +311,13 @@ function Set-TargetResource { if ($availablePerms -notcontains $accessLevel) { - throw ("Unknown AccessLevel is used ($accessLevel). Allowed values are " + ` + $message = ("Unknown AccessLevel is used ($accessLevel). Allowed values are " + ` "'" + ($availablePerms -join "', '") + "'") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -301,8 +332,13 @@ function Set-TargetResource { if ($availablePerms -notcontains $accessLevel) { - throw ("Unknown AccessLevel is used ($accessLevel). Allowed values are " + ` + $message = ("Unknown AccessLevel is used ($accessLevel). Allowed values are " + ` "'" + ($availablePerms -join "', '") + "'") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 b/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 index c23340c88..a9a326a1a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPServiceIdentity/MSFT_SPServiceIdentity.psm1 @@ -85,8 +85,11 @@ function Set-TargetResource Write-Verbose -Message "Setting service instance '$Name' to '$ManagedAccount'" - Invoke-SPDscCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { + Invoke-SPDscCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` + -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.Name -eq "SharePoint Server Search") { @@ -99,12 +102,22 @@ function Set-TargetResource } if ($null -eq $serviceInstance) { - throw [System.Exception] "Unable to locate service $($params.Name)" + $message = "Unable to locate service $($params.Name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -eq $serviceInstance.service.processidentity) { - throw [System.Exception] "Service $($params.name) does not support setting the process identity" + $message = "Service $($params.name) does not support setting the process identity" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $processIdentity = $serviceInstance.Service.ProcessIdentity @@ -122,7 +135,12 @@ function Set-TargetResource -ErrorAction SilentlyContinue if ($null -eq $managedAccount) { - throw [System.Exception] "Unable to locate Managed Account $($params.ManagedAccount)" + $message = "Unable to locate Managed Account $($params.ManagedAccount)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $processIdentity.CurrentIdentityType = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser diff --git a/SharePointDsc/DSCResources/MSFT_SPServiceInstance/MSFT_SPServiceInstance.psm1 b/SharePointDsc/DSCResources/MSFT_SPServiceInstance/MSFT_SPServiceInstance.psm1 index bf193240c..a670975a4 100644 --- a/SharePointDsc/DSCResources/MSFT_SPServiceInstance/MSFT_SPServiceInstance.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPServiceInstance/MSFT_SPServiceInstance.psm1 @@ -95,7 +95,7 @@ function Set-TargetResource $newName = (Get-SPDscServiceTypeName -DisplayName $Name) $invokeArgs = @{ Credential = $InstallAccount - Arguments = @($PSBoundParameters, $newName) + Arguments = @($PSBoundParameters, $MyInvocation.MyCommand.Source, $newName) } if ($Ensure -eq "Present") @@ -104,7 +104,8 @@ function Set-TargetResource Invoke-SPDscCommand @invokeArgs -ScriptBlock { $params = $args[0] - $newName = $args[1] + $eventSource = $args[1] + $newName = $args[2] $computerName = $env:COMPUTERNAME $si = Get-SPServiceInstance -Server $computerName -All | Where-Object -FilterScript { @@ -126,7 +127,12 @@ function Set-TargetResource if ($null -eq $si) { - throw [Exception] "Unable to locate service instance '$($params.Name)'" + $message = "Unable to locate service instance '$($params.Name)'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Start-SPServiceInstance -Identity $si @@ -158,7 +164,8 @@ function Set-TargetResource Invoke-SPDscCommand @invokeArgs -ScriptBlock { $params = $args[0] - $newName = $args[1] + $eventSource = $args[1] + $newName = $args[2] $si = Get-SPServiceInstance -Server $env:COMPUTERNAME -All | Where-Object -FilterScript { $_.TypeName -eq $params.Name -or ` @@ -178,7 +185,12 @@ function Set-TargetResource } if ($null -eq $si) { - throw [Exception] "Unable to locate service instance '$($params.Name)'" + $message = "Unable to locate service instance '$($params.Name)'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Stop-SPServiceInstance -Identity $si diff --git a/SharePointDsc/DSCResources/MSFT_SPShellAdmins/MSFT_SPShellAdmins.psm1 b/SharePointDsc/DSCResources/MSFT_SPShellAdmins/MSFT_SPShellAdmins.psm1 index 5d916b83e..9464c83e8 100644 --- a/SharePointDsc/DSCResources/MSFT_SPShellAdmins/MSFT_SPShellAdmins.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPShellAdmins/MSFT_SPShellAdmins.psm1 @@ -200,8 +200,13 @@ function Set-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the " + ` + $message = ("Cannot use the Members parameter together with the " + ` "MembersToInclude or MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Databases) @@ -211,18 +216,28 @@ function Set-TargetResource if ($database.Members -and (($database.MembersToInclude) ` -or ($database.MembersToExclude))) { - throw ("Databases: Cannot use the Members parameter " + ` + $message = ("Databases: Cannot use the Members parameter " + ` "together with the MembersToInclude or " + ` "MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$database.Members ` -and !$database.MembersToInclude ` -and !$database.MembersToExclude) { - throw ("Databases: At least one of the following " + ` + $message = ("Databases: At least one of the following " + ` "parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -230,28 +245,44 @@ function Set-TargetResource { if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { - throw ("At least one of the following parameters must be " + ` + $message = ("At least one of the following parameters must be " + ` "specified: Members, MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } if ($Databases -and $AllDatabases) { - throw ("Cannot use the Databases parameter together with the " + ` + $message = ("Cannot use the Databases parameter together with the " + ` "AllDatabases parameter") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Databases -and $ExcludeDatabases) { - throw ("Cannot use the Databases parameter together with the " + ` + $message = ("Cannot use the Databases parameter together with the " + ` "ExcludeDatabases parameter") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] + $eventSource = $args[1] + $scriptRoot = $args[2] Import-Module -Name (Join-Path -Path $scriptRoot -ChildPath "MSFT_SPShellAdmins.psm1") @@ -261,8 +292,13 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. Shell admin " + ` + $message = ("No local SharePoint farm was detected. Shell admin " + ` "settings will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $shellAdmins = Get-SPShellAdmin @@ -296,10 +332,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell " + ` + $message = ("Error while setting the Shell Admin. The Shell " + ` "Admin permissions will not be applied. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } elseif ($difference.SideIndicator -eq "<=") @@ -311,10 +351,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The Shell Admin " + ` + $message = ("Error while removing the Shell Admin. The Shell Admin " + ` "permissions will not be revoked. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -330,10 +374,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell Admin " + ` + $message = ("Error while setting the Shell Admin. The Shell Admin " + ` "permissions will not be applied. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -354,10 +402,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell Admin " + ` + $message = ("Error while setting the Shell Admin. The Shell Admin " + ` "permissions will not be applied. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -372,9 +424,13 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell Admin " + ` + $message = ("Error while setting the Shell Admin. The Shell Admin " + ` "permissions will not be applied. Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -395,10 +451,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The Shell Admin " + ` + $message = ("Error while removing the Shell Admin. The Shell Admin " + ` "permissions will not be revoked. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -441,10 +501,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The " + ` + $message = ("Error while setting the Shell Admin. The " + ` "Shell Admin permissions will not be applied. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } elseif ($difference.SideIndicator -eq "=>") @@ -458,10 +522,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The " + ` + $message = ("Error while removing the Shell Admin. The " + ` "Shell Admin permissions will not be revoked. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -476,10 +544,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell " + ` + $message = ("Error while setting the Shell Admin. The Shell " + ` "Admin permissions will not be applied. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -500,10 +572,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The " + ` + $message = ("Error while setting the Shell Admin. The " + ` "Shell Admin permissions will not be applied. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -518,10 +594,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell " + ` + $message = ("Error while setting the Shell Admin. The Shell " + ` "Admin permissions will not be applied. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -544,10 +624,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The " + ` + $message = ("Error while removing the Shell Admin. The " + ` "Shell Admin permissions will not be revoked. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -556,7 +640,12 @@ function Set-TargetResource } else { - throw "Specified database does not exist: $($database.Name)" + $message = "Specified database does not exist: $($database.Name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -604,10 +693,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The " + ` + $message = ("Error while setting the Shell Admin. The " + ` "Shell Admin permissions will not be applied. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } elseif ($difference.SideIndicator -eq "<=") @@ -621,10 +714,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The " + ` + $message = ("Error while removing the Shell Admin. The " + ` "Shell Admin permissions will not be revoked. " + ` "Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -640,10 +737,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell Admin " + ` + $message = ("Error while setting the Shell Admin. The Shell Admin " + ` "permissions will not be applied. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -663,10 +764,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell " + ` + $message = ("Error while setting the Shell Admin. The Shell " + ` "Admin permissions will not be applied. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -681,10 +786,14 @@ function Set-TargetResource } catch { - throw ("Error while setting the Shell Admin. The Shell Admin " + ` + $message = ("Error while setting the Shell Admin. The Shell Admin " + ` "permissions will not be applied. Error details: " + ` "$($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -707,10 +816,14 @@ function Set-TargetResource } catch { - throw ("Error while removing the Shell Admin. The Shell " + ` + $message = ("Error while removing the Shell Admin. The Shell " + ` "Admin permissions will not be revoked. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -1070,7 +1183,12 @@ function Test-TargetResource } else { - throw "Specified database does not exist: $($database.Name)" + $message = "Specified database does not exist: $($database.Name)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPSitePropertyBag/MSFT_SPSitePropertyBag.psm1 b/SharePointDsc/DSCResources/MSFT_SPSitePropertyBag/MSFT_SPSitePropertyBag.psm1 index 7c7292877..7a881e6ef 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSitePropertyBag/MSFT_SPSitePropertyBag.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSitePropertyBag/MSFT_SPSitePropertyBag.psm1 @@ -29,15 +29,21 @@ function Get-TargetResource() Write-Verbose -Message "Looking for SPSite property '$Key'" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $spSite = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $spSite) { - throw "Specified site collection could not be found." + $message = "Specified site collection could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -ne $spSite.RootWeb.Properties -and ` @@ -92,15 +98,21 @@ function Set-TargetResource() Write-Verbose -Message "Setting SPSite property '$Key'" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $spSite = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $spSite) { - throw "Specified site collection could not be found." + $message = "Specified site collection could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $spWeb = $spSite.OpenWeb() @@ -123,7 +135,12 @@ function Set-TargetResource() } else { - throw "Cannot retrieve the property bag. Please check if you have the correct permissions." + $message = "Cannot retrieve the property bag. Please check if you have the correct permissions." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPSiteUrl/MSFT_SPSiteUrl.psm1 b/SharePointDsc/DSCResources/MSFT_SPSiteUrl/MSFT_SPSiteUrl.psm1 index 3f21360cb..3b1bf4781 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSiteUrl/MSFT_SPSiteUrl.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSiteUrl/MSFT_SPSiteUrl.psm1 @@ -148,25 +148,41 @@ function Set-TargetResource $PSBoundParameters.ContainsKey("Extranet") -eq $false -and $PSBoundParameters.ContainsKey("Custom") -eq $false) { - throw "No zone specified. Please specify a zone" + $message = "No zone specified. Please specify a zone" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $site = Get-SPSite -Identity $params.Url ` -ErrorAction SilentlyContinue if ($null -eq $site) { - throw "Specified site $($params.Url) does not exist" + $message = "Specified site $($params.Url) does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($site.HostHeaderIsSiteName -eq $false) { - throw "Specified site $($params.Url) is not a Host Named Site Collection" + $message = "Specified site $($params.Url) is not a Host Named Site Collection" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $siteurls = Get-SPSiteUrl -Identity $params.Url @@ -222,8 +238,13 @@ function Set-TargetResource } else { - throw ("Specified URL $($params.Intranet) (Zone: Intranet) is already assigned " + ` + $message = ("Specified URL $($params.Intranet) (Zone: Intranet) is already assigned " + ` "to a site collection: $($siteurl[0].Url)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -236,8 +257,13 @@ function Set-TargetResource } else { - throw ("Specified URL $($params.Internet) (Zone: Internet) is already assigned " + ` + $message = ("Specified URL $($params.Internet) (Zone: Internet) is already assigned " + ` "to a site collection: $($siteurl[0].Url)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -250,8 +276,13 @@ function Set-TargetResource } else { - throw ("Specified URL $($params.Extranet) (Zone: Extranet) is already assigned " + ` + $message = ("Specified URL $($params.Extranet) (Zone: Extranet) is already assigned " + ` "to a site collection: $($siteurl[0].Url)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -264,8 +295,13 @@ function Set-TargetResource } else { - throw ("Specified URL $($params.Custom) (Zone: Custom) is already assigned " + ` + $message = ("Specified URL $($params.Custom) (Zone: Custom) is already assigned " + ` "to a site collection: $($siteurl[0].Url)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPTimerJobState/MSFT_SPTimerJobState.psm1 b/SharePointDsc/DSCResources/MSFT_SPTimerJobState/MSFT_SPTimerJobState.psm1 index 7fc1acccb..fd59fb446 100644 --- a/SharePointDsc/DSCResources/MSFT_SPTimerJobState/MSFT_SPTimerJobState.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPTimerJobState/MSFT_SPTimerJobState.psm1 @@ -29,14 +29,20 @@ function Get-TargetResource if ($TypeName -eq "Microsoft.SharePoint.Administration.Health.SPHealthAnalyzerJobDefinition") { - throw ("You cannot use SPTimerJobState to change the schedule of " + ` + $message = ("You cannot use SPTimerJobState to change the schedule of " + ` "health analyzer timer jobs.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -44,8 +50,13 @@ function Get-TargetResource } catch { - throw ("No local SharePoint farm was detected. Timer job " + ` + $message = ("No local SharePoint farm was detected. Timer job " + ` "settings will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $returnval = @{ @@ -57,7 +68,12 @@ function Get-TargetResource $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw ("Specified web application not found!") + $message = ("Specified web application not found!") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $timerjob = Get-SPTimerJob -Type $params.TypeName ` @@ -65,7 +81,12 @@ function Get-TargetResource if ($timerjob.Count -eq 0) { - throw ("No timer jobs found. Please check the input values") + $message = ("No timer jobs found. Please check the input values") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $returnval.WebAppUrl = $params.WebAppUrl @@ -91,8 +112,13 @@ function Get-TargetResource } else { - throw ("$($timerjob.Count) timer jobs found. Check input " + ` + $message = ("$($timerjob.Count) timer jobs found. Check input " + ` "values or use the WebAppUrl parameter.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } return $returnval @@ -131,14 +157,20 @@ function Set-TargetResource if ($TypeName -eq "Microsoft.SharePoint.Administration.Health.SPHealthAnalyzerJobDefinition") { - throw ("You cannot use SPTimerJobState to change the schedule of " + ` + $message = ("You cannot use SPTimerJobState to change the schedule of " + ` "health analyzer timer jobs.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -146,7 +178,12 @@ function Set-TargetResource } catch { - throw "No local SharePoint farm was detected. Timer job settings will not be applied" + $message = "No local SharePoint farm was detected. Timer job settings will not be applied" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Start update" @@ -156,7 +193,12 @@ function Set-TargetResource $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Specified web application not found!" + $message = "Specified web application not found!" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $timerjob = Get-SPTimerJob -Type $params.TypeName ` @@ -164,7 +206,12 @@ function Set-TargetResource if ($timerjob.Count -eq 0) { - throw ("No timer jobs found. Please check the input values") + $message = ("No timer jobs found. Please check the input values") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("Schedule") -eq $true) @@ -182,13 +229,23 @@ function Set-TargetResource if ($_.Exception.Message -like ` "*The time given was not given in the proper format*") { - throw ("Incorrect schedule format used. New schedule will " + ` + $message = ("Incorrect schedule format used. New schedule will " + ` "not be applied.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { - throw ("Error occurred. Timer job settings will not be applied. " + ` + $message = ("Error occurred. Timer job settings will not be applied. " + ` "Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -207,9 +264,13 @@ function Set-TargetResource } catch { - throw ("Error occurred while enabling job. Timer job settings will " + ` + $message = ("Error occurred while enabling job. Timer job settings will " + ` "not be applied. Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -221,9 +282,13 @@ function Set-TargetResource } catch { - throw ("Error occurred while disabling job. Timer job settings will " + ` + $message = ("Error occurred while disabling job. Timer job settings will " + ` "not be applied. Error details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -249,13 +314,23 @@ function Set-TargetResource if ($_.Exception.Message -like ` "*The time given was not given in the proper format*") { - throw ("Incorrect schedule format used. New schedule will " + ` + $message = ("Incorrect schedule format used. New schedule will " + ` "not be applied.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { - throw ("Error occurred. Timer job settings will not be applied. " + ` + $message = ("Error occurred. Timer job settings will not be applied. " + ` "Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -274,8 +349,13 @@ function Set-TargetResource } catch { - throw ("Error occurred while enabling job. Timer job settings will " + ` + $message = ("Error occurred while enabling job. Timer job settings will " + ` "not be applied. Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -287,8 +367,13 @@ function Set-TargetResource } catch { - throw ("Error occurred while disabling job. Timer job settings will " + ` + $message = ("Error occurred while disabling job. Timer job settings will " + ` "not be applied. Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -296,8 +381,13 @@ function Set-TargetResource } else { - throw ("$($timerjob.Count) timer jobs found. Check input " + ` + $message = ("$($timerjob.Count) timer jobs found. Check input " + ` "values or use the WebAppUrl parameter.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -334,8 +424,13 @@ function Test-TargetResource if ($TypeName -eq "Microsoft.SharePoint.Administration.Health.SPHealthAnalyzerJobDefinition") { - throw ("You cannot use SPTimerJobState to change the schedule of " + ` + $message = ("You cannot use SPTimerJobState to change the schedule of " + ` "health analyzer timer jobs.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 b/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 index 030d7da46..364f3197a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 @@ -189,23 +189,33 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` $PSBoundParameters.ContainsKey("SigningCertificateFilePath")) { - throw ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") - return + $message = ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` !$PSBoundParameters.ContainsKey("SigningCertificateFilePath")) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "SigningCertificateThumbprint, SigningCertificateFilePath.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Creating SPTrustedIdentityTokenIssuer '$Name'" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] + if ($params.SigningCertificateThumbprint) { Write-Verbose -Message ("Getting signing certificate with thumbprint " + ` @@ -213,7 +223,12 @@ function Set-TargetResource if ($params.SigningCertificateThumbprint -notmatch "^[A-Fa-f0-9]{40}$") { - throw ("Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'.") + $message = ("Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $cert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object -FilterScript { @@ -222,14 +237,24 @@ function Set-TargetResource if (!$cert) { - throw ("Signing certificate with thumbprint $($params.SigningCertificateThumbprint) " + ` + $message = ("Signing certificate with thumbprint $($params.SigningCertificateThumbprint) " + ` "was not found in certificate store 'LocalMachine\My'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($cert.HasPrivateKey) { - throw ("SharePoint requires that the private key of the signing certificate" + ` + $message = ("SharePoint requires that the private key of the signing certificate" + ` " is not installed in the certificate store.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } else @@ -242,7 +267,12 @@ function Set-TargetResource } catch { - throw ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + $message = ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -270,7 +300,12 @@ function Set-TargetResource }) if ($null -eq $mappings) { - throw ("IdentifierClaim does not match any claim type specified in ClaimsMappings.") + $message = ("IdentifierClaim does not match any claim type specified in ClaimsMappings.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $runParams = @{ } @@ -286,7 +321,12 @@ function Set-TargetResource if ($null -eq $trust) { - throw "SharePoint failed to create the SPTrustedIdentityTokenIssuer." + $message = "SharePoint failed to create the SPTrustedIdentityTokenIssuer." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($false -eq [String]::IsNullOrWhiteSpace($params.ClaimProviderName)) @@ -425,14 +465,24 @@ function Test-TargetResource if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` $PSBoundParameters.ContainsKey("SigningCertificateFilePath")) { - throw ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") + $message = ("Cannot use both parameters SigningCertificateThumbprint and SigningCertificateFilePath at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -eq $false -and ` $PSBoundParameters.ContainsKey("SigningCertificateFilePath") -eq $false) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "SigningCertificateThumbprint, SigningCertificateFilePath.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 b/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 index adccc85b9..8bc0f08b5 100644 --- a/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuerProviderRealms/MSFT_SPTrustedIdentityTokenIssuerProviderRealms.psm1 @@ -31,14 +31,24 @@ function Get-TargetResource if ($ProviderRealms.Count -gt 0 -and ($ProviderRealmsToInclude.Count -gt 0 -or $ProviderRealmsToExclude.Count -gt 0)) { - throw ("Cannot use the ProviderRealms parameter together with the " + ` + $message = ("Cannot use the ProviderRealms parameter together with the " + ` "ProviderRealmsToInclude or ProviderRealmsToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($ProviderRealms.Count -eq 0 -and $ProviderRealmsToInclude.Count -eq 0 -and $ProviderRealmsToExclude.Count -eq 0) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "ProviderRealms, ProviderRealmsToInclude, ProviderRealmsToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $paramRealms = @{ } @@ -160,16 +170,22 @@ function Set-TargetResource Write-Verbose -Message "Setting SPTrustedIdentityTokenIssuer provider realms" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $trust = Get-SPTrustedIdentityTokenIssuer -Identity $params.IssuerName ` -ErrorAction SilentlyContinue if ($null -eq $trust) { - throw ("SPTrustedIdentityTokenIssuer '$($params.IssuerName)' not found") + $message = ("SPTrustedIdentityTokenIssuer '$($params.IssuerName)' not found") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $trust.ProviderRealms.Clear() @@ -366,12 +382,22 @@ function Get-ProviderRealmsStatus() { if ($includeRealms.Count -gt 0 -or $excludeRealms.Count -gt 0) { - throw ("Parameters ProviderRealmsToInclude and/or ProviderRealmsToExclude can not be used together with Ensure='Absent' use ProviderRealms instead") + $message = ("Parameters ProviderRealmsToInclude and/or ProviderRealmsToExclude can not be used together with Ensure='Absent' use ProviderRealms instead") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($desiredRealms.Count -eq 0) { - throw ("Parameter ProviderRealms is empty or Null") + $message = ("Parameter ProviderRealms is empty or Null") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $eqBoth = $desiredRealms.Keys | Where-Object { diff --git a/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 b/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 index fa7fbc6ad..9e96fc3ef 100644 --- a/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPTrustedRootAuthority/MSFT_SPTrustedRootAuthority.psm1 @@ -40,7 +40,12 @@ function Get-TargetResource { if (-not (Test-Path -Path $CertificateFilePath)) { - throw ("Specified CertificateFilePath does not exist: $CertificateFilePath") + $message = ("Specified CertificateFilePath does not exist: $CertificateFilePath") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -110,8 +115,13 @@ function Set-TargetResource if (-not ($PSBoundParameters.ContainsKey("CertificateThumbprint")) -and ` -not($PSBoundParameters.ContainsKey("CertificateFilePath"))) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "CertificateThumbprint, CertificateFilePath.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("CertificateFilePath") -and ` @@ -119,7 +129,12 @@ function Set-TargetResource { if (-not (Test-Path -Path $CertificateFilePath)) { - throw ("Specified CertificateFilePath does not exist: $CertificateFilePath") + $message = ("Specified CertificateFilePath does not exist: $CertificateFilePath") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -128,9 +143,10 @@ function Set-TargetResource { Write-Verbose -Message "Updating SPTrustedRootAuthority '$Name'" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] if ($params.ContainsKey("CertificateFilePath")) { @@ -142,19 +158,34 @@ function Set-TargetResource } catch { - throw "An error occured: $($_.Exception.Message)" + $message = "An error occured: $($_.Exception.Message)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -eq $cert) { - throw "Import of certificate failed." + $message = "Import of certificate failed." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("CertificateThumbprint")) { if (-not $params.CertificateThumbprint.Equals($cert.Thumbprint)) { - throw "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.CertificateThumbprint))." + $message = "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.CertificateThumbprint))." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -166,7 +197,12 @@ function Set-TargetResource if ($null -eq $cert) { - throw "Certificate not found in the local Certificate Store" + $message = "Certificate not found in the local Certificate Store" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -188,9 +224,10 @@ function Set-TargetResource { Write-Verbose -Message "Adding SPTrustedRootAuthority '$Name'" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { - $params = $args[0] + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` + -ScriptBlock { + $params = $args[0] + $eventSource = $args[1] if ($params.ContainsKey("CertificateFilePath")) { @@ -202,19 +239,34 @@ function Set-TargetResource } catch { - throw "An error occured: $($_.Exception.Message)" + $message = "An error occured: $($_.Exception.Message)" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -eq $cert) { - throw "Import of certificate failed." + $message = "Import of certificate failed." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("CertificateThumbprint")) { if (-not $params.CertificateThumbprint.Equals($cert.Thumbprint)) { - throw "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.CertificateThumbprint))." + $message = "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.CertificateThumbprint))." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -226,7 +278,12 @@ function Set-TargetResource if ($null -eq $cert) { - throw "Certificate not found in the local Certificate Store" + $message = "Certificate not found in the local Certificate Store" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -289,8 +346,13 @@ function Test-TargetResource if (-not ($PSBoundParameters.ContainsKey("CertificateThumbprint")) -and ` -not($PSBoundParameters.ContainsKey("CertificateFilePath"))) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "CertificateThumbprint, CertificateFilePath.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("CertificateFilePath") -and ` @@ -298,7 +360,12 @@ function Test-TargetResource { if (-not (Test-Path -Path $CertificateFilePath)) { - throw ("Specified CertificateFilePath does not exist: $CertificateFilePath") + $message = ("Specified CertificateFilePath does not exist: $CertificateFilePath") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPTrustedSecurityTokenIssuer/MSFT_SPTrustedSecurityTokenIssuer.psm1 b/SharePointDsc/DSCResources/MSFT_SPTrustedSecurityTokenIssuer/MSFT_SPTrustedSecurityTokenIssuer.psm1 index 5573f2b16..4d78062ff 100644 --- a/SharePointDsc/DSCResources/MSFT_SPTrustedSecurityTokenIssuer/MSFT_SPTrustedSecurityTokenIssuer.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPTrustedSecurityTokenIssuer/MSFT_SPTrustedSecurityTokenIssuer.psm1 @@ -49,9 +49,10 @@ function Get-TargetResource Write-Verbose -Message "Getting SPTrustedSecurityTokenIssuer '$Name' settings" $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $spTrust = Get-SPTrustedSecurityTokenIssuer -Identity $params.Name ` -ErrorAction SilentlyContinue @@ -84,7 +85,12 @@ function Get-TargetResource } catch { - throw ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + $message = ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($cert.Thumbprint -match $signingCertificateThumbprint) @@ -199,42 +205,68 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint")) { - throw ("Cannot use both parameters SigningCertificateThumbprint and MetadataEndPoint at the same time.") + $message = ("Cannot use both parameters SigningCertificateThumbprint and MetadataEndPoint at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("SigningCertificateFilePath") -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint")) { - throw ("Cannot use both parameters SigningCertificateFilePath and MetadataEndPoint at the same time.") + $message = ("Cannot use both parameters SigningCertificateFilePath and MetadataEndPoint at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -eq $false -and ` $PSBoundParameters.ContainsKey("SigningCertificateFilePath") -eq $false -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint") -eq $false) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "SigningCertificateThumbprint, SigningCertificateFilePath, MetadataEndPoint.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("MetadataEndPoint") -and ` $PSBoundParameters.ContainsKey("RegisteredIssuerNameIdentifier")) { - throw ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameIdentifier at the same time.") + $message = ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameIdentifier at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("MetadataEndPoint") -and ` $PSBoundParameters.ContainsKey("RegisteredIssuerNameRealm")) { - throw ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameRealm at the same time.") + $message = ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameRealm at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $PSBoundParameters.Add("CurrentValues", $CurrentValues) $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $runParams = @{ } if ($params.Description) @@ -265,13 +297,23 @@ function Set-TargetResource } catch { - throw ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + $message = ("Signing certificate was not found in path '$($params.SigningCertificateFilePath)'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.SigningCertificateThumbprint) { if (-not ($params.SigningCertificateThumbprint -eq $cert.Thumbprint)) { - throw "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.SigningCertificateThumbprint))." + $message = "Imported certificate thumbprint ($($cert.Thumbprint)) does not match expected thumbprint ($($params.SigningCertificateThumbprint))." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -282,7 +324,12 @@ function Set-TargetResource if ($params.SigningCertificateThumbprint -notmatch "^[A-Fa-f0-9]{40}$") { - throw ("Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'.") + $message = ("Parameter SigningCertificateThumbprint does not match valid format '^[A-Fa-f0-9]{40}$'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $cert = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object -FilterScript { @@ -291,8 +338,13 @@ function Set-TargetResource if (!$cert) { - throw ("Signing certificate with thumbprint $($params.SigningCertificateThumbprint) " + ` + $message = ("Signing certificate with thumbprint $($params.SigningCertificateThumbprint) " + ` "was not found in certificate store 'LocalMachine\My'.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } @@ -404,33 +456,58 @@ function Test-TargetResource if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint")) { - throw ("Cannot use both parameters SigningCertificateThumbprint and MetadataEndPoint at the same time.") + $message = ("Cannot use both parameters SigningCertificateThumbprint and MetadataEndPoint at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("SigningCertificateFilePath") -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint")) { - throw ("Cannot use both parameters SigningCertificateFilePath and MetadataEndPoint at the same time.") + $message = ("Cannot use both parameters SigningCertificateFilePath and MetadataEndPoint at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("SigningCertificateThumbprint") -eq $false -and ` $PSBoundParameters.ContainsKey("SigningCertificateFilePath") -eq $false -and ` $PSBoundParameters.ContainsKey("MetadataEndPoint") -eq $false) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "SigningCertificateThumbprint, SigningCertificateFilePath, MetadataEndPoint.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("MetadataEndPoint") -and ` $PSBoundParameters.ContainsKey("RegisteredIssuerNameIdentifier")) { - throw ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameIdentifier at the same time.") + $message = ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameIdentifier at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("MetadataEndPoint") -and ` $PSBoundParameters.ContainsKey("RegisteredIssuerNameRealm")) { - throw ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameRealm at the same time.") + $message = ("Cannot use both parameters MetadataEndPoint and RegisteredIssuerNameRealm at the same time.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # If RegisteredIssuerNameRealm was not set, it won't be present in the $PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 index 91b2eff38..ea02e8e9f 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileProperty/MSFT_SPUserProfileProperty.psm1 @@ -419,10 +419,10 @@ function Set-TargetResource $PSBoundParameters.Ensure = $Ensure Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { - $params = $args[0] + $eventSource = $args[1] if ( ($params.ContainsKey("TermSet") ` -or $params.ContainsKey("TermGroup") ` @@ -432,14 +432,24 @@ function Set-TargetResource -and $params.ContainsKey("TermSet") -eq $false) ) { - throw ("You have to provide all 3 parameters Termset, TermGroup and TermStore " + ` + $message = ("You have to provide all 3 parameters Termset, TermGroup and TermStore " + ` "when providing any of the 3.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("TermSet") ` -and (@("string (single value)", "string (multi value)").Contains($params.Type.ToLower()) -eq $false)) { - throw "Only String and String Multivalue can use Termsets" + $message = "Only String and String Multivalue can use Termsets" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $ups = Get-SPServiceApplication -Name $params.UserProfileService ` @@ -461,8 +471,13 @@ function Set-TargetResource if ($null -eq $userProfileConfigManager) { #if config manager returns when ups is available then isuee is permissions - throw ("Account running process needs admin permissions on the user profile " + ` + $message = ("Account running process needs admin permissions on the user profile " + ` "service application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $coreProperties = $userProfileConfigManager.ProfilePropertyManager.GetCoreProperties() @@ -474,8 +489,13 @@ function Set-TargetResource if ($null -ne $userProfileProperty -and $params.ContainsKey("Type") ` -and $userProfileProperty.CoreProperty.Type -ne $params.Type) { - throw ("Can't change property type. Current Type is " + ` + $message = ("Can't change property type. Current Type is " + ` "$($userProfileProperty.CoreProperty.Type)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $termSet = $null @@ -494,20 +514,35 @@ function Set-TargetResource if ($null -eq $termStore) { - throw "Term Store $($params.termStore) not found" + $message = "Term Store $($params.termStore) not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $group = $termStore.Groups[$params.TermGroup] if ($null -eq $group) { - throw "Term Group $($params.termGroup) not found" + $message = "Term Group $($params.termGroup) not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $termSet = $group.TermSets[$params.TermSet] if ($null -eq $termSet) { - throw "Term Set $($params.termSet) not found" + $message = "Term Set $($params.termSet) not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -637,7 +672,12 @@ function Set-TargetResource if ($null -eq $syncConnection) { - throw "connection not found" + $message = "connection not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -ne $syncConnection.PropertyMapping) @@ -661,7 +701,12 @@ function Set-TargetResource { if ($export) { - throw "not implemented" + $message = "not implemented" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/MSFT_SPUserProfileSection.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/MSFT_SPUserProfileSection.psm1 index d2a0d4223..50dbb576b 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/MSFT_SPUserProfileSection.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileSection/MSFT_SPUserProfileSection.psm1 @@ -114,16 +114,22 @@ function Set-TargetResource $PSBoundParameters.Ensure = $Ensure Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $ups = Get-SPServiceApplication -Name $params.UserProfileService ` -ErrorAction SilentlyContinue if ($null -eq $ups) { - throw "Service application $($params.UserProfileService) not found" + $message = "Service application $($params.UserProfileService) not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $caURL = (Get-SpWebApplication -IncludeCentralAdministration | Where-Object -FilterScript { @@ -137,7 +143,12 @@ function Set-TargetResource if ($null -eq $userProfileConfigManager) { #if config manager returns null when ups is available then isuee is permissions - throw "Account running process needs admin permission on user profile service application" + $message = "Account running process needs admin permission on user profile service application" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $properties = $userProfileConfigManager.GetPropertiesWithSection() $userProfileProperty = $properties.GetSectionByName($params.Name) diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index 0b6909d72..1fc40d4b9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -98,9 +98,14 @@ function Get-TargetResource # InstallAccount used if ($InstallAccount.UserName -eq $farmAccount.UserName) { - throw ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` + $message = ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -120,13 +125,19 @@ function Get-TargetResource } else { - throw ("Unable to retrieve the Farm Account. Check if the farm exists.") + $message = ("Unable to retrieve the Farm Account. Check if the farm exists.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue $nullReturn = @{ @@ -212,7 +223,12 @@ function Get-TargetResource } catch { - throw "The provided My Site Location is not a valid My Site Host." + $message = "The provided My Site Location is not a valid My Site Host." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } return @{ @@ -341,9 +357,14 @@ function Set-TargetResource # InstallAccount used if ($InstallAccount.UserName -eq $farmAccount.UserName) { - throw ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` + $message = ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $setupAccount = $InstallAccount.UserName } @@ -356,9 +377,14 @@ function Set-TargetResource $localaccount = "$($Env:USERDOMAIN)\$($Env:USERNAME)" if ($localaccount -eq $farmAccount.UserName) { - throw ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` + $message = ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` "Account. Make sure the specified PSDSCRunAsCredential isn't the " + ` "Farm Account and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $setupAccount = $localaccount } @@ -366,7 +392,12 @@ function Set-TargetResource } else { - throw ("Unable to retrieve the Farm Account. Check if the farm exists.") + $message = ("Unable to retrieve the Farm Account. Check if the farm exists.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Creating user profile service application $Name" @@ -387,10 +418,11 @@ function Set-TargetResource } $null = Invoke-SPDscCommand -Credential $FarmAccount ` - -Arguments @($PSBoundParameters, $setupAccount) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $setupAccount) ` -ScriptBlock { $params = $args[0] - $setupAccount = $args[1] + $eventSource = $args[1] + $setupAccount = $args[2] $updateEnableNetBIOS = $false if ($params.ContainsKey("EnableNetBIOS")) @@ -428,13 +460,13 @@ function Set-TargetResource $params.Remove("Ensure") | Out-Null } - $params = Rename-SPDscParamValue -params $params ` - -oldName "SyncDBName" ` - -newName "ProfileSyncDBName" + $params = Rename-SPDscParamValue -Params $params ` + -OldName "SyncDBName" ` + -NewName "ProfileSyncDBName" - $params = Rename-SPDscParamValue -params $params ` - -oldName "SyncDBServer" ` - -newName "ProfileSyncDBServer" + $params = Rename-SPDscParamValue -Params $params ` + -OldName "SyncDBServer" ` + -NewName "ProfileSyncDBServer" $pName = "$($params.Name) Proxy" @@ -466,8 +498,13 @@ function Set-TargetResource $app = New-SPProfileServiceApplication @params if ($null -eq $app) { - throw ("An error occurred during creation of the service application: " + ` + $message = ("An error occurred during creation of the service application: " + ` $_.Exception.Message) + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } New-SPProfileServiceApplicationProxy -Name $pName ` -ServiceApplication $app ` diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 index 047d06e3e..640c68be9 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceAppPermissions/MSFT_SPUserProfileServiceAppPermissions.psm1 @@ -164,15 +164,22 @@ function Set-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters } - Invoke-SPDscCommand -Credential $InstallAccount -Arguments @($PSBoundParameters, $CurrentValues) -ScriptBlock { + Invoke-SPDscCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $CurrentValues) ` + -ScriptBlock { $params = $args[0] - $CurrentValues = $args[1] + $eventSource = $args[1] + $CurrentValues = $args[2] $proxy = Get-SPServiceApplicationProxy | Where-Object { $_.DisplayName -eq $params.ProxyName } if ($null -eq $proxy) { - throw "Unable to find service application proxy called '$($params.ProxyName)'" - return + $message = "Unable to find service application proxy called '$($params.ProxyName)'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $security = Get-SPProfileServiceApplicationSecurity -ProfileServiceApplicationProxy $proxy @@ -363,8 +370,13 @@ function Confirm-SPDscUpaPermissionsConfig() ) | ForEach-Object -Process { if (($Parameters.$_ -contains "Everyone") -and ($Parameters.$_ -contains "None")) { - throw ("You can not specify 'Everyone' and 'None' in the same property. " + ` + $message = ("You can not specify 'Everyone' and 'None' in the same property. " + ` "Check the value for the '$_' property on this resource.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 index af457d6f6..876ba8417 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 @@ -328,11 +328,12 @@ function Set-TargetResource } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] + $eventSource = $args[1] + $scriptRoot = $args[2] Import-Module -Name (Join-Path $scriptRoot "MSFT_SPUserProfileSyncConnection.psm1") @@ -344,7 +345,12 @@ function Set-TargetResource if ($null -eq $ups) { - throw "User Profile Service Application $($params.UserProfileService) not found" + $message = "User Profile Service Application $($params.UserProfileService) not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $context = Get-SPDscServiceContext -ProxyGroup $ups.ServiceApplicationProxyGroup @@ -354,7 +360,12 @@ function Set-TargetResource if ($upcm.IsSynchronizationRunning()) { - throw "Synchronization is in Progress." + $message = "Synchronization is in Progress." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # In SP2016, the forest name is used as name but the dot is replaced by a dash @@ -370,7 +381,7 @@ function Set-TargetResource $connection = $upcm.ConnectionManager | Where-Object -FilterScript { $_.DisplayName -eq $Name - } | Select-Object -first 1 + } | Select-Object -First 1 if ($params.Ensure -eq "Present") { @@ -424,7 +435,12 @@ function Set-TargetResource } else { - throw "connection exists and forest is different. use force" + $message = "connection exists and forest is different. use force" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 b/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 index d258bc09f..17fca340c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncService/MSFT_SPUserProfileSyncService.psm1 @@ -25,8 +25,13 @@ function Get-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` + $message = ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` "service via DSC, as 2016/2019 do not use the FIM based sync service.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $farmAccount = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -42,9 +47,14 @@ function Get-TargetResource # InstallAccount used if ($InstallAccount.UserName -eq $farmAccount.UserName) { - throw ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` + $message = ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -56,16 +66,26 @@ function Get-TargetResource $localaccount = "$($Env:USERDOMAIN)\$($Env:USERNAME)" if ($localaccount -eq $farmAccount.UserName) { - throw ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` + $message = ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` "Account. Make sure the specified PSDSCRunAsCredential isn't the " + ` "Farm Account and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } } else { - throw ("Unable to retrieve the Farm Account. Check if the farm exists.") + $message = ("Unable to retrieve the Farm Account. Check if the farm exists.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -161,8 +181,13 @@ function Set-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` + $message = ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` "service via DSC, as 2016/2019 do not use the FIM based sync service.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $farmAccount = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -178,9 +203,14 @@ function Set-TargetResource # InstallAccount used if ($InstallAccount.UserName -eq $farmAccount.UserName) { - throw ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` + $message = ("Specified InstallAccount ($($InstallAccount.UserName)) is the Farm " + ` "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -192,16 +222,26 @@ function Set-TargetResource $localaccount = "$($Env:USERDOMAIN)\$($Env:USERNAME)" if ($localaccount -eq $farmAccount.UserName) { - throw ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` + $message = ("Specified PSDSCRunAsCredential ($localaccount) is the Farm " + ` "Account. Make sure the specified PSDSCRunAsCredential isn't the " + ` "Farm Account and try again") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } } else { - throw ("Unable to retrieve the Farm Account. Check if the farm exists.") + $message = ("Unable to retrieve the Farm Account. Check if the farm exists.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PSBoundParameters.ContainsKey("RunOnlyWhenWriteable") -eq $true) @@ -241,10 +281,11 @@ function Set-TargetResource try { Invoke-SPDscCommand -Credential $FarmAccount ` - -Arguments ($PSBoundParameters, $farmAccount) ` + -Arguments ($PSBoundParameters, $MyInvocation.MyCommand.Source, $farmAccount) ` -ScriptBlock { $params = $args[0] - $farmAccount = $args[1] + $eventSource = $args[1] + $farmAccount = $args[2] $currentServer = $env:COMPUTERNAME @@ -263,7 +304,12 @@ function Set-TargetResource } if ($null -eq $syncService) { - throw "Unable to locate a user profile sync service instance on $currentServer to start" + $message = "Unable to locate a user profile sync service instance on $currentServer to start" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Start the Sync service if it should be running on this server @@ -273,8 +319,13 @@ function Set-TargetResource -ErrorAction SilentlyContinue if ($null -eq $ups) { - throw [Exception] ("No User Profile Service Application was found " + ` + $message = ("No User Profile Service Application was found " + ` "named $($params.UserProfileServiceAppName)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $userName = $farmAccount.UserName @@ -317,7 +368,12 @@ function Set-TargetResource if ($syncService.Status -ne $desiredState) { - throw "An error occured. We couldn't properly set the User Profile Sync Service on the server." + $message = "An error occured. We couldn't properly set the User Profile Sync Service on the server." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -367,8 +423,13 @@ function Test-TargetResource if ((Get-SPDscInstalledProductVersion).FileMajorPart -ne 15) { - throw [Exception] ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` + $message = ("Only SharePoint 2013 is supported to deploy the user profile sync " + ` "service via DSC, as 2016/2019 do not use the FIM based sync service.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters @@ -418,16 +479,22 @@ function Test-SPDscUserProfileDBReadOnly() ) $databaseReadOnly = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $UserProfileServiceAppName ` + -Arguments @($UserProfileServiceAppName, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $UserProfileServiceAppName = $args[0] + $eventSource = $args[1] $serviceApps = Get-SPServiceApplication -Name $UserProfileServiceAppName ` -ErrorAction SilentlyContinue if ($null -eq $serviceApps) { - throw [Exception] ("No user profile service was found " + ` + $message = ("No user profile service was found " + ` "named $UserProfileServiceAppName") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $ups = $serviceApps | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.Office.Server.Administration.UserProfileApplication" diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 index a7af5794c..a014703dc 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppAuthentication/MSFT_SPWebAppAuthentication.psm1 @@ -302,7 +302,12 @@ function Set-TargetResource $PSBoundParameters.ContainsKey("Extranet") -eq $false -and ` $PSBoundParameters.ContainsKey("Custom") -eq $false) { - throw "You have to specify at least one zone." + $message = "You have to specify at least one zone." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Perform test on specified configurations for each zone @@ -333,14 +338,20 @@ function Set-TargetResource # Get current authentication method $authMethod = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Specified Web Application $($params.WebAppUrl) does not exist" + $message = "Specified Web Application $($params.WebAppUrl) does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $authProviders = Get-SPAuthenticationProvider -WebApplication $params.WebAppUrl -Zone Default @@ -404,7 +415,12 @@ function Set-TargetResource # Check if specified zone exists if ($CurrentValues.ContainsKey("Intranet") -eq $false) { - throw "Specified zone Intranet does not exist" + $message = "Specified zone Intranet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Test is current config matches desired config @@ -423,7 +439,12 @@ function Set-TargetResource # Check if specified zone exists if ($CurrentValues.ContainsKey("Internet") -eq $false) { - throw "Specified zone Internet does not exist" + $message = "Specified zone Internet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Test is current config matches desired config @@ -442,7 +463,12 @@ function Set-TargetResource # Check if specified zone exists if ($CurrentValues.ContainsKey("Extranet") -eq $false) { - throw "Specified zone Extranet does not exist" + $message = "Specified zone Extranet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Test is current config matches desired config @@ -461,7 +487,12 @@ function Set-TargetResource # Check if specified zone exists if ($CurrentValues.ContainsKey("Custom") -eq $false) { - throw "Specified zone Custom does not exist" + $message = "Specified zone Custom does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } # Test is current config matches desired config @@ -545,7 +576,12 @@ function Test-TargetResource { if ($CurrentValues.ContainsKey("Intranet") -eq $false) { - throw "Specified zone Intranet does not exist" + $message = "Specified zone Intranet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Test-ZoneConfiguration -DesiredConfig $Intranet ` @@ -563,7 +599,12 @@ function Test-TargetResource { if ($CurrentValues.ContainsKey("Internet") -eq $false) { - throw "Specified zone Internet does not exist" + $message = "Specified zone Internet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Test-ZoneConfiguration -DesiredConfig $Internet ` @@ -581,7 +622,12 @@ function Test-TargetResource { if ($CurrentValues.ContainsKey("Extranet") -eq $false) { - throw "Specified zone Extranet does not exist" + $message = "Specified zone Extranet does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Test-ZoneConfiguration -DesiredConfig $Extranet ` @@ -599,8 +645,13 @@ function Test-TargetResource { if ($CurrentValues.ContainsKey("Custom") -eq $false) { + $message = "Specified zone Custom does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message Write-Verbose -Message "Test-TargetResource returned false" - throw "Specified zone Custom does not exist" } $result = Test-ZoneConfiguration -DesiredConfig $Custom ` @@ -711,6 +762,10 @@ function Test-Parameter() "using WindowsAuthentication" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -728,6 +783,10 @@ function Test-Parameter() "or RoleProvider when using WindowsAuthentication" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -746,6 +805,10 @@ function Test-Parameter() "RoleProvider when using FBA" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -762,6 +825,10 @@ function Test-Parameter() "when using FBA" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -777,6 +844,10 @@ function Test-Parameter() "using FBA" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -795,6 +866,10 @@ function Test-Parameter() "RoleProvider when using Federated" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -811,6 +886,10 @@ function Test-Parameter() "when using Federated" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -826,6 +905,10 @@ function Test-Parameter() "using Federated" if ($Exception) { + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source throw $message } else @@ -855,9 +938,14 @@ function Test-ZoneIsNotClassic() { if ($desiredAuth.AuthenticationMethod -ne "Classic") { - throw ("Specified Web Application is using Classic Authentication and " + ` + $message = ("Specified Web Application is using Classic Authentication and " + ` "Claims Authentication is specified. Please use " + ` "Convert-SPWebApplication first!") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -880,9 +968,10 @@ function Set-ZoneConfiguration() ) Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $ap = @() @@ -919,8 +1008,13 @@ function Set-ZoneConfiguration() -ErrorAction SilentlyContinue if ($null -eq $tokenIssuer) { - throw ("Specified AuthenticationProvider $($zoneConfig.AuthenticationProvider) " + ` + $message = ("Specified AuthenticationProvider $($zoneConfig.AuthenticationProvider) " + ` "does not exist") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $newap = New-SPAuthenticationProvider -TrustedIdentityTokenIssuer $tokenIssuer } diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppBlockedFileTypes/MSFT_SPWebAppBlockedFileTypes.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppBlockedFileTypes/MSFT_SPWebAppBlockedFileTypes.psm1 index 16005f588..124f65867 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppBlockedFileTypes/MSFT_SPWebAppBlockedFileTypes.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppBlockedFileTypes/MSFT_SPWebAppBlockedFileTypes.psm1 @@ -84,16 +84,21 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$WebAppUrl' blocked file types" $null = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] + $eventSource = $args[1] + $ScriptRoot = $args[2] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web application $($params.WebAppUrl) was not found" - return + $message = "Web application $($params.WebAppUrl) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $modulePath = "..\..\Modules\SharePointDsc.WebApplication\SPWebApplication.BlockedFileTypes.psm1" diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 index 203275237..5727132ea 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -65,8 +65,13 @@ function Get-TargetResource if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) { - throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + $message = ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` "ProxyLibrariesToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -206,19 +211,30 @@ function Set-TargetResource if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) { - throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + $message = ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` "ProxyLibrariesToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $webApplication = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $webApplication) { - throw "Web application $($params.WebAppUrl) was not found" + $message = "Web application $($params.WebAppUrl) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $clientCallableSettings = $webApplication.ClientCallableSettings diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppGeneralSettings/MSFT_SPWebAppGeneralSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppGeneralSettings/MSFT_SPWebAppGeneralSettings.psm1 index 6ab1fa5da..dc2efb7bf 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppGeneralSettings/MSFT_SPWebAppGeneralSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppGeneralSettings/MSFT_SPWebAppGeneralSettings.psm1 @@ -238,15 +238,21 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$WebAppUrl' general settings" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] + $eventSource = $args[1] + $ScriptRoot = $args[2] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web application $($params.WebAppUrl) was not found" + $message = "Web application $($params.WebAppUrl) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("DefaultQuotaTemplate")) @@ -256,7 +262,12 @@ function Set-TargetResource $quotaTemplate = $admService.QuotaTemplates[$params.DefaultQuotaTemplate] if ($null -eq $quotaTemplate) { - throw "Quota template $($params.DefaultQuotaTemplate) was not found" + $message = "Quota template $($params.DefaultQuotaTemplate) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppPeoplePickerSettings/MSFT_SPWebAppPeoplePickerSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppPeoplePickerSettings/MSFT_SPWebAppPeoplePickerSettings.psm1 index fd8d03f6f..03dbe0f7c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppPeoplePickerSettings/MSFT_SPWebAppPeoplePickerSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppPeoplePickerSettings/MSFT_SPWebAppPeoplePickerSettings.psm1 @@ -116,15 +116,21 @@ function Set-TargetResource ## Perform changes Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Specified web application could not be found." + $message = "Specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($params.ContainsKey("ActiveDirectoryCustomFilter")) diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 index 2f2235d35..0e51c229a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppPermissions/MSFT_SPWebAppPermissions.psm1 @@ -277,16 +277,22 @@ function Set-TargetResource if ($AllPermissions) { $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl ` -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "The specified web application could not be found." + $message = "The specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $wa.RightsMask = [Microsoft.SharePoint.SPBasePermissions]::FullMask @@ -296,16 +302,22 @@ function Set-TargetResource else { $result = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl ` -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "The specified web application could not be found." + $message = "The specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $newMask = [Microsoft.SharePoint.SPBasePermissions]::EmptyMask @@ -633,8 +645,13 @@ function Test-SPDscInput() # AllPermissions parameter specified with and one of the other parameters if ($ListPermissions -or $SitePermissions -or $PersonalPermissions) { - throw ("Do not specify parameters ListPermissions, SitePermissions " + ` + $message = ("Do not specify parameters ListPermissions, SitePermissions " + ` "or PersonalPermissions when specifying parameter AllPermissions") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else @@ -642,15 +659,25 @@ function Test-SPDscInput() # You have to specify all three parameters if (-not ($ListPermissions -and $SitePermissions -and $PersonalPermissions)) { - throw ("One of the parameters ListPermissions, SitePermissions or " + ` + $message = ("One of the parameters ListPermissions, SitePermissions or " + ` "PersonalPermissions is missing") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } #Checks if ($ListPermissions -contains "Approve Items" -and -not ($ListPermissions -contains "Edit Items")) { - throw "Edit Items is required when specifying Approve Items" + $message = "Edit Items is required when specifying Approve Items" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ListPermissions -contains "Manage Lists" ` @@ -673,37 +700,62 @@ function Test-SPDscInput() -or $PersonalPermissions -contains "Update Personal Web Parts") ` -and -not ($ListPermissions -contains "View Items")) { - throw ("View Items is required when specifying Manage Lists, Override List Behaviors, " + ` + $message = ("View Items is required when specifying Manage Lists, Override List Behaviors, " + ` "Add Items, Edit Items, Delete Items, Approve Items, Open Items, View " + ` "Versions, Delete Versions, Create Alerts, Manage Permissions, Manage Web Site, " + ` "Add and Customize Pages, Manage Alerts, Use Client Integration Features, " + ` "Manage Personal Views, Add/Remove Personal Web Parts or Update Personal Web Parts") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ListPermissions -contains "View Versions" ` -or $SitePermissions -contains "Manage Permissions") ` -and -not ($ListPermissions -contains "Open Items")) { - throw "Open Items is required when specifying View Versions or Manage Permissions" + $message = "Open Items is required when specifying View Versions or Manage Permissions" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ListPermissions -contains "Delete Versions" ` -or $SitePermissions -contains "Manage Permissions") ` -and -not ($ListPermissions -contains "View Versions")) { - throw "View Versions is required when specifying Delete Versions or Manage Permissions" + $message = "View Versions is required when specifying Delete Versions or Manage Permissions" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($SitePermissions -contains "Manage Alerts" ` -and -not ($ListPermissions -contains "Create Alerts")) { - throw "Create Alerts is required when specifying Manage Alerts" + $message = "Create Alerts is required when specifying Manage Alerts" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($SitePermissions -contains "Manage Web Site" ` -and -not ($SitePermissions -contains "Add and Customize Pages")) { - throw "Add and Customize Pages is required when specifying Manage Web Site" + $message = "Add and Customize Pages is required when specifying Manage Web Site" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($SitePermissions -contains "Manage Permissions" ` @@ -712,8 +764,13 @@ function Test-SPDscInput() -or $SitePermissions -contains "Enumerate Permissions") ` -and -not ($SitePermissions -contains "Browse Directories")) { - throw ("Browse Directories is required when specifying Manage Permissions, Manage Web " + ` + $message = ("Browse Directories is required when specifying Manage Permissions, Manage Web " + ` "Site, Add and Customize Pages or Enumerate Permissions") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ListPermissions -contains "Manage Lists" ` @@ -744,7 +801,7 @@ function Test-SPDscInput() -or $PersonalPermissions -contains "Update Personal Web Parts") ` -and -not ($SitePermissions -contains "View Pages")) { - throw ("View Pages is required when specifying Manage Lists, Override List Behaviors, " + ` + $message = ("View Pages is required when specifying Manage Lists, Override List Behaviors, " + ` "Add Items, Edit Items, Delete Items, View Items, Approve Items, Open Items, " + ` "View Versions, Delete Versions, Create Alerts, Manage Permissions, View Web " + ` "Analytics Data, Create Subsites, Manage Web Site, Add and Customize Pages, " + ` @@ -752,14 +809,24 @@ function Test-SPDscInput() "Directories, Use Self-Service Site Creation, Enumerate Permissions, Manage " + ` "Alerts, Manage Personal Views, Add/Remove Personal Web Parts or Update " + ` "Personal Web Parts") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($SitePermissions -contains "Manage Permissions" ` -or $SitePermissions -contains "Manage Web Site") ` -and -not ($SitePermissions -contains "Enumerate Permissions")) { - throw ("Enumerate Permissions is required when specifying Manage Permissions or " + ` + $message = ("Enumerate Permissions is required when specifying Manage Permissions or " + ` "Manage Web Site") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($SitePermissions -contains "Manage Permissions" ` @@ -771,15 +838,25 @@ function Test-SPDscInput() -or $SitePermissions -contains "Edit Personal User Information") ` -and -not ($SitePermissions -contains "Browse User Information")) { - throw ("Browse User Information is required when specifying Manage Permissions, " + ` + $message = ("Browse User Information is required when specifying Manage Permissions, " + ` "Create Subsites, Manage Web Site, Create Groups, Use Self-Service Site " + ` "Creation, Enumerate Permissions or Edit Personal User Information") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($SitePermissions -contains "Use Client Integration Features" ` -and -not ($SitePermissions -contains "Use Remote Interfaces")) { - throw "Use Remote Interfaces is required when specifying Use Client Integration Features" + $message = "Use Remote Interfaces is required when specifying Use Client Integration Features" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($ListPermissions -contains "Manage Lists" ` @@ -816,13 +893,23 @@ function Test-SPDscInput() -or $PersonalPermissions -contains "Update Personal Web Parts") ` -and -not ($SitePermissions -contains "Open")) { - throw "Open is required when specifying any of the other permissions" + $message = "Open is required when specifying any of the other permissions" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($PersonalPermissions -contains "Add/Remove Personal Web Parts" ` -and -not ($PersonalPermissions -contains "Update Personal Web Parts")) { - throw "Update Personal Web Parts is required when specifying Add/Remove Personal Web Parts" + $message = "Update Personal Web Parts is required when specifying Add/Remove Personal Web Parts" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppPolicy/MSFT_SPWebAppPolicy.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppPolicy/MSFT_SPWebAppPolicy.psm1 index 285f6a1c3..977801b2d 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppPolicy/MSFT_SPWebAppPolicy.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppPolicy/MSFT_SPWebAppPolicy.psm1 @@ -228,14 +228,24 @@ function Set-TargetResource if ($Members -and (($MembersToInclude) -or ($MembersToExclude))) { - throw ("Cannot use the Members parameter together with the " + ` + $message = ("Cannot use the Members parameter together with the " + ` "MembersToInclude or MembersToExclude parameters") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (!$Members -and !$MembersToInclude -and !$MembersToExclude) { - throw ("At least one of the following parameters must be specified: " + ` + $message = ("At least one of the following parameters must be specified: " + ` "Members, MembersToInclude, MembersToExclude") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } foreach ($member in $Members) @@ -243,8 +253,13 @@ function Set-TargetResource if (($member.ActAsSystemAccount -eq $true) -and ` ($member.PermissionLevel -ne "Full Control")) { - throw ("Members Parameter: You cannot specify ActAsSystemAccount " + ` + $message = ("Members Parameter: You cannot specify ActAsSystemAccount " + ` "with any other permission than Full Control") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -253,8 +268,13 @@ function Set-TargetResource if (($member.ActAsSystemAccount -eq $true) -and ` ($member.PermissionLevel -ne "Full Control")) { - throw ("MembersToInclude Parameter: You cannot specify ActAsSystemAccount " + ` + $message = ("MembersToInclude Parameter: You cannot specify ActAsSystemAccount " + ` "with any other permission than Full Control") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -266,7 +286,12 @@ function Set-TargetResource if ($null -eq $CurrentValues.WebAppUrl) { - throw "Web application does not exist" + $message = "Web application does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $cacheAccounts = Get-SPDscCacheAccountConfiguration -InputParameters $WebAppUrl @@ -275,8 +300,13 @@ function Set-TargetResource { if ($cacheAccounts.SuperUserAccount -eq "" -or $cacheAccounts.SuperReaderAccount -eq "") { - throw ("Cache accounts not configured properly. PortalSuperUserAccount or " + ` + $message = ("Cache accounts not configured properly. PortalSuperUserAccount or " + ` "PortalSuperReaderAccount property is not configured.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -398,7 +428,12 @@ function Set-TargetResource if (($cacheAccounts.SuperUserAccount -eq $member.Username) -or ` ($cacheAccounts.SuperReaderAccount -eq $member.Username)) { - throw "You cannot exclude the Cache accounts from the Web Application Policy" + $message = "You cannot exclude the Cache accounts from the Web Application Policy" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($null -ne $policy) @@ -414,11 +449,12 @@ function Set-TargetResource ## Perform changes Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $PSScriptRoot, $changeUsers) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot, $changeUsers) ` -ScriptBlock { $params = $args[0] - $scriptRoot = $args[1] - $changeUsers = $args[2] + $eventSource = $args[1] + $scriptRoot = $args[2] + $changeUsers = $args[3] $modulePath = "..\..\Modules\SharePointDsc.WebAppPolicy\SPWebAppPolicy.psm1" Import-Module -Name (Join-Path -Path $scriptRoot -ChildPath $modulePath -Resolve) @@ -427,7 +463,12 @@ function Set-TargetResource if ($null -eq $wa) { - throw "Specified web application could not be found." + $message = "Specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $denyAll = $wa.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::DenyAll) @@ -657,8 +698,13 @@ function Test-TargetResource if (($cacheAccounts.SuperUserAccount -eq "") -or ` ($cacheAccounts.SuperReaderAccount -eq "")) { - throw "Cache accounts not configured properly. PortalSuperUserAccount or " + ` + $message = "Cache accounts not configured properly. PortalSuperUserAccount or " + ` "PortalSuperReaderAccount property is not configured." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -839,7 +885,12 @@ function Test-TargetResource if (($cacheAccounts.SuperUserAccount -eq $member.Username) -or ` ($cacheAccounts.SuperReaderAccount -eq $member.Username)) { - throw "You cannot exclude the Cache accounts from the Web Application Policy" + $message = "You cannot exclude the Cache accounts from the Web Application Policy" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } foreach ($policy in $CurrentValues.Members) @@ -898,16 +949,22 @@ function Get-SPDscCacheAccountConfiguration() ) $cacheAccounts = Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $InputParameters ` + -Arguments @($InputParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { Write-Verbose -Message "Retrieving CacheAccounts" $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Specified web application could not be found." + $message = "Specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $returnval = @{ diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 index 468c69a87..28b9165b1 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppSiteUseAndDeletion/MSFT_SPWebAppSiteUseAndDeletion.psm1 @@ -111,9 +111,10 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$WebAppUrl' Site Use and Deletion settings" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] try { @@ -121,21 +122,36 @@ function Set-TargetResource } catch { - throw ("No local SharePoint farm was detected. Site Use and Deletion settings " + ` + $message = ("No local SharePoint farm was detected. Site Use and Deletion settings " + ` "will not be applied") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Configured web application could not be found" + $message = "Configured web application could not be found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } # Check if the specified value is in the range for the configured schedule $job = Get-SPTimerJob -Identity job-dead-site-delete -WebApplication $params.WebAppUrl if ($null -eq $job) { - throw "Dead Site Delete timer job for web application $($params.WebAppUrl) could not be found" + $message = "Dead Site Delete timer job for web application $($params.WebAppUrl) could not be found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { @@ -147,8 +163,13 @@ function Set-TargetResource if (($params.UnusedSiteNotificationsBeforeDeletion -lt 28) -or ($params.UnusedSiteNotificationsBeforeDeletion -gt 168)) { - throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >28 and " + ` + $message = ("Value of UnusedSiteNotificationsBeforeDeletion has to be >28 and " + ` "<168 when the schedule is set to daily") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } "Weekly" @@ -156,8 +177,13 @@ function Set-TargetResource if (($params.UnusedSiteNotificationsBeforeDeletion -lt 4) -or ($params.UnusedSiteNotificationsBeforeDeletion -gt 24)) { - throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >4 and " + ` + $message = ("Value of UnusedSiteNotificationsBeforeDeletion has to be >4 and " + ` "<24 when the schedule is set to weekly") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } "Monthly" @@ -165,8 +191,13 @@ function Set-TargetResource if (($params.UnusedSiteNotificationsBeforeDeletion -lt 2) -or ($params.UnusedSiteNotificationsBeforeDeletion -gt 6)) { - throw ("Value of UnusedSiteNotificationsBeforeDeletion has to be >2 and " + ` + $message = ("Value of UnusedSiteNotificationsBeforeDeletion has to be >2 and " + ` "<6 when the schedule is set to monthly") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 index 0a61a3e1b..5a13a0e23 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 @@ -129,16 +129,26 @@ function Set-TargetResource -or $PSBoundParameters.ContainsKey("SuiteNavBrandingLogoUrl") ` -or $PSBoundParameters.ContainsKey("SuiteNavBrandingText")) { - throw ("Cannot specify SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, " + ` + $message = ("Cannot specify SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, " + ` "SuiteNavBrandingLogoUrl or SuiteNavBrandingText with SharePoint 2013. Instead," + ` " only specify the SuiteBarBrandingElementHtml parameter") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } <# Exception: The SP2013 optional parameter is null. #> if (!$PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { - throw ("You need to specify a value for the SuiteBarBrandingElementHtml parameter with" + ` + $message = ("You need to specify a value for the SuiteBarBrandingElementHtml parameter with" + ` " SharePoint 2013") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } 16 @@ -172,9 +182,14 @@ function Set-TargetResource -and !$PSBoundParameters.ContainsKey("SuiteNavBrandingText") ` -and !$PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { - throw ("You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, " + ` + $message = ("You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, " + ` "SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl, SuiteNavBrandingText " + ` "or SuiteBarBrandingElementHtml with SharePoint 2016") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -183,14 +198,20 @@ function Set-TargetResource if ($null -eq $CurrentValues.WebAppUrl) { - throw "Web application does not exist" + $message = "Web application does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } ## Perform changes Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $installedVersion = Get-SPDscInstalledProductVersion @@ -198,7 +219,12 @@ function Set-TargetResource if ($null -eq $wa) { - throw "Specified web application could not be found." + $message = "Specified web application could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Processing changes" diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 index 4f9665e11..9d9c0bbb3 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppThrottlingSettings/MSFT_SPWebAppThrottlingSettings.psm1 @@ -153,16 +153,24 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$WebAppUrl' throttling settings" - $paramArgs = @($PSBoundParameters, $PSScriptRoot) + $paramArgs = @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) - $null = Invoke-SPDscCommand -Credential $InstallAccount -Arguments $paramArgs -ScriptBlock { + $null = Invoke-SPDscCommand -Credential $InstallAccount ` + -Arguments $paramArgs ` + -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] + $eventSource = $args[1] + $ScriptRoot = $args[2] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web application $($params.WebAppUrl) was not found" + $message = "Web application $($params.WebAppUrl) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $relPath = "..\..\Modules\SharePointDsc.WebApplication\SPWebApplication.Throttling.psm1" diff --git a/SharePointDsc/DSCResources/MSFT_SPWebAppWorkflowSettings/MSFT_SPWebAppWorkflowSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebAppWorkflowSettings/MSFT_SPWebAppWorkflowSettings.psm1 index 1c28dfa0c..f3f51f738 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebAppWorkflowSettings/MSFT_SPWebAppWorkflowSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebAppWorkflowSettings/MSFT_SPWebAppWorkflowSettings.psm1 @@ -84,18 +84,23 @@ function Set-TargetResource Write-Verbose -Message "Setting web application '$WebAppUrl' workflow settings" - $paramArgs = @($PSBoundParameters, $PSScriptRoot) + $paramArgs = @($PSBoundParameters, $MyInvocation.MyCommand.Source, $PSScriptRoot) $null = Invoke-SPDscCommand -Credential $InstallAccount ` -Arguments $paramArgs ` -ScriptBlock { $params = $args[0] - $ScriptRoot = $args[1] + $eventSource = $args[1] + $ScriptRoot = $args[2] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web application $($params.WebAppUrl) was not found" - return + $message = "Web application $($params.WebAppUrl) was not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } $relpath = "..\..\Modules\SharePointDsc.WebApplication\SPWebApplication.Workflow.psm1" diff --git a/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 index 76c5c2adf..5397c4c2c 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebApplication/MSFT_SPWebApplication.psm1 @@ -191,9 +191,10 @@ function Set-TargetResource if ($Ensure -eq "Present") { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.Name -ErrorAction SilentlyContinue if ($null -eq $wa) @@ -223,15 +224,23 @@ function Set-TargetResource { if ($_.Exception.Message -like "*No matching accounts were found*") { - throw ("The specified managed account was not found. Please make " + ` + $message = ("The specified managed account was not found. Please make " + ` "sure the managed account exists before continuing.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } else { - throw ("Error occurred. Web application was not created. Error " + ` + $message = ("Error occurred. Web application was not created. Error " + ` "details: $($_.Exception.Message)") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } diff --git a/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 b/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 index ac2116c42..b7d4a1835 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWebApplicationExtension/MSFT_SPWebApplicationExtension.psm1 @@ -182,14 +182,20 @@ function Set-TargetResource if ($Ensure -eq "Present") { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web Application with URL $($params.WebAppUrl) does not exist" + $message = "Web Application with URL $($params.WebAppUrl) does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } @@ -241,14 +247,20 @@ function Set-TargetResource if ($Ensure -eq "Absent") { Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue if ($null -eq $wa) { - throw "Web Application with URL $($params.WebAppUrl) does not exist" + $message = "Web Application with URL $($params.WebAppUrl) does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } if ($null -ne $wa) { diff --git a/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/MSFT_SPWordAutomationServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/MSFT_SPWordAutomationServiceApp.psm1 index 7a490c0be..5cbd436b5 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/MSFT_SPWordAutomationServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWordAutomationServiceApp/MSFT_SPWordAutomationServiceApp.psm1 @@ -122,13 +122,23 @@ function Get-TargetResource $MaximumConversionTime) -and ` ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and -not ($ApplicationPool -and $DatabaseName)) { - throw ("An Application Pool and Database Name are required to configure the Word " + ` + $message = ("An Application Pool and Database Name are required to configure the Word " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -327,15 +337,25 @@ function Set-TargetResource $MaximumConversionTime) -and ` ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $PSBoundParameters.Ensure = $Ensure if (($Ensure -eq "Present") -and -not ($ApplicationPool -and $DatabaseName)) { - throw ("An Application Pool and Database Name are required to configure the Word " + ` + $message = ("An Application Pool and Database Name are required to configure the Word " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters @@ -343,9 +363,10 @@ function Set-TargetResource { Write-Verbose -Message "Creating Word Automation Service Application $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool if ($appPool) @@ -379,7 +400,12 @@ function Set-TargetResource } else { - throw "Specified application pool does not exist" + $message = "Specified application pool does not exist" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } } @@ -388,9 +414,10 @@ function Set-TargetResource { Write-Verbose -Message "Updating Word Automation Service Application $Name" Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $serviceApp = Get-SPServiceApplication -Name $params.Name ` | Where-Object -FilterScript { @@ -501,7 +528,12 @@ function Set-TargetResource } else { - throw "Timerjob could not be found" + $message = "Timerjob could not be found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } } if ($params.NumberOfConversionsPerProcess) @@ -687,13 +719,23 @@ function Test-TargetResource $MaximumConversionTime) -and ` ($Ensure -eq "Absent")) { - throw "You cannot use any of the parameters when Ensure is specified as Absent" + $message = "You cannot use any of the parameters when Ensure is specified as Absent" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Ensure -eq "Present") -and -not ($ApplicationPool -and $DatabaseName)) { - throw ("An Application Pool and Database Name are required to configure the Word " + ` + $message = ("An Application Pool and Database Name are required to configure the Word " + ` "Automation Service Application") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 b/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 index 1eced4077..ea8193108 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWorkManagementServiceApp/MSFT_SPWorkManagementServiceApp.psm1 @@ -55,9 +55,14 @@ function Get-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -eq 16) { - throw [Exception] ("Work Management Service Application is no longer available " + ` + $message = ("Work Management Service Application is no longer available " + ` "in SharePoint 2016/2019: " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Invoke-SPDscCommand -Credential $InstallAccount ` @@ -173,14 +178,24 @@ function Set-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -eq 16) { - throw [Exception] ("Work Management Service Application is no longer available " + ` + $message = ("Work Management Service Application is no longer available " + ` "in SharePoint 2016/2019: " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Ensure -ne "Absent" -and $PSBoundParameters.ContainsKey("ApplicationPool") -eq $false) { - throw "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" + $message = "Parameter ApplicationPool is required unless service is being removed(Ensure='Absent')" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $result = Get-TargetResource @PSBoundParameters @@ -385,9 +400,14 @@ function Test-TargetResource $installedVersion = Get-SPDscInstalledProductVersion if ($installedVersion.FileMajorPart -eq 16) { - throw [Exception] ("Work Management Service Application is no longer available " + ` + $message = ("Work Management Service Application is no longer available " + ` "in SharePoint 2016/2019: " + ` "https://technet.microsoft.com/en-us/library/mt346112(v=office.16).aspx") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $PSBoundParameters.Ensure = $Ensure @@ -403,14 +423,14 @@ function Test-TargetResource -Source $($MyInvocation.MyCommand.Source) ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("ApplicationPool", - "MinimumTimeBetweenEwsSyncSubscriptionSearches", - "MinimumTimeBetweenProviderRefreshes", - "MinimumTimeBetweenSearchQueries", - "Name", - "NumberOfSubscriptionSyncsPerEwsSyncRun", - "NumberOfUsersEwsSyncWillProcessAtOnce", - "NumberOfUsersPerEwsSyncBatch", - "Ensure") + "MinimumTimeBetweenEwsSyncSubscriptionSearches", + "MinimumTimeBetweenProviderRefreshes", + "MinimumTimeBetweenSearchQueries", + "Name", + "NumberOfSubscriptionSyncsPerEwsSyncRun", + "NumberOfUsersEwsSyncWillProcessAtOnce", + "NumberOfUsersPerEwsSyncBatch", + "Ensure") } else { diff --git a/SharePointDsc/DSCResources/MSFT_SPWorkflowService/MSFT_SPWorkflowService.psm1 b/SharePointDsc/DSCResources/MSFT_SPWorkflowService/MSFT_SPWorkflowService.psm1 index 93232fae8..65a0e5d5e 100644 --- a/SharePointDsc/DSCResources/MSFT_SPWorkflowService/MSFT_SPWorkflowService.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPWorkflowService/MSFT_SPWorkflowService.psm1 @@ -95,15 +95,21 @@ function Set-TargetResource ## Perform changes Invoke-SPDscCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` + -Arguments @($PSBoundParameters, $MyInvocation.MyCommand.Source) ` -ScriptBlock { $params = $args[0] + $eventSource = $args[1] $site = Get-SPSite $params.SPSiteUrl if ($null -eq $site) { - throw "Specified site collection could not be found." + $message = "Specified site collection could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $eventSource + throw $message } Write-Verbose -Message "Processing changes" diff --git a/SharePointDsc/Modules/SharePointDsc.ContentDatabase/SPContentDatabase.psm1 b/SharePointDsc/Modules/SharePointDsc.ContentDatabase/SPContentDatabase.psm1 index b85248e0c..3a81f0532 100644 --- a/SharePointDsc/Modules/SharePointDsc.ContentDatabase/SPContentDatabase.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.ContentDatabase/SPContentDatabase.psm1 @@ -2,11 +2,11 @@ function Mount-SPDscContentDatabase() { param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Collections.Hashtable] $params, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Boolean] $enabled ) @@ -15,17 +15,17 @@ function Mount-SPDscContentDatabase() { $params.Remove("Enabled") } - + if ($params.ContainsKey("Ensure")) { $params.Remove("Ensure") } - + if ($params.ContainsKey("InstallAccount")) { $params.Remove("InstallAccount") } - + if ($params.ContainsKey("MaximumSiteCount")) { $params.MaxSiteCount = $params.MaximumSiteCount @@ -43,9 +43,14 @@ function Mount-SPDscContentDatabase() } catch { - throw ("Error occurred while mounting content database. " + ` + $message = ("Error occurred while mounting content database. " + ` "Content database is not mounted. " + ` "Error details: $($_.Exception.Message)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($cdb.Status -eq "Online") diff --git a/SharePointDsc/Modules/SharePointDsc.ProjectServerConnector/SharePointDsc.ProjectServerConnector.psm1 b/SharePointDsc/Modules/SharePointDsc.ProjectServerConnector/SharePointDsc.ProjectServerConnector.psm1 index 2b7490afd..323369e31 100644 --- a/SharePointDsc/Modules/SharePointDsc.ProjectServerConnector/SharePointDsc.ProjectServerConnector.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.ProjectServerConnector/SharePointDsc.ProjectServerConnector.psm1 @@ -36,7 +36,12 @@ function Get-SPDscProjectServerGlobalPermissionId $errorString += ", $($_.Name)" } } - throw "Unable to find permission '$PermissionName' - acceptable values are: $errorString" + $message = "Unable to find permission '$PermissionName' - acceptable values are: $errorString" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } return $result @@ -62,7 +67,12 @@ function Get-SPDscProjectServerPermissionName if ($null -eq $result) { - throw "Unable to find permission with ID '$PermissionId'" + $message = "Unable to find permission with ID '$PermissionId'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } return $result } @@ -132,12 +142,22 @@ function Get-SPDscProjectServerResourceId } if ($null -eq $script:SPDscReturnVal) { - throw "Resource '$ResourceName' not found" + $message = "Resource '$ResourceName' not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } else { - throw "Resource '$ResourceName' not found" + $message = "Resource '$ResourceName' not found" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } return $script:SPDscReturnVal @@ -198,8 +218,13 @@ function New-SPDscProjectServerWebService $filehash = "44CC60C2227011D08F36A7954C317195C0A44F3D52D51B0F54009AA03EF97E1B2F80A162D76F177E70D1756E42484DF367FACB25920C2C93FB8DFB8A8F5F08A5" if ($filehash -ne (Get-FileHash -Path $psDllPath -Algorithm SHA512).Hash) { - throw ("The hash for ProjectServerServices.dll isn't the expected value. Please make " + ` + $message = ("The hash for ProjectServerServices.dll isn't the expected value. Please make " + ` "sure the correct file exists on the file system.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $bytes = [System.IO.File]::ReadAllBytes($psDllPath) [System.Reflection.Assembly]::Load($bytes) | Out-Null diff --git a/SharePointDsc/Modules/SharePointDsc.Search/SPSearchContentSource.Schedules.psm1 b/SharePointDsc/Modules/SharePointDsc.Search/SPSearchContentSource.Schedules.psm1 index 9ef3445de..b4049ced6 100644 --- a/SharePointDsc/Modules/SharePointDsc.Search/SPSearchContentSource.Schedules.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Search/SPSearchContentSource.Schedules.psm1 @@ -44,7 +44,12 @@ function Get-SPDscSearchCrawlSchedule } Default { - throw "An unknown schedule type was detected" + $message = "An unknown schedule type was detected" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } return $result diff --git a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 index 0dfe59da1..c43b80b0a 100644 --- a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 @@ -48,7 +48,7 @@ function Add-SPDscEvent try { Write-EventLog -LogName $LogName -Source $Source ` - -EventID $EventID -Message $Message -EntryType $EntryType + -EventId $EventID -Message $Message -EntryType $EntryType } catch { @@ -68,7 +68,12 @@ function Add-SPDscUserToLocalAdmin if ($UserName.Contains("\") -eq $false) { - throw [Exception] "Usernames should be formatted as domain\username" + $message = "Usernames should be formatted as domain\username" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $domainName = $UserName.Split('\')[0] @@ -190,7 +195,12 @@ function Convert-SPDscADGroupIDToName } else { - throw "Unable to locate group with id $GroupId" + $message = "Unable to locate group with id $GroupId" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -396,7 +406,12 @@ function Get-SPDscFarmVersionInfo if ($null -eq $products) { - throw "Product not found: $ProductToCheck" + $message = "Product not found: $ProductToCheck" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -493,7 +508,12 @@ function Get-SPDscRegistryKey } else { - throw "Specified registry key $Key could not be found." + $message = "Specified registry key $Key could not be found." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } @@ -558,7 +578,12 @@ function Get-SPDscInstalledProductVersion $fullPath = Get-Item $pathToSearch -ErrorAction SilentlyContinue | Sort-Object { $_.Directory } -Descending | Select-Object -First 1 if ($null -eq $fullPath) { - throw 'SharePoint path {C:\Program Files\Common Files\microsoft shared\Web Server Extensions} does not exist' + $message = 'SharePoint path {C:\Program Files\Common Files\microsoft shared\Web Server Extensions} does not exist' + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { @@ -606,9 +631,13 @@ function Invoke-SPDscCommand { if ($Env:USERNAME.Contains("$")) { - throw [Exception] ("You need to specify a value for either InstallAccount " + ` + $message = ("You need to specify a value for either InstallAccount " + ` "or PsDscRunAsCredential.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } Write-Verbose -Message "Executing as the local run as user $($Env:USERDOMAIN)\$($Env:USERNAME)" @@ -626,7 +655,12 @@ function Invoke-SPDscCommand } else { - throw $_ + $message = $_ + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } } @@ -636,10 +670,14 @@ function Invoke-SPDscCommand { if (-not $Env:USERNAME.Contains("$")) { - throw [Exception] ("Unable to use both InstallAccount and " + ` + $message = ("Unable to use both InstallAccount and " + ` "PsDscRunAsCredential in a single resource. Remove one " + ` "and try again.") - return + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } Write-Verbose -Message ("Executing using a provided credential and local PSSession " + ` @@ -675,7 +713,12 @@ function Invoke-SPDscCommand } else { - throw $_ + $message = $_ + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } } finally @@ -723,7 +766,12 @@ function Remove-SPDscUserToLocalAdmin if ($UserName.Contains("\") -eq $false) { - throw [Exception] "Usernames should be formatted as domain\username" + $message = "Usernames should be formatted as domain\username" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $domainName = $UserName.Split('\')[0] @@ -868,8 +916,12 @@ function Test-SPDscRunningAsFarmAccount { if ($Env:USERNAME.Contains("$")) { - throw [Exception] "You need to specify a value for either InstallAccount or PsDscRunAsCredential." - return + $message = "You need to specify a value for either InstallAccount or PsDscRunAsCredential." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $Username = "$($Env:USERDOMAIN)\$($Env:USERNAME)" } @@ -928,14 +980,24 @@ function Test-SPDscParameterState ($DesiredValues.GetType().Name -ne "CimInstance") -and ` ($DesiredValues.GetType().Name -ne "PSBoundParametersDictionary")) { - throw ("Property 'DesiredValues' in Test-SPDscParameterState must be either a " + ` + $message = ("Property 'DesiredValues' in Test-SPDscParameterState must be either a " + ` "Hashtable or CimInstance. Type detected was $($DesiredValues.GetType().Name)") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($DesiredValues.GetType().Name -eq "CimInstance") -and ($null -eq $ValuesToCheck)) { - throw ("If 'DesiredValues' is a CimInstance then property 'ValuesToCheck' must contain " + ` + $message = ("If 'DesiredValues' is a CimInstance then property 'ValuesToCheck' must contain " + ` "a value") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($null -eq $ValuesToCheck) -or ($ValuesToCheck.Count -lt 1)) @@ -1261,7 +1323,12 @@ function Test-SPDscUserIsLocalAdmin if ($UserName.Contains("\") -eq $false) { - throw [Exception] "Usernames should be formatted as domain\username" + $message = "Usernames should be formatted as domain\username" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $accountName = $UserName.Split('\')[1] @@ -1299,7 +1366,12 @@ function Test-SPDscIsADUser if ($null -eq $result) { - throw "Unable to locate identity '$IdentityName' in the current domain." + $message = "Unable to locate identity '$IdentityName' in the current domain." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($result[0].Properties.objectclass -contains "user") @@ -1383,7 +1455,12 @@ function Format-OfficePatchGUID -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" + $message = "The provided Office Patch GUID is not in the expected format (e.g. XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $newPart1 = ConvertTo-ReverseString -InputString $guidParts[0] @@ -1408,7 +1485,12 @@ function ConvertTo-TwoDigitFlipString if ($InputString.Length % 2 -ne 0) { - throw "The input string was not in the correct format. It needs to have an even length." + $message = "The input string was not in the correct format. It needs to have an even length." + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $flippedString = "" diff --git a/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.BlockedFileTypes.psm1 b/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.BlockedFileTypes.psm1 index aee0d0668..560f5bf6b 100644 --- a/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.BlockedFileTypes.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.BlockedFileTypes.psm1 @@ -34,16 +34,26 @@ function Set-SPDscWebApplicationBlockedFileTypeConfig -and (($Settings.ContainsKey("EnsureBlocked") -eq $true) ` -or ($Settings.ContainsKey("EnsureAllowed") -eq $true))) { - throw ("Blocked file types must use either the 'blocked' property or the " + ` + $message = ("Blocked file types must use either the 'blocked' property or the " + ` "'EnsureBlocked' and/or 'EnsureAllowed' properties, but not both.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($Settings.ContainsKey("Blocked") -eq $false) ` -and ($Settings.ContainsKey("EnsureBlocked") -eq $false) ` -and ($Settings.ContainsKey("EnsureAllowed") -eq $false)) { - throw ("Blocked file types must specify at least one property (either 'Blocked, " + ` + $message = ("Blocked file types must specify at least one property (either 'Blocked, " + ` "'EnsureBlocked' or 'EnsureAllowed')") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Settings.ContainsKey("Blocked") -eq $true) @@ -99,16 +109,26 @@ function Test-SPDscWebApplicationBlockedFileTypeConfig -and (($DesiredSettings.ContainsKey("EnsureBlocked") -eq $true) ` -or ($DesiredSettings.ContainsKey("EnsureAllowed") -eq $true))) { - throw ("Blocked file types must use either the 'blocked' property or the " + ` + $message = ("Blocked file types must use either the 'blocked' property or the " + ` "'EnsureBlocked' and/or 'EnsureAllowed' properties, but not both.") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if (($DesiredSettings.ContainsKey("Blocked") -eq $false) ` -and ($DesiredSettings.ContainsKey("EnsureBlocked") -eq $false) ` -and ($DesiredSettings.ContainsKey("EnsureAllowed") -eq $false)) { - throw ("Blocked file types must specify at least one property (either 'Blocked, " + ` + $message = ("Blocked file types must specify at least one property (either 'Blocked, " + ` "'EnsureBlocked' or 'EnsureAllowed')") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($DesiredSettings.ContainsKey("Blocked") -eq $true) @@ -122,7 +142,7 @@ function Test-SPDscWebApplicationBlockedFileTypeConfig else { $message = ("The parameter Blocked does not match the desired state. " + ` - "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.Blocked)") + "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.Blocked)") Write-Verbose -Message $message Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $Source @@ -139,7 +159,7 @@ function Test-SPDscWebApplicationBlockedFileTypeConfig if ($null -ne $itemsToAdd) { $message = ("The parameter EnsureBlocked does not match the desired state. " + ` - "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.EnsureBlocked)") + "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.EnsureBlocked)") Write-Verbose -Message $message Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $Source @@ -155,7 +175,7 @@ function Test-SPDscWebApplicationBlockedFileTypeConfig if ($null -ne $itemsToRemove) { $message = ("The parameter EnsureAllowed does not match the desired state. " + ` - "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.EnsureAllowed)") + "Actual: $($CurrentSettings.Blocked). Desired: $($DesiredSettings.EnsureAllowed)") Write-Verbose -Message $message Add-SPDscEvent -Message $message -EntryType 'Error' -EventID 1 -Source $Source diff --git a/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 b/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 index a89d28c8a..7e5603b7a 100644 --- a/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.WebApplication/SPWebApplication.Throttling.psm1 @@ -87,21 +87,41 @@ function Set-SPDscWebApplicationHappyHourConfig -or (Test-SPDscObjectHasProperty $Settings "Minute") -eq $false ` -or (Test-SPDscObjectHasProperty $Settings "Duration") -eq $false) { - throw "Happy hour settings must include 'hour', 'minute' and 'duration'" + $message = "Happy hour settings must include 'hour', 'minute' and 'duration'" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } else { if ($Settings.Hour -lt 0 -or $Settings.Hour -gt 23) { - throw "Happy hour setting 'hour' must be between 0 and 23" + $message = "Happy hour setting 'hour' must be between 0 and 23" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Settings.Minute -lt 0 -or $Settings.Minute -gt 59) { - throw "Happy hour setting 'minute' must be between 0 and 59" + $message = "Happy hour setting 'minute' must be between 0 and 59" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } if ($Settings.Duration -lt 0 -or $Settings.Duration -gt 23) { - throw "Happy hour setting 'hour' must be between 0 and 23" + $message = "Happy hour setting 'hour' must be between 0 and 23" + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message } $h = $Settings.Hour $m = $Settings.Minute @@ -133,17 +153,17 @@ function Test-SPDscWebApplicationThrottlingConfig -Source $Source ` -DesiredValues $DesiredSettings ` -ValuesToCheck @( - "ListViewThreshold", - "AllowObjectModelOverride", - "AdminThreshold", - "ListViewLookupThreshold", - "HappyHourEnabled", - "UniquePermissionThreshold", - "RequestThrottling", - "ChangeLogEnabled", - "ChangeLogExpiryDays", - "EventHandlersEnabled" - ) + "ListViewThreshold", + "AllowObjectModelOverride", + "AdminThreshold", + "ListViewLookupThreshold", + "HappyHourEnabled", + "UniquePermissionThreshold", + "RequestThrottling", + "ChangeLogEnabled", + "ChangeLogExpiryDays", + "EventHandlersEnabled" + ) if ($testReturn -eq $true) { if ($null -ne $DesiredSettings.HappyHour) diff --git a/tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 index 5adacba00..0fd98cdbc 100644 --- a/tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDSC.SPPowerPointAutomationServiceApp.Tests.ps1 @@ -62,6 +62,28 @@ try Mock -CommandName New-SPPowerPointConversionServiceApplication -MockWith { } Mock -CommandName New-SPPowerPointConversionServiceApplicationProxy -MockWith { } Mock -CommandName Remove-SPServiceApplication -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.ProjectServerConnector.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.ProjectServerConnector.Tests.ps1 index 326be2a48..5d2197a11 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.ProjectServerConnector.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.ProjectServerConnector.Tests.ps1 @@ -79,6 +79,28 @@ try DisableKerberos = $true } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "New-SPDscProjectServerWebService" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 index 4a793b494..cdcc78408 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPAlternateUrl.Tests.ps1 @@ -52,9 +52,30 @@ try Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope # Mocks for all contexts - Mock -CommandName New-SPAlternateURL { } - Mock -CommandName Set-SPAlternateURL { } - Mock -CommandName Remove-SPAlternateURL { } + Mock -CommandName New-SPAlternateURL -MockWith { } + Mock -CommandName Set-SPAlternateURL -MockWith { } + Mock -CommandName Remove-SPAlternateURL -MockWith { } + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPAntivirusSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPAntivirusSettings.Tests.ps1 index 9d8ef5d49..45f981078 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPAntivirusSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPAntivirusSettings.Tests.ps1 @@ -50,6 +50,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPAppCatalog.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPAppCatalog.Tests.ps1 index 9cb7f8ea3..3acb11100 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPAppCatalog.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPAppCatalog.Tests.ps1 @@ -67,6 +67,27 @@ try Mock -CommandName Test-SPDscUserIsLocalAdmin -MockWith { return $false } Mock -CommandName Remove-SPDscUserToLocalAdmin -MockWith { } Mock -CommandName Restart-Service { } + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPAppStoreSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPAppStoreSettings.Tests.ps1 index 29a87b81b..38ecb1753 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPAppStoreSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPAppStoreSettings.Tests.ps1 @@ -56,6 +56,28 @@ try # Mocks for all contexts Mock -CommandName Set-SPAppAcquisitionConfiguration -MockWith { } Mock -CommandName Set-SPOfficeStoreAppsDefaultActivation -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPBCSServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPBCSServiceApp.Tests.ps1 index 21c991db0..d64ef808c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPBCSServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPBCSServiceApp.Tests.ps1 @@ -56,6 +56,28 @@ try # Mocks for all contexts Mock -CommandName Remove-SPServiceApplication -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 index ea110bf7a..5d636e70b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPBlobCacheSettings.Tests.ps1 @@ -115,6 +115,28 @@ try ) Set-Content -Path $Global:SPDscWebConfigFile -Value $Content } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 index 4fa9222f7..de3f54654 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPCacheAccounts.Tests.ps1 @@ -82,6 +82,28 @@ try Value = $Identity -replace "i:0#.w|" } } -ParameterFilter { $IdentityType -eq "EncodedClaim" } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPConfigWizard.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPConfigWizard.Tests.ps1 index 2d8143d68..8b6949df2 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPConfigWizard.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPConfigWizard.Tests.ps1 @@ -55,6 +55,28 @@ try Mock -CommandName Remove-Item -MockWith { } Mock -CommandName Get-Content -MockWith { return "log info" } Mock -CommandName Get-SPDscServerPatchStatus -MockWith { return "UpgradeRequired" } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPContentDatabase.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPContentDatabase.Tests.ps1 index 1a3dd37e8..1245d9161 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPContentDatabase.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPContentDatabase.Tests.ps1 @@ -72,6 +72,28 @@ namespace Microsoft.SharePoint.Administration { Url = "http://sharepoint.contoso.com/" } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDatabaseAAG.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDatabaseAAG.Tests.ps1 index bed18478f..e305d89a4 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDatabaseAAG.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDatabaseAAG.Tests.ps1 @@ -63,6 +63,28 @@ try } } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDesignerSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDesignerSettings.Tests.ps1 index f0e29ad55..cca6d012e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDesignerSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDesignerSettings.Tests.ps1 @@ -55,6 +55,28 @@ try Mock -CommandName Get-SPFarm -MockWith { return @{ } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts @@ -215,15 +237,15 @@ try } It "Should throw an exception in the get method to say that this is not supported" { - { Get-TargetResource @testParams } | Should -Throw "http://aka.ms/xSharePointRemoteIssues" + { Get-TargetResource @testParams } | Should -Throw "http://aka.ms/SharePointDscRemoteIssues" } It "Should throw an exception in the test method to say that this is not supported" { - { Test-TargetResource @testParams } | Should -Throw "http://aka.ms/xSharePointRemoteIssues" + { Test-TargetResource @testParams } | Should -Throw "http://aka.ms/SharePointDscRemoteIssues" } It "Should throw an exception in the set method to say that this is not supported" { - { Set-TargetResource @testParams } | Should -Throw "http://aka.ms/xSharePointRemoteIssues" + { Set-TargetResource @testParams } | Should -Throw "http://aka.ms/SharePointDscRemoteIssues" } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 index 375b2631b..bcf7b9d8b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDiagnosticsProvider.Tests.ps1 @@ -62,6 +62,28 @@ try } Mock -CommandName Set-SPDiagnosticsProvider -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When the Diagnostics Provider passed doesn't exist" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 index 9fb4dcf61..4eb6b3c9c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 @@ -54,6 +54,28 @@ try # Mocks for all contexts Mock -CommandName Set-SPDistributedCacheClientSetting { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 index 5cb726437..c97a3a469 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheService.Tests.ps1 @@ -171,6 +171,28 @@ try } -PassThru -Force) } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 index a0489bf7a..81fa565cb 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 @@ -65,6 +65,28 @@ try Mock -CommandName Set-SPExcelFileLocation -MockWith { } Mock -CommandName Remove-SPExcelFileLocation -MockWith { } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 5c842ecd1..94836ce9a 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -108,6 +108,28 @@ try } return $returnVal } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test Contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarmAdministrators.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarmAdministrators.Tests.ps1 index 9591d4306..648644a73 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarmAdministrators.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarmAdministrators.Tests.ps1 @@ -50,6 +50,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarmPropertyBag.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarmPropertyBag.Tests.ps1 index edba9db31..83e78ff6b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarmPropertyBag.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarmPropertyBag.Tests.ps1 @@ -50,6 +50,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPHealthAnalyzerRuleState.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPHealthAnalyzerRuleState.Tests.ps1 index 37531cddc..dd961e594 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPHealthAnalyzerRuleState.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPHealthAnalyzerRuleState.Tests.ps1 @@ -65,6 +65,28 @@ try IsAdministrationWebApplication = $true } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPIncomingEmailSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPIncomingEmailSettings.Tests.ps1 index 1f8a20b13..e6fada511 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPIncomingEmailSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPIncomingEmailSettings.Tests.ps1 @@ -77,6 +77,28 @@ try $Global:SPDscUpdateCalled = $true } -PassThru return @($serviceInstance) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 index f500e2016..4aed5add0 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPInfoPathFormsServiceConfig.Tests.ps1 @@ -71,6 +71,28 @@ try $global:InfoPathSettingsUpdated = $true } -PassThru } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When the InfoPath Form Services is null" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPInstall.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPInstall.Tests.ps1 index 883556850..568fd0584 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPInstall.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPInstall.Tests.ps1 @@ -97,6 +97,28 @@ try Mock -CommandName Test-Path -MockWith { return $true } -ParameterFilter { $Path -eq (Join-Path -Path $testParams.BinaryDir -ChildPath "setup.exe") } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 index 43ca9b93d..2e0b4b352 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPInstallLanguagePack.Tests.ps1 @@ -84,6 +84,28 @@ try Mock -CommandName Test-Path -MockWith { return $true } -ParameterFilter { $Path -eq (Join-Path -Path $testParams.BinaryDir -ChildPath "setup.exe") } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPInstallPrereqs.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPInstallPrereqs.Tests.ps1 index fb3618ef7..c18f4c085 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPInstallPrereqs.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPInstallPrereqs.Tests.ps1 @@ -165,6 +165,28 @@ try Mock -CommandName Get-SPDscBuildVersion { return $Global:SPDscHelper.CurrentStubBuildNumber.Build } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPIrmSettings.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPIrmSettings.tests.ps1 index 22521a6d6..4e55dbb62 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPIrmSettings.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPIrmSettings.tests.ps1 @@ -56,6 +56,28 @@ try Mock -CommandName Get-SPFarm -MockWith { return @{ } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPLogLevel.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPLogLevel.Tests.ps1 index a300d708a..6565057dc 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPLogLevel.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPLogLevel.Tests.ps1 @@ -53,6 +53,28 @@ try # Mocks for all contexts Mock -CommandName Set-SPLogLevel -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedAccount.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedAccount.Tests.ps1 index d17bacf63..fdcc83f4f 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedAccount.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedAccount.Tests.ps1 @@ -61,6 +61,28 @@ try Mock -CommandName New-SPManagedAccount -MockWith { } Mock -CommandName Set-SPManagedAccount -MockWith { } Mock -CommandName Remove-SPManagedAccount -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index f73d776ee..579391e04 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -192,6 +192,28 @@ try } "@ } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceAppDefault.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceAppDefault.Tests.ps1 index fb9d96cce..89173fc9e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceAppDefault.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceAppDefault.Tests.ps1 @@ -107,6 +107,28 @@ try ) } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "Specified proxy group does not exist" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPMinRoleCompliance.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPMinRoleCompliance.Tests.ps1 index ec5ac9ebc..d8a63eb04 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPMinRoleCompliance.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPMinRoleCompliance.Tests.ps1 @@ -63,6 +63,28 @@ try } -PassThru -Force return $obj } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 index e47f2a250..497ce9ca8 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPOutgoingEmailSettings.Tests.ps1 @@ -50,6 +50,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 index 7447d510a..593200169 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProductUpdate.Tests.ps1 @@ -218,6 +218,28 @@ try } Mock -CommandName Clear-ComObject -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerADResourcePoolSync.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerADResourcePoolSync.Tests.ps1 index c2c840290..e28f396dd 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerADResourcePoolSync.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerADResourcePoolSync.Tests.ps1 @@ -113,6 +113,28 @@ try return $global:SPDscGroupsToReturn[$global:SPDscSidCount - 1] } Mock -CommandName "Convert-SPDscADGroupNameToID" -MockWith { return New-Guid } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerAdditionalSettings.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerAdditionalSettings.tests.ps1 index 2d374d977..d84f12d83 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerAdditionalSettings.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerAdditionalSettings.tests.ps1 @@ -166,6 +166,28 @@ try } -PassThru -Force return $service } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGlobalPermissions.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGlobalPermissions.tests.ps1 index 82417d75e..330cfc9ce 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGlobalPermissions.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGlobalPermissions.tests.ps1 @@ -226,6 +226,28 @@ try } return $permissions[$PermissionId] } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGroup.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGroup.tests.ps1 index a47993033..e1c5f4842 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGroup.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerGroup.tests.ps1 @@ -193,6 +193,28 @@ try } ) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 index 3364e4204..0a2cd76b8 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerLicense.Tests.ps1 @@ -55,6 +55,28 @@ try { Mock -CommandName Enable-ProjectServerLicense -MockWith { } Mock -CommandName Disable-ProjectServerLicense -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerPermissionsMode.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerPermissionsMode.Tests.ps1 index 2e6df9141..9e74e4bb2 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerPermissionsMode.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerPermissionsMode.Tests.ps1 @@ -54,6 +54,28 @@ try if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) { Mock -CommandName Set-SPProjectPermissionMode -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerServiceApp.Tests.ps1 index a09570d23..531415eb0 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerServiceApp.Tests.ps1 @@ -61,6 +61,28 @@ try Mock -CommandName Set-SPProjectServiceApplication -MockWith { } Mock -CommandName Remove-SPServiceApplication -MockWith { } Mock -CommandName New-SPProjectServiceApplicationProxy -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerTimeSheetSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerTimeSheetSettings.Tests.ps1 index fa3b097c3..a2f9ca128 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerTimeSheetSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerTimeSheetSettings.Tests.ps1 @@ -140,6 +140,28 @@ try } -PassThru -Force return $service } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerUserSyncSettings.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerUserSyncSettings.tests.ps1 index 2d5e90961..4ae39c8e1 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerUserSyncSettings.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerUserSyncSettings.tests.ps1 @@ -137,6 +137,28 @@ try } Mock -CommandName "Set-SPProjectUserSync" -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerWssSettings.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerWssSettings.tests.ps1 index fb719e0f6..620c0468e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerWssSettings.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPProjectServerWssSettings.tests.ps1 @@ -142,6 +142,28 @@ try } Mock -CommandName "Set-SPProjectUserSync" -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPPublishServiceApplication.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPPublishServiceApplication.Tests.ps1 index 4883e1e05..b0752da40 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPPublishServiceApplication.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPPublishServiceApplication.Tests.ps1 @@ -61,6 +61,28 @@ try Mock Publish-SPServiceApplication { } Mock Unpublish-SPServiceApplication { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "An invalid service application is specified to be published" { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 index 845bce01d..50a154ef7 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPQuotaTemplate.Tests.ps1 @@ -70,6 +70,28 @@ try Mock -CommandName Get-SPFarm -MockWith { return @{ } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 index 2e4e14bab..2dfd20e05 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchAuthoritativePage.Tests.ps1 @@ -83,6 +83,28 @@ try Mock -CommandName Get-SPEnterpriseSearchQueryDemoted -MockWith { } Mock -CommandName New-SPEnterpriseSearchQueryDemoted -MockWith { } Mock -CommandName Remove-SPEnterpriseSearchQueryDemoted -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 index 82024d991..ff2099975 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 @@ -91,6 +91,28 @@ try Mock -CommandName Start-Sleep -MockWith { } Mock -CommandName Set-SPEnterpriseSearchCrawlContentSource -MockWith { } Mock -CommandName Remove-SPEnterpriseSearchCrawlContentSource -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 index 4e29deede..1a00d866f 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlMapping.Tests.ps1 @@ -74,6 +74,28 @@ try } ` -PassThru -Force) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlRule.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlRule.Tests.ps1 index d729550bc..882591a5e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlRule.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlRule.Tests.ps1 @@ -73,6 +73,28 @@ try } ` -PassThru -Force) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 index 2d6eb5b24..f5565e7a2 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 @@ -72,6 +72,28 @@ try } ` -PassThru -Force) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchFileType.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchFileType.Tests.ps1 index ec93d872b..f16a35dcc 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchFileType.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchFileType.Tests.ps1 @@ -73,6 +73,28 @@ try } ` -PassThru -Force) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When no service applications exist in the current farm" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 index 193e743aa..d70c59678 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 @@ -129,6 +129,28 @@ try Write-Verbose "The Type Microsoft.Office.Server.Search.Administration.Mapping was already added." } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When the property doesn't exist and should" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchMetadataCategory.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchMetadataCategory.Tests.ps1 index 8af0afb71..f232566d6 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchMetadataCategory.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchMetadataCategory.Tests.ps1 @@ -71,6 +71,28 @@ try Mock -CommandName Remove-SPEnterpriseSearchMetadataCategory { return @{ } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 index 9a449b12c..d1ac3408b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 @@ -192,6 +192,28 @@ try } } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 index f22f07a92..4dbd60662 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceApp.Tests.ps1 @@ -103,6 +103,28 @@ try } Mock Import-Module -MockWith { } -ParameterFilter { $_.Name -eq $ModuleName } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceSettings.Tests.ps1 index b9b0888ad..c18189373 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchServiceSettings.Tests.ps1 @@ -58,6 +58,28 @@ try -ArgumentList @("DOMAIN\username", $mockPassword) # Mocks for all contexts + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 index 473345106..936f0595c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 @@ -156,6 +156,28 @@ try } ) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 index daa7117f0..e92e97510 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSecureStoreServiceApp.Tests.ps1 @@ -63,6 +63,28 @@ try Mock -CommandName New-SPSecureStoreServiceApplication -MockWith { return "" } Mock -CommandName New-SPSecureStoreServiceApplicationProxy -MockWith { } Mock -CommandName Set-SPSecureStoreServiceApplication -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 index ebeefeafd..9a8b44942 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSecurityTokenServiceConfig.Tests.ps1 @@ -50,6 +50,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When the Security Token Service is null" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 index b346300ae..9f2d4be7c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 @@ -94,6 +94,28 @@ try ProductBuildPart = $Global:SPDscHelper.CurrentStubBuildNumber.Build } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 index 188464ad6..a00a4bf8a 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppProxyGroup.tests.ps1 @@ -77,6 +77,28 @@ try Name = $TestParams.Name } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 index 33fb31fa9..574547910 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 @@ -82,6 +82,28 @@ try Id = [Guid]"02a0cea2-d4e0-4e4e-ba2e-e532a433cfef" } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 index 4da920586..1d12bc0b7 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceIdentity.Tests.ps1 @@ -66,6 +66,28 @@ try Mock -CommandName Get-SPManagedAccount -MockWith { return "CONTOSO\svc.c2wts" } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceInstance.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceInstance.Tests.ps1 index 73d7dd6ff..9ebbaab55 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPServiceInstance.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPServiceInstance.Tests.ps1 @@ -54,6 +54,28 @@ try # Mocks for all contexts Mock -CommandName Start-SPServiceInstance -MockWith { } Mock -CommandName Stop-SPServiceInstance -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 index e60b8f49f..7966ea0e4 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPShellAdmins.Tests.ps1 @@ -54,6 +54,28 @@ try # Mocks for all contexts Mock -CommandName Add-SPShellAdmin -MockWith { } Mock -CommandName Remove-SPShellAdmin -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSitePropertyBag.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSitePropertyBag.Tests.ps1 index 5f8a14520..762ae5545 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSitePropertyBag.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSitePropertyBag.Tests.ps1 @@ -80,6 +80,28 @@ try } -PassThru return $spSite } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name 'The site collection does not exist' -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSiteUrl.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSiteUrl.Tests.ps1 index 5719a935b..e09dabfe1 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSiteUrl.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSiteUrl.Tests.ps1 @@ -79,6 +79,28 @@ try } } $global:SpDscSPSiteUrlRanOnce = $false + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPTimerJobState.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPTimerJobState.Tests.ps1 index fa1a5039a..c87cb6369 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPTimerJobState.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPTimerJobState.Tests.ps1 @@ -66,6 +66,28 @@ try Mock -CommandName Get-SPWebApplication -MockWith { return @{ } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 index 61c4e9216..5ddb921d1 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuer.Tests.ps1 @@ -107,6 +107,28 @@ try } "@ } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuerProviderRealms.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuerProviderRealms.Tests.ps1 index b628a44e4..106aa3f7a 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuerProviderRealms.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedIdentityTokenIssuerProviderRealms.Tests.ps1 @@ -49,6 +49,28 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "The SPTrustedLoginProvider not exists in the farm" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 index 39064f582..10241aa9a 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedRootAuthority.Tests.ps1 @@ -54,6 +54,28 @@ try Mock -CommandName Remove-SPTrustedRootAuthority -MockWith { } Mock -CommandName Set-SPTrustedRootAuthority -MockWith { } Mock -CommandName New-SPTrustedRootAuthority -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When both CertificalThumbprint and CertificateFilePath are specified and thumbprints does not match (root authority exists)" -Fixture { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedSecurityTokenIssuer.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedSecurityTokenIssuer.Tests.ps1 index d9402937f..9bb1b72a2 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedSecurityTokenIssuer.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPTrustedSecurityTokenIssuer.Tests.ps1 @@ -92,6 +92,28 @@ try } Mock -CommandName Set-SPTrustedSecurityTokenIssuer -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 index 87a86284c..eda82f772 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileProperty.Tests.ps1 @@ -437,6 +437,28 @@ try } Mock -CommandName Get-SPServiceApplication { return $userProfileServiceValidConnection } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "Non-Existing User Profile Service Application" { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 index f644ee1a5..2e674dc94 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSection.Tests.ps1 @@ -188,6 +188,28 @@ try } Mock -CommandName Get-SPServiceApplication -MockWith { return $userProfileService } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } Context -Name "When section doesn't exist" { diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 index bc56b1578..3f81db2d7 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 @@ -165,6 +165,28 @@ try Fake1 = $true }) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 index a75cda671..0782fe85f 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceAppPermissions.Tests.ps1 @@ -84,6 +84,28 @@ try } ) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 index 048770a97..a75457376 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncConnection.Tests.ps1 @@ -263,6 +263,28 @@ try Mock -CommandName Import-Module { } -ParameterFilter { $_.Name -eq $ModuleName } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncService.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncService.Tests.ps1 index 739dbb4f1..3cca8b21d 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncService.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileSyncService.Tests.ps1 @@ -157,6 +157,28 @@ try } -PassThru -Force ) } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppAuthentication.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppAuthentication.Tests.ps1 index a9daee5b2..5d820f72b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppAuthentication.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppAuthentication.Tests.ps1 @@ -55,6 +55,28 @@ try # Mocks for all contexts Mock -CommandName Set-SPWebApplication { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppBlockedFileTypes.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppBlockedFileTypes.Tests.ps1 index 7ae45a147..368a92684 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppBlockedFileTypes.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppBlockedFileTypes.Tests.ps1 @@ -62,6 +62,28 @@ try AllowAnonymous = $false } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 index 1d2244805..91837019d 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 @@ -96,6 +96,28 @@ try } return $webApp } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppGeneralSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppGeneralSettings.Tests.ps1 index bf20db779..c7076cfae 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppGeneralSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppGeneralSettings.Tests.ps1 @@ -62,6 +62,28 @@ try AllowAnonymous = $false } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPeoplePickerSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPeoplePickerSettings.Tests.ps1 index 5a192c039..f10ece39a 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPeoplePickerSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPeoplePickerSettings.Tests.ps1 @@ -77,6 +77,28 @@ try "@ } # Mocks for all contexts + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPermissions.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPermissions.Tests.ps1 index 07c3cb57f..b649279e2 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPermissions.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPermissions.Tests.ps1 @@ -71,6 +71,28 @@ try "@ } # Mocks for all contexts + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 index a4c59ec07..4bb2119b6 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPolicy.Tests.ps1 @@ -85,6 +85,28 @@ try } -ParameterFilter { $IdentityType -eq "WindowsSamAccountName" } Mock -CommandName Remove-SPDscGenericObject { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 index 94ad34858..01fdf8abe 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSiteUseAndDeletion.Tests.ps1 @@ -54,6 +54,28 @@ try # Initialize tests # Mocks for all contexts + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 index ad0be85b4..a3b29b89e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 @@ -54,6 +54,28 @@ try # Initialize tests # Mocks for all contexts + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppThrottlingSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppThrottlingSettings.Tests.ps1 index c4a543ec1..3ddd5a7a7 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppThrottlingSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppThrottlingSettings.Tests.ps1 @@ -62,6 +62,28 @@ try AllowAnonymous = $false } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppWorkflowSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppWorkflowSettings.Tests.ps1 index 242bd6d0c..82bc1c743 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppWorkflowSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebAppWorkflowSettings.Tests.ps1 @@ -62,6 +62,28 @@ try AllowAnonymous = $false } } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 index eac3545b5..62de4b30c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplication.Tests.ps1 @@ -58,6 +58,28 @@ try Mock -CommandName New-SPWebApplication -MockWith { } Mock -CommandName Remove-SPWebApplication -MockWith { } Mock -CommandName Get-SPManagedAccount -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 index b54a4cc5d..914351e1c 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWebApplicationExtension.Tests.ps1 @@ -72,6 +72,28 @@ try Mock -CommandName Remove-SPWebApplication -MockWith { } Mock -CommandName Get-SPTrustedIdentityTokenIssuer -MockWith { } Mock -CommandName Set-SPWebApplication -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWordAutomationServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWordAutomationServiceApp.Tests.ps1 index 354e5c8fe..2017c1cc6 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWordAutomationServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWordAutomationServiceApp.Tests.ps1 @@ -58,6 +58,28 @@ try Mock -CommandName Remove-SPServiceApplication -MockWith { } Mock -CommandName Set-SPWordConversionServiceApplication -MockWith { } Mock -CommandName Set-SPTimerJob { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 index 64f063f1e..89189263f 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWorkManagementServiceApp.Tests.ps1 @@ -60,6 +60,28 @@ try Mock -CommandName Remove-SPServiceApplication -MockWith { } Mock -CommandName New-SPWorkManagementServiceApplication -MockWith { } Mock -CommandName New-SPWorkManagementServiceApplicationProxy -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } } diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPWorkflowService.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPWorkflowService.Tests.ps1 index c92159896..f8de621a0 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPWorkflowService.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPWorkflowService.Tests.ps1 @@ -78,6 +78,28 @@ try } Mock -CommandName Register-SPWorkflowService -MockWith { } + + function Add-SPDscEvent + { + param ( + [Parameter(Mandatory = $true)] + [System.String] + $Message, + + [Parameter(Mandatory = $true)] + [System.String] + $Source, + + [Parameter()] + [ValidateSet('Error', 'Information', 'FailureAudit', 'SuccessAudit', 'Warning')] + [System.String] + $EntryType, + + [Parameter()] + [System.UInt32] + $EventID + ) + } } # Test contexts diff --git a/tests/Unit/SharePointDsc/SharePointDsc.Util.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.Util.Tests.ps1 index e0658b8ac..348639d5f 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.Util.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.Util.Tests.ps1 @@ -67,6 +67,8 @@ try Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Mock -CommandName Add-SPDscEvent -MockWith {} } Context -Name "Validate Get-SPDscAssemblyVersion" -Fixture {