Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
0ecece0
Improve markdown and changelog instructions for clarity and consistency
johlju Aug 21, 2025
276c6c9
Add new public commands for managing SQL Agent Alerts
johlju Aug 23, 2025
92edce7
Add regex pattern to ignore specific word formats in cSpell settings
johlju Aug 23, 2025
57d8b88
Update DSC class-based resource guidelines for clarity and consistency
johlju Aug 23, 2025
76dd156
Clarify guideline to avoid testing verbose or debug messages in Peste…
johlju Aug 23, 2025
d462a1b
Enhance guidelines for ShouldProcess and Force parameter usage in Pow…
johlju Aug 23, 2025
0fd3ee4
Add unit test guidelines for SMO type stubbing and session management
johlju Aug 23, 2025
e021916
Clarify guideline on `InModuleScope` usage for public commands to inc…
johlju Aug 23, 2025
6768018
Clarify OutputType usage in function definitions to specify System.St…
johlju Aug 23, 2025
9f1315d
Add guideline to use ErrorAction 'Stop' for immediate failure visibil…
johlju Aug 23, 2025
38e8096
Remove unused New-SqlDscAgentAlertSmoObject and its associated tests
johlju Aug 23, 2025
a11721c
Update OutputType guideline to specify empty usage for functions with…
johlju Aug 23, 2025
29f28d9
Fix file naming convention in DSC class resource guidelines
johlju Aug 23, 2025
30983a4
Add section for file naming conventions in PowerShell guidelines
johlju Aug 23, 2025
44e4805
Fix indentation for ShouldProcess guidelines in function parameters s…
johlju Aug 23, 2025
e1b0043
Remove sqlcmd.exe from cSpell ignoreRegExpList in settings.json
johlju Aug 23, 2025
7e8fe27
Fix localization keys for SQL Agent Alert functions
johlju Aug 23, 2025
7f6c28b
Update key naming section in localization guidelines for clarity and …
johlju Aug 23, 2025
2be3e9f
Clarify testing guidelines by refining language on verbose/debug mess…
johlju Aug 23, 2025
5de581f
Enhance parameter documentation for SQL Agent Alert functions by addi…
johlju Aug 23, 2025
81f1829
Add clarification for private function naming format in guidelines
johlju Aug 23, 2025
ec839f2
Rename private function
johlju Aug 23, 2025
c9b9e8c
Add guidelines for handling `-MockWith` blocks in tests
johlju Aug 23, 2025
1fee3f9
Refactor mock commands in tests to remove unnecessary `-MockWith` par…
johlju Aug 23, 2025
ced263d
Add guidelines for `$PSDefaultParameterValues` and `-ModuleName` para…
johlju Aug 23, 2025
6f63ee2
Refactor tests for Remove-SqlDscAgentAlert to improve parameter valid…
johlju Aug 23, 2025
7116c8a
Refactor unit tests for SQL DSC Agent Alerts
johlju Aug 23, 2025
3597d33
Refactor New-SqlDscAgentAlert to use static method for alert object c…
johlju Aug 23, 2025
c5ec58d
Update source/Public/Get-SqlDscAgentAlert.ps1
johlju Aug 23, 2025
5c59760
Update source/Public/Set-SqlDscAgentAlert.ps1
johlju Aug 23, 2025
f875e17
Update source/Public/Test-SqlDscAgentAlert.ps1
johlju Aug 23, 2025
8074e3d
Update tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
johlju Aug 23, 2025
a38325f
Add validation for Name parameter in SQL Agent Alert functions
johlju Aug 23, 2025
6993fe4
Refactor Get-SqlDscAgentAlert to streamline alert retrieval and remov…
johlju Aug 23, 2025
c5b8e9b
Add INPUTS section to SQL Agent Alert functions for clarity on expect…
johlju Aug 23, 2025
c1a5fc2
Add Parent property to JobServer class for better hierarchy represent…
johlju Aug 23, 2025
32fe9e1
Add integration tests for SqlDscAgentAlert commands to enhance test c…
johlju Aug 23, 2025
3c42557
Add integration tests for SQL Agent Alert commands, including Get, Ne…
johlju Aug 23, 2025
7f7082d
Fix formatting in integration tests guidelines for ErrorAction parameter
johlju Aug 23, 2025
0d6d99b
Enhance Server creation by initializing JobServer and its Alerts in C…
johlju Aug 23, 2025
83cea57
Refine ShouldProcess pattern by updating message variable names for c…
johlju Aug 23, 2025
4b5acf5
Refactor SQL Agent Alert messages for improved clarity and consistency
johlju Aug 23, 2025
68444ea
Update output documentation for Get-AgentAlertObject to clarify retur…
johlju Aug 23, 2025
8c3e102
Update Get-SqlDscAgentAlert documentation and tests to clarify output…
johlju Aug 23, 2025
a6b13cc
Update New-SqlDscAgentAlert documentation to clarify parameter requir…
johlju Aug 23, 2025
d974935
Remove redundant comment in Get-SqlDscAgentAlert tests for clarity
johlju Aug 23, 2025
95469d2
Clarify best practice for assigning unused return objects in Pester t…
johlju Aug 23, 2025
0c7bd9f
Refactor tests to suppress unused return value warnings for alert man…
johlju Aug 23, 2025
790b81c
Enhance tests for New-SqlDscAgentAlert to verify boundary values and …
johlju Aug 23, 2025
6f42365
Enhance Set-SqlDscAgentAlert to check for unchanged properties before…
johlju Aug 23, 2025
387fb3e
Remove redundant comment in 'When no changes are needed' context for …
johlju Aug 23, 2025
9e27498
Merge branch 'main' into f/refactor-sqlagentalert
johlju Aug 23, 2025
816f511
Clarify requirement for string localization to include removal of orp…
johlju Aug 24, 2025
d5f0b8b
Remove obsolete SQL Agent Alert strings to streamline localization
johlju Aug 24, 2025
a1d3da6
Update source/en-US/SqlServerDsc.strings.psd1
johlju Aug 24, 2025
8d24c97
Update .github/instructions/dsc-community-style-guidelines.instructio…
johlju Aug 24, 2025
0dcf6bb
Remove OUTPUTS section from Remove-SqlDscAgentAlert documentation
johlju Aug 24, 2025
2668b0c
Add Force parameter to Set-SqlDscAgentAlert for non-interactive updates
johlju Aug 24, 2025
32148e6
Clarify 'It' description rule in Pester guidelines to emphasize not u…
johlju Aug 24, 2025
5c85f3e
Refactor integration tests for SqlDscAgentAlert commands to improve c…
johlju Aug 24, 2025
bb8c5b2
Add -ErrorAction Stop to New-SqlDscAgentAlert and related tests for b…
johlju Aug 24, 2025
e013689
Remove redundant cleanup logic for test alerts in Remove-SqlDscAgentA…
johlju Aug 24, 2025
f7332c8
Refactor test cases in Test-SqlDscAgentAlert to improve clarity and c…
johlju Aug 24, 2025
edb9243
Refactor New-SqlDscAgentAlert tests to improve structure and clarity …
johlju Aug 24, 2025
25fa7c9
Refactor tests for Set-SqlDscAgentAlert to improve structure and add …
johlju Aug 24, 2025
67606f7
Add test to verify ServerObject parameter accepts pipeline input in T…
johlju Aug 24, 2025
b9565fc
Set JobServer.Parent property in Server initialization to establish p…
johlju Aug 24, 2025
c32518d
Refactor CreateTypeInstance method to use object initializer for JobS…
johlju Aug 24, 2025
6ee68c3
Set JobServer.Alerts.Parent to establish parent-child relationship in…
johlju Aug 24, 2025
5912913
Fix wording in Test-SqlDscAgentAlert message for clarity
johlju Aug 24, 2025
9317dd8
Update source/Public/Set-SqlDscAgentAlert.ps1
johlju Aug 24, 2025
d5e3f5f
Update .github/instructions/dsc-community-style-guidelines-pester.ins…
johlju Aug 24, 2025
38e8822
Clarify syntax rule for 'It' descriptions in Pester guidelines
johlju Aug 24, 2025
3582c0d
Refactor alert cleanup in integration tests for Get-SqlDscAgentAlert,…
johlju Aug 24, 2025
a694dca
Refactor integration tests for SQL DSC agent alerts to use mock crede…
johlju Aug 24, 2025
ad21960
Update SQL Server connection setup in integration tests to use the co…
johlju Aug 24, 2025
8c1efad
Enhance integration tests for SQL DSC agent alerts by starting and st…
johlju Aug 24, 2025
a33cca4
Add SQL Server system message for testing message ID alerts in integr…
johlju Aug 24, 2025
dfe3d0c
Remove unused variable for computer name in Get-SqlDscRole integratio…
johlju Aug 24, 2025
84bf73b
Add verbose logging for adding SQL Server system message in integrati…
johlju Aug 24, 2025
babe813
Add verbose flag to Invoke-SqlDscQuery for better logging in integrat…
johlju Aug 24, 2025
7ded823
Enhance integration tests for SQL DSC agent alerts by adding error ha…
johlju Aug 24, 2025
b508273
Fix severity levels in duplicate alert tests and ensure error handlin…
johlju Aug 24, 2025
bc7871f
Set conflicting properties to 0 when updating Severity or MessageId i…
johlju Aug 25, 2025
d82b5f8
Add tests to ensure Severity and MessageId are reset to avoid conflic…
johlju Aug 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/instructions/SqlServerDsc-guidelines.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ applyTo: "**"

## Naming
- Public commands: `{Verb}-SqlDsc{Noun}` format
- Private function: `{Verb}-{Noun}` format

## Resources
- Database Engine resources: inherit `SqlResourceBase`
Expand All @@ -24,8 +25,15 @@ applyTo: "**"

## Test Requirements
- Unit tests: Add `$env:SqlServerDscCI = $true` in `BeforeAll`, remove in `AfterAll`
- Integration tests: Use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
- Test config: tests/Integration/Commands/README.md and tests/Integration/Resources/README.md
- Integration test script files must be added to a group
within the test stage in ./azure-pipelines.yml.
- Choose the appropriate group number based on the required dependencies
- Integration tests:
- If requiring SQL Server DB, start the Windows service in `BeforeAll`, stop it in `AfterAll`.
- Use `Connect-SqlDscDatabaseEngine` for SQL Server DB session, and always with correct CI credentials
- Use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine`
- Test config: tests/Integration/Commands/README.md and tests/Integration/Resources/README.md
- Integration test script files must be added to a group within the test stage in ./azure-pipelines.yml.
- Choose the appropriate group number based on the required dependencies

## Unit tests
- When unit test uses SMO types, ensure they are properly stubbed in SMO.cs
- Load stub types from SMO.cs in unit test files, e.g. `Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"`
- After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,73 @@ applyTo: "source/[cC]lasses/**/*.ps1"
**Applies to:** Classes with `[DscResource(...)]` decoration only.

## Requirements
- File: `source/Classes/{ResourceName}.ps1`
- File: `source/Classes/020.{ResourceName}.ps1`
- Decoration: `[DscResource(RunAsCredential = 'Optional')]` (replace with `'Mandatory'` if required)
- Inheritance: Must inherit `ResourceBase` (part of module DscResource.Base)
- `$this.localizedData` hashtable auto-populated by `ResourceBase` from localization file

## Required constructor

```powershell
MyResourceName () : base ($PSScriptRoot)
{
# Property names where state cannot be enforced, e.g Ensure
$this.ExcludeDscProperties = @()
}
```

## Required Method Pattern

```powershell
[MyResourceName] Get()
{
# Call base implementation to get current state
$currentState = ([ResourceBase] $this).Get()

# If needed, post-processing based on returned current state before returning to user
# If needed, post-processing on current state that can not be handled by GetCurrentState()

return $currentState
}

[System.Boolean] Test()
{
# Call base implementation to test current state
$inDesiredState = ([ResourceBase] $this).Test()

# If needed, post-processing based on returned test result before returning to user
# If needed, post-processing on test result that can not be handled by base Test()

return $inDesiredState
}

[void] Set()
{
# Call base implementation to set desired state
([ResourceBase] $this).Set()

# If needed, additional state changes that could not be handled by Modify()
# If needed, additional state changes that can not be handled by Modify()
}

hidden [System.Collections.Hashtable] GetCurrentState([System.Collections.Hashtable] $properties)
{
# Return current state as hashtable
# Variable $properties contains the key properties (key-value pairs).
# Always return current state as hashtable, $properties contains key properties
}

hidden [void] Modify([System.Collections.Hashtable] $properties)
{
# Set desired state for non-compliant properties only
# Variable $properties contains the properties (key-value pairs) that are not in desired state.
# Always set desired state, $properties contain those that must change state
}
```

## Optional Method Pattern

```powershell
hidden [void] AssertProperties([System.Collections.Hashtable] $properties)
{
# Validate user-provided properties
# Variable $properties contains properties user assigned values.
# Validate user-provided properties, $properties contains user assigned values
}

hidden [void] NormalizeProperties([System.Collections.Hashtable] $properties)
{
# Normalize user-provided properties
# Variable $properties contains properties user assigned values.
# Normalize user-provided properties, $properties contains user assigned values
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ applyTo: "tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1"
- Avoid `ExpectedMessage` for `Should -Throw` assertions
- Only run integration tests in CI unless explicitly instructed.
- Call commands with `-Force` parameter where applicable (avoids prompting).
- Use `-ErrorAction Stop` on commands so failures surface immediately

## Required Setup Block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ applyTo: "source/**/*.ps1"
- Commands/functions: `source/en-US/SqlServerDsc.strings.psd1`
- Class resources: `source/en-US/{ResourceClassName}.strings.psd1`

## Key Naming
- Format: `FunctionName_Description` (underscore separators)
- Example: `Get_SqlDscDatabase_ConnectingToDatabase`
## Key Naming Patterns
- Format: `Verb_FunctionName_Action` (underscore separators), e.g. `Get_SqlDscDatabase_ConnectingToDatabase`

## String Format
```powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ applyTo: "**/*.md"
- Use '1.' for all items in ordered lists (1/1/1 numbering style)
- Disable `MD013` rule by adding a comment for tables/code blocks exceeding 80 characters
- Empty lines required before/after code blocks and headings (except before line 1)
- Escape backslashes in file paths only (not in code blocks)
- Code blocks must specify language identifiers

## Text Formatting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ applyTo: "**/*.[Tt]ests.ps1"
- One `Describe` block per file matching the tested entity name
- Test code only inside `Describe` blocks
- Assertions only in `It` blocks
- Never test `Write-Verbose`, `Write-Debug`, or parameter binding behavior
- Never test verbose messages, debug messages or parameter binding behavior
- Pass all mandatory parameters to avoid prompts

## Structure & Scope
Expand All @@ -25,11 +25,15 @@ applyTo: "**/*.[Tt]ests.ps1"

## Syntax Rules
- PascalCase: `Describe`, `Context`, `It`, `Should`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach`
- `It` descriptions start with 'Should'
- `Context` descriptions start with 'When'
- `It` descriptions start with 'Should', must not contain 'when'
- Mock variables prefix: 'mock'
- Prefer `-BeTrue`/`-BeFalse` over `-Be $true`/`-Be $false`
- No `Should -Not -Throw` - invoke commands directly
- Never add an empty `-MockWith` block
- Omit `-MockWith` when returning `$null`
- Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
- Omit `-ModuleName` parameter on Pester commands

## File Organization
- Class resources: `tests/Unit/Classes/{Name}.Tests.ps1`
Expand All @@ -42,7 +46,7 @@ applyTo: "**/*.[Tt]ests.ps1"
- Keep scope close to usage context

## Best Practices
- Assign unused return objects to `$null`
- Inside `It` blocks, assign unused return objects to `$null` (unless part of pipeline)
- Tested entity must be called from within the `It` blocks
- Keep results and assertions in same `It` block
- Cover all scenarios and code paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ applyTo: "**/*.ps?(m|d)1"
- Classes: PascalCase
- Include scope for script/global/environment variables: `$script:`, `$global:`, `$env:`

## File naming

- Class files: `###.ClassName.ps1` format (e.g. `001.SqlReason.ps1`, `004.StartupParameters.ps1`)

## Formatting

### Indentation & Spacing
Expand Down Expand Up @@ -71,8 +75,10 @@ applyTo: "**/*.ps?(m|d)1"
- Avoid `Write-Output` (use `return` instead)
- Avoid `ConvertTo-SecureString -AsPlainText` in production code
- Don't redefine reserved parameters (Verbose, Debug, etc.)
- Include a `Force` parameter for functions that support `$PSCmdlet.ShouldContinue` or that use `$PSCmdlet.ShouldProcess`
- Include a `Force` parameter for functions that uses `$PSCmdlet.ShouldContinue` or `$PSCmdlet.ShouldProcess`
- For state-changing functions, use `SupportsShouldProcess`
- Place ShouldProcess check immediately before each state-change
- `$PSCmdlet.ShouldProcess` must use required pattern
- Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors, use relevant error category
- Use `Write-Error` for non-terminating errors, use relevant error category
- Use `Write-Warning` for warnings
Expand All @@ -81,6 +87,32 @@ applyTo: "**/*.ps?(m|d)1"
- Use `Write-Information` for informational messages.
- Never use backtick as line continuation in production code.

## ShouldProcess Required Pattern

- Ensure `$descriptionMessage` explains what will happen
- Ensure `$confirmationMessage` succinctly asks for confirmation
- Keep `$captionMessage` short and descriptive (no trailing `.`)

```powershell
$descriptionMessage = $script:localizedData.FunctionName_Action_ShouldProcessDescription -f $param1, $param2
$confirmationMessage = $script:localizedData.FunctionName_Action_ShouldProcessConfirmation -f $param1
$captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption

if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
{
# state changing code
}
```

## Force Parameter Pattern

```powershell
if ($Force.IsPresent -and -not $Confirm)
{
$ConfirmPreference = 'None'
}
```

### Structure

```powershell
Expand All @@ -107,7 +139,7 @@ applyTo: "**/*.ps?(m|d)1"
function Get-Something
{
[CmdletBinding()]
[OutputType([String])]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true)]
Expand All @@ -128,7 +160,7 @@ function Get-Something
- Include `[CmdletBinding()]` on every function
- Parameter block at top
- Parameter block: `param ()` if empty, else opening/closing parentheses on own lines
- `[OutputType()]` for functions with output
- `[OutputType({return type})]` for functions with output, no output use `[OutputType()]`
- All parameters use `[Parameter()]` attribute, mandatory parameters use `[Parameter(Mandatory = $true)]`
- Parameter attributes on separate lines
- Parameter type on line above parameter name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ applyTo: "**"
## Requirements
- Follow guidelines over existing code patterns
- Always update CHANGELOG.md Unreleased section
- Localize all strings using string keys
- Localize all strings using string keys; remove any orphaned string keys
- Check DscResource.Common before creating private functions
- Separate reusable logic into private functions
- Add unit tests for all commands/functions/resources
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"/@prkelly/g",
"/@glennsarti/g",
"/tempdb/g",
"/sqlcmd\\.exe/g"
"/\\b[A-Za-z]{2,}\\d{4}\\b/g"
],
"[markdown]": {
"files.trimTrailingWhitespace": true,
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Throws a terminating error if the specified principal does not exist as a login.
- Supports pipeline input and provides detailed error messages with localization.
- Uses `Test-SqlDscIsLogin` command for login validation following module patterns.
- Added `Get-SqlDscLogin`, `Get-SqlDscRole`, `New-SqlDscLogin`, `New-SqlDscRole`, `Remove-SqlDscRole`, and `Remove-SqlDscLogin` commands for retrieving and managing SQL Server logins and roles with support for refresh, pipeline input, and ShouldProcess.
- Added `Get-SqlDscLogin`, `Get-SqlDscRole`, `New-SqlDscLogin`, `New-SqlDscRole`,
`Remove-SqlDscRole`, and `Remove-SqlDscLogin` commands for retrieving and managing
SQL Server logins and roles with support for refresh, pipeline input, and ShouldProcess.
- Added `Get-SqlDscAgentAlert`, `New-SqlDscAgentAlert`,
`Set-SqlDscAgentAlert`, `Remove-SqlDscAgentAlert`, and `Test-SqlDscAgentAlert`
to manage SQL Agent alerts on a Database Engine instance.

### Changed

Expand Down Expand Up @@ -77,7 +82,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DSC community style guidelines
- Added requirement to follow guidelines over existing code patterns.
- Improved markdown, pester, powershell, and changelog instructions.
- Fixed `Ingore` that seems in edge-cases fail.
- Fixed `Ignore` that seems in edge-cases fail.
- Improved markdown and changelog instructions.

## [17.1.0] - 2025-05-22

Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ stages:
'tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1'
'tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1'
'tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1'
'tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1'
'tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1'

# Group 9
'tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1'
)
Expand Down
50 changes: 50 additions & 0 deletions source/Private/Get-AgentAlertObject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<#
.SYNOPSIS
Gets a SQL Agent Alert object from the JobServer.

.DESCRIPTION
Gets a SQL Agent Alert object from the JobServer based on the specified name.

.PARAMETER ServerObject
Specifies the SQL Server object.

.PARAMETER Name
Specifies the name of the SQL Agent Alert.

.OUTPUTS
Microsoft.SqlServer.Management.Smo.Agent.Alert

Returns the SQL Agent Alert object when an alert with the specified name is found.

.OUTPUTS
None.

When no alert with the specified name is found.

.EXAMPLE
$serverObject = Connect-SqlDscDatabaseEngine
Get-AgentAlertObject -ServerObject $serverObject -Name 'MyAlert'

Gets the SQL Agent Alert named 'MyAlert'.
#>
function Get-AgentAlertObject
{
[CmdletBinding()]
[OutputType([Microsoft.SqlServer.Management.Smo.Agent.Alert])]
param
(
[Parameter(Mandatory = $true)]
[Microsoft.SqlServer.Management.Smo.Server]
$ServerObject,

[Parameter(Mandatory = $true)]
[System.String]
$Name
)

Write-Verbose -Message ($script:localizedData.Get_AgentAlertObject_GettingAlert -f $Name)

$alertObject = $ServerObject.JobServer.Alerts | Where-Object -FilterScript { $_.Name -eq $Name }

return $alertObject
}
Loading
Loading