diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eebb14894..136e5e460d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `New-SqlDscDatabase` + - Added comprehensive set of settable database properties that were previously + only available in `Set-SqlDscDatabaseProperty` + ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)). + +### Changed + +- `Set-SqlDscDatabaseProperty` + - Updated comment-based help to reference correct enum values. + - Added SQL Server version requirements to version-specific parameter help. + +### Fixed + +- `New-SqlDscDatabase` + - Fixed parameter types for database-scoped configuration properties from + `System.Boolean` to `Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff` + to match SMO property types and support all valid values (Off, On, Primary) + ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)). + - Fixed parameter types for boolean database properties from `System.Boolean` to + `System.Management.Automation.SwitchParameter` to follow PowerShell best practices. + ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)). +- `Set-SqlDscDatabaseProperty` + - Fixed parameter types for database-scoped configuration properties from + `System.Boolean` to `Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff` + to match SMO property types and support all valid values (Off, On, Primary) + ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)). + - Fixed parameter types for boolean database properties from `System.Boolean` to + `System.Management.Automation.SwitchParameter` to follow PowerShell best practices. + ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)). + ## [17.3.0] - 2025-12-01 ### Removed diff --git a/source/Public/New-SqlDscDatabase.ps1 b/source/Public/New-SqlDscDatabase.ps1 index 7140cae906..3a1ea0ef5b 100644 --- a/source/Public/New-SqlDscDatabase.ps1 +++ b/source/Public/New-SqlDscDatabase.ps1 @@ -40,6 +40,229 @@ after the database is created. This parameter requires SQL Server 2022 (version 16) or later, or Azure SQL Database. + .PARAMETER AcceleratedRecoveryEnabled + Specifies whether Accelerated Database Recovery (ADR) is enabled for the database. + This parameter requires SQL Server 2019 (version 15) or later. + + .PARAMETER AnsiNullDefault + Specifies whether new columns allow NULL by default unless explicitly specified (when ON). + + .PARAMETER AnsiNullsEnabled + Specifies whether comparisons to NULL follow ANSI SQL behavior (when ON, x = NULL yields UNKNOWN). + + .PARAMETER AnsiPaddingEnabled + Specifies whether padding for variable-length columns (e.g., CHAR/VARCHAR) follows ANSI rules. + + .PARAMETER AnsiWarningsEnabled + Specifies whether ANSI warnings are generated for certain conditions (when ON, e.g., divide by zero). + + .PARAMETER ArithmeticAbortEnabled + Specifies whether a query is terminated when an overflow or divide-by-zero error occurs. + + .PARAMETER AutoClose + Specifies whether the database closes after the last user exits. + + .PARAMETER AutoCreateIncrementalStatisticsEnabled + Specifies whether creation of incremental statistics on partitioned tables is allowed. + + .PARAMETER AutoCreateStatisticsEnabled + Specifies whether single-column statistics are automatically created for query optimization. + + .PARAMETER AutoShrink + Specifies whether the database automatically shrinks files when free space is detected. + + .PARAMETER AutoUpdateStatisticsAsync + Specifies whether statistics are updated asynchronously, allowing queries to proceed with old stats. + + .PARAMETER AutoUpdateStatisticsEnabled + Specifies whether statistics are automatically updated when they are out-of-date. + + .PARAMETER BrokerEnabled + Specifies whether Service Broker is enabled for the database. + + .PARAMETER ChangeTrackingAutoCleanUp + Specifies whether automatic cleanup of change tracking information is enabled. + + .PARAMETER ChangeTrackingEnabled + Specifies whether change tracking is enabled for the database. + + .PARAMETER ChangeTrackingRetentionPeriod + Specifies the retention period value for change tracking information. + + .PARAMETER ChangeTrackingRetentionPeriodUnits + Specifies the units for the retention period (e.g., DAYS, HOURS). + + .PARAMETER CloseCursorsOnCommitEnabled + Specifies whether open cursors are closed when a transaction is committed. + + .PARAMETER ConcatenateNullYieldsNull + Specifies whether concatenation with NULL results in NULL (when ON). + + .PARAMETER ContainmentType + Specifies the containment level of the database (NONE or PARTIAL). + + .PARAMETER DatabaseOwnershipChaining + Specifies whether ownership chaining across objects within the database is enabled. + + .PARAMETER DataRetentionEnabled + Specifies whether SQL Server data retention policy is enabled at the database level. + This parameter requires SQL Server 2017 (version 14) or later. + + .PARAMETER DateCorrelationOptimization + Specifies whether date correlation optimization is enabled to speed up temporal joins. + + .PARAMETER DefaultFullTextLanguage + Specifies the LCID of the default full-text language. + + .PARAMETER DefaultLanguage + Specifies the ID of the default language for the database. + + .PARAMETER DelayedDurability + Specifies the delayed durability setting for the database (DISABLED, ALLOWED, FORCED). + + .PARAMETER EncryptionEnabled + Specifies whether Transparent Data Encryption (TDE) is enabled. + + .PARAMETER FilestreamDirectoryName + Specifies the directory name used for FILESTREAM data. + + .PARAMETER FilestreamNonTransactedAccess + Specifies the FILESTREAM access level for non-transactional access. + + .PARAMETER HonorBrokerPriority + Specifies whether honoring Service Broker conversation priority is enabled. + + .PARAMETER IsFullTextEnabled + Specifies whether full-text search is enabled. + + .PARAMETER IsParameterizationForced + Specifies whether forced parameterization is enabled for the database. + + .PARAMETER IsReadCommittedSnapshotOn + Specifies whether READ_COMMITTED_SNAPSHOT isolation is ON. + + .PARAMETER IsSqlDw + Specifies whether the database is a SQL Data Warehouse database. + + .PARAMETER IsVarDecimalStorageFormatEnabled + Specifies whether vardecimal compression is enabled. + + .PARAMETER LegacyCardinalityEstimation + Specifies the legacy cardinality estimator setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). + + .PARAMETER LegacyCardinalityEstimationForSecondary + Specifies the legacy cardinality estimator setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). + + .PARAMETER LocalCursorsDefault + Specifies whether cursors are local by default instead of global (when ON). + + .PARAMETER MaxDop + Specifies the MAXDOP database-scoped configuration for primary replicas. + + .PARAMETER MaxDopForSecondary + Specifies the MAXDOP database-scoped configuration for secondary replicas. + + .PARAMETER MaxSizeInBytes + Specifies the maximum size of the database in bytes. + + .PARAMETER MirroringPartner + Specifies the mirroring partner server name (if configured). + + .PARAMETER MirroringPartnerInstance + Specifies the mirroring partner instance name (if configured). + + .PARAMETER MirroringRedoQueueMaxSize + Specifies the redo queue maximum size for mirroring/AGs. + + .PARAMETER MirroringSafetyLevel + Specifies the mirroring safety level (FULL/Off/HighPerformance). + + .PARAMETER MirroringTimeout + Specifies the timeout in seconds for mirroring sessions. + + .PARAMETER MirroringWitness + Specifies the mirroring witness server (if used). + + .PARAMETER NestedTriggersEnabled + Specifies whether triggers are allowed to fire other triggers (nested triggers). + + .PARAMETER NumericRoundAbortEnabled + Specifies whether an error is raised on loss of precision due to rounding (when ON). + + .PARAMETER PageVerify + Specifies the page verification setting (NONE, TORN_PAGE_DETECTION, CHECKSUM). + + .PARAMETER ParameterSniffing + Specifies the parameter sniffing setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). + + .PARAMETER ParameterSniffingForSecondary + Specifies the parameter sniffing setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). + + .PARAMETER PersistentVersionStoreFileGroup + Specifies the filegroup used for the Persistent Version Store (PVS). + This parameter requires SQL Server 2019 (version 15) or later. + + .PARAMETER PrimaryFilePath + Specifies the path of the primary data files directory. + + .PARAMETER QueryOptimizerHotfixes + Specifies the query optimizer hotfixes setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). + + .PARAMETER QueryOptimizerHotfixesForSecondary + Specifies the query optimizer hotfixes setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). + + .PARAMETER QuotedIdentifiersEnabled + Specifies whether identifiers can be delimited by double quotes (when ON). + + .PARAMETER ReadOnly + Specifies whether the database is in read-only mode. + + .PARAMETER RecursiveTriggersEnabled + Specifies whether a trigger is allowed to fire itself recursively. + + .PARAMETER RemoteDataArchiveCredential + Specifies the credential name for Stretch Database/remote data archive. + + .PARAMETER RemoteDataArchiveEnabled + Specifies whether Stretch Database (remote data archive) is enabled. + + .PARAMETER RemoteDataArchiveEndpoint + Specifies the endpoint URL for remote data archive. + + .PARAMETER RemoteDataArchiveLinkedServer + Specifies the linked server used by remote data archive. + + .PARAMETER RemoteDataArchiveUseFederatedServiceAccount + Specifies whether to use federated service account for remote data archive. + + .PARAMETER RemoteDatabaseName + Specifies the remote database name for remote data archive. + + .PARAMETER TargetRecoveryTime + Specifies the target recovery time (seconds) for indirect checkpointing. + + .PARAMETER TemporalHistoryRetentionEnabled + Specifies whether automatic cleanup of system-versioned temporal history is enabled. + This parameter requires SQL Server 2017 (version 14) or later. + + .PARAMETER TransformNoiseWords + Specifies how full-text noise word behavior is controlled during queries. + + .PARAMETER Trustworthy + Specifies whether implicit access to external resources by modules is allowed (use with caution). + + .PARAMETER TwoDigitYearCutoff + Specifies the two-digit year cutoff used for date conversion. + + .PARAMETER UserAccess + Specifies the database user access mode. Valid values are Multiple, Restricted, and Single. + .PARAMETER DatabaseSnapshotBaseName Specifies the name of the source database from which to create a snapshot. When this parameter is specified, a database snapshot will be created instead @@ -103,12 +326,21 @@ using specification objects created with the -AsSpec parameter. All properties are set directly via parameters without prompting for confirmation. + .EXAMPLE + $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' + $serverObject | New-SqlDscDatabase -Name 'MyDatabase' -LegacyCardinalityEstimation 'On' -ParameterSniffing 'Off' -QueryOptimizerHotfixes 'On' -Force + + Creates a new database named **MyDatabase** with database-scoped configuration settings: + legacy cardinality estimation enabled, parameter sniffing disabled, and query optimizer + hotfixes enabled, without prompting for confirmation. + .OUTPUTS `[Microsoft.SqlServer.Management.Smo.Database]` #> function New-SqlDscDatabase { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '', Justification = 'RemoteDataArchiveCredential is not a password but a credential name reference.')] [OutputType([Microsoft.SqlServer.Management.Smo.Database])] [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium', DefaultParameterSetName = 'Database')] param @@ -146,9 +378,298 @@ function New-SqlDscDatabase $OwnerName, [Parameter(ParameterSetName = 'Database')] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsLedger, + # Boolean Properties + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AcceleratedRecoveryEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AnsiNullDefault, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AnsiNullsEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AnsiPaddingEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AnsiWarningsEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $ArithmeticAbortEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoClose, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoCreateIncrementalStatisticsEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoCreateStatisticsEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoShrink, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoUpdateStatisticsAsync, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $AutoUpdateStatisticsEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $BrokerEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $ChangeTrackingAutoCleanUp, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $ChangeTrackingEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $CloseCursorsOnCommitEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $ConcatenateNullYieldsNull, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $DatabaseOwnershipChaining, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $DataRetentionEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $DateCorrelationOptimization, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $EncryptionEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $HonorBrokerPriority, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $IsFullTextEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $IsParameterizationForced, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $IsReadCommittedSnapshotOn, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $IsSqlDw, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $IsVarDecimalStorageFormatEnabled, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $LegacyCardinalityEstimation, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $LegacyCardinalityEstimationForSecondary, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $LocalCursorsDefault, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $NestedTriggersEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $NumericRoundAbortEnabled, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $ParameterSniffing, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $ParameterSniffingForSecondary, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $QueryOptimizerHotfixes, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] + $QueryOptimizerHotfixesForSecondary, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $QuotedIdentifiersEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $ReadOnly, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $RecursiveTriggersEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $RemoteDataArchiveEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $RemoteDataArchiveUseFederatedServiceAccount, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $TemporalHistoryRetentionEnabled, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $TransformNoiseWords, + + [Parameter(ParameterSetName = 'Database')] + [System.Management.Automation.SwitchParameter] + $Trustworthy, + + # Integer Properties + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $ChangeTrackingRetentionPeriod, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $DefaultFullTextLanguage, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $DefaultLanguage, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $MaxDop, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $MaxDopForSecondary, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $MirroringRedoQueueMaxSize, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $MirroringTimeout, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $TargetRecoveryTime, + + [Parameter(ParameterSetName = 'Database')] + [System.Int32] + $TwoDigitYearCutoff, + + # Long Integer Properties + [Parameter(ParameterSetName = 'Database')] + [System.Double] + $MaxSizeInBytes, + + # String Properties + [Parameter(ParameterSetName = 'Database')] + [System.String] + $FilestreamDirectoryName, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $MirroringPartner, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $MirroringPartnerInstance, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $MirroringWitness, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $PersistentVersionStoreFileGroup, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $PrimaryFilePath, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $RemoteDataArchiveCredential, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $RemoteDataArchiveEndpoint, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $RemoteDataArchiveLinkedServer, + + [Parameter(ParameterSetName = 'Database')] + [System.String] + $RemoteDatabaseName, + + # Enum Properties + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.RetentionPeriodUnits] + $ChangeTrackingRetentionPeriodUnits, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.ContainmentType] + $ContainmentType, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DelayedDurability] + $DelayedDurability, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.FilestreamNonTransactedAccessType] + $FilestreamNonTransactedAccess, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.MirroringSafetyLevel] + $MirroringSafetyLevel, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.PageVerify] + $PageVerify, + + [Parameter(ParameterSetName = 'Database')] + [Microsoft.SqlServer.Management.Smo.DatabaseUserAccess] + $UserAccess, + [Parameter(Mandatory = $true, ParameterSetName = 'Snapshot')] [ValidateNotNullOrEmpty()] [System.String] @@ -344,7 +865,367 @@ function New-SqlDscDatabase if ($PSBoundParameters.ContainsKey('IsLedger')) { - $sqlDatabaseObjectToCreate.IsLedger = $IsLedger + $sqlDatabaseObjectToCreate.IsLedger = $IsLedger.IsPresent + } + + # Boolean Properties + if ($PSBoundParameters.ContainsKey('AcceleratedRecoveryEnabled')) + { + $sqlDatabaseObjectToCreate.AcceleratedRecoveryEnabled = $AcceleratedRecoveryEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AnsiNullDefault')) + { + $sqlDatabaseObjectToCreate.AnsiNullDefault = $AnsiNullDefault.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AnsiNullsEnabled')) + { + $sqlDatabaseObjectToCreate.AnsiNullsEnabled = $AnsiNullsEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AnsiPaddingEnabled')) + { + $sqlDatabaseObjectToCreate.AnsiPaddingEnabled = $AnsiPaddingEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AnsiWarningsEnabled')) + { + $sqlDatabaseObjectToCreate.AnsiWarningsEnabled = $AnsiWarningsEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ArithmeticAbortEnabled')) + { + $sqlDatabaseObjectToCreate.ArithmeticAbortEnabled = $ArithmeticAbortEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoClose')) + { + $sqlDatabaseObjectToCreate.AutoClose = $AutoClose.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoCreateIncrementalStatisticsEnabled')) + { + $sqlDatabaseObjectToCreate.AutoCreateIncrementalStatisticsEnabled = $AutoCreateIncrementalStatisticsEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoCreateStatisticsEnabled')) + { + $sqlDatabaseObjectToCreate.AutoCreateStatisticsEnabled = $AutoCreateStatisticsEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoShrink')) + { + $sqlDatabaseObjectToCreate.AutoShrink = $AutoShrink.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoUpdateStatisticsAsync')) + { + $sqlDatabaseObjectToCreate.AutoUpdateStatisticsAsync = $AutoUpdateStatisticsAsync.IsPresent + } + + if ($PSBoundParameters.ContainsKey('AutoUpdateStatisticsEnabled')) + { + $sqlDatabaseObjectToCreate.AutoUpdateStatisticsEnabled = $AutoUpdateStatisticsEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('BrokerEnabled')) + { + $sqlDatabaseObjectToCreate.BrokerEnabled = $BrokerEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ChangeTrackingAutoCleanUp')) + { + $sqlDatabaseObjectToCreate.ChangeTrackingAutoCleanUp = $ChangeTrackingAutoCleanUp.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ChangeTrackingEnabled')) + { + $sqlDatabaseObjectToCreate.ChangeTrackingEnabled = $ChangeTrackingEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('CloseCursorsOnCommitEnabled')) + { + $sqlDatabaseObjectToCreate.CloseCursorsOnCommitEnabled = $CloseCursorsOnCommitEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ConcatenateNullYieldsNull')) + { + $sqlDatabaseObjectToCreate.ConcatenateNullYieldsNull = $ConcatenateNullYieldsNull.IsPresent + } + + if ($PSBoundParameters.ContainsKey('DatabaseOwnershipChaining')) + { + $sqlDatabaseObjectToCreate.DatabaseOwnershipChaining = $DatabaseOwnershipChaining.IsPresent + } + + if ($PSBoundParameters.ContainsKey('DataRetentionEnabled')) + { + $sqlDatabaseObjectToCreate.DataRetentionEnabled = $DataRetentionEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('DateCorrelationOptimization')) + { + $sqlDatabaseObjectToCreate.DateCorrelationOptimization = $DateCorrelationOptimization.IsPresent + } + + if ($PSBoundParameters.ContainsKey('EncryptionEnabled')) + { + $sqlDatabaseObjectToCreate.EncryptionEnabled = $EncryptionEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('HonorBrokerPriority')) + { + $sqlDatabaseObjectToCreate.HonorBrokerPriority = $HonorBrokerPriority.IsPresent + } + + if ($PSBoundParameters.ContainsKey('IsFullTextEnabled')) + { + $sqlDatabaseObjectToCreate.IsFullTextEnabled = $IsFullTextEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('IsParameterizationForced')) + { + $sqlDatabaseObjectToCreate.IsParameterizationForced = $IsParameterizationForced.IsPresent + } + + if ($PSBoundParameters.ContainsKey('IsReadCommittedSnapshotOn')) + { + $sqlDatabaseObjectToCreate.IsReadCommittedSnapshotOn = $IsReadCommittedSnapshotOn.IsPresent + } + + if ($PSBoundParameters.ContainsKey('IsSqlDw')) + { + $sqlDatabaseObjectToCreate.IsSqlDw = $IsSqlDw.IsPresent + } + + if ($PSBoundParameters.ContainsKey('IsVarDecimalStorageFormatEnabled')) + { + $sqlDatabaseObjectToCreate.IsVarDecimalStorageFormatEnabled = $IsVarDecimalStorageFormatEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('LegacyCardinalityEstimation')) + { + $sqlDatabaseObjectToCreate.LegacyCardinalityEstimation = $LegacyCardinalityEstimation + } + + if ($PSBoundParameters.ContainsKey('LegacyCardinalityEstimationForSecondary')) + { + $sqlDatabaseObjectToCreate.LegacyCardinalityEstimationForSecondary = $LegacyCardinalityEstimationForSecondary + } + + if ($PSBoundParameters.ContainsKey('LocalCursorsDefault')) + { + $sqlDatabaseObjectToCreate.LocalCursorsDefault = $LocalCursorsDefault.IsPresent + } + + if ($PSBoundParameters.ContainsKey('NestedTriggersEnabled')) + { + $sqlDatabaseObjectToCreate.NestedTriggersEnabled = $NestedTriggersEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('NumericRoundAbortEnabled')) + { + $sqlDatabaseObjectToCreate.NumericRoundAbortEnabled = $NumericRoundAbortEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ParameterSniffing')) + { + $sqlDatabaseObjectToCreate.ParameterSniffing = $ParameterSniffing + } + + if ($PSBoundParameters.ContainsKey('ParameterSniffingForSecondary')) + { + $sqlDatabaseObjectToCreate.ParameterSniffingForSecondary = $ParameterSniffingForSecondary + } + + if ($PSBoundParameters.ContainsKey('QueryOptimizerHotfixes')) + { + $sqlDatabaseObjectToCreate.QueryOptimizerHotfixes = $QueryOptimizerHotfixes + } + + if ($PSBoundParameters.ContainsKey('QueryOptimizerHotfixesForSecondary')) + { + $sqlDatabaseObjectToCreate.QueryOptimizerHotfixesForSecondary = $QueryOptimizerHotfixesForSecondary + } + + if ($PSBoundParameters.ContainsKey('QuotedIdentifiersEnabled')) + { + $sqlDatabaseObjectToCreate.QuotedIdentifiersEnabled = $QuotedIdentifiersEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('ReadOnly')) + { + $sqlDatabaseObjectToCreate.ReadOnly = $ReadOnly.IsPresent + } + + if ($PSBoundParameters.ContainsKey('RecursiveTriggersEnabled')) + { + $sqlDatabaseObjectToCreate.RecursiveTriggersEnabled = $RecursiveTriggersEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('RemoteDataArchiveEnabled')) + { + $sqlDatabaseObjectToCreate.RemoteDataArchiveEnabled = $RemoteDataArchiveEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('RemoteDataArchiveUseFederatedServiceAccount')) + { + $sqlDatabaseObjectToCreate.RemoteDataArchiveUseFederatedServiceAccount = $RemoteDataArchiveUseFederatedServiceAccount.IsPresent + } + + if ($PSBoundParameters.ContainsKey('TemporalHistoryRetentionEnabled')) + { + $sqlDatabaseObjectToCreate.TemporalHistoryRetentionEnabled = $TemporalHistoryRetentionEnabled.IsPresent + } + + if ($PSBoundParameters.ContainsKey('TransformNoiseWords')) + { + $sqlDatabaseObjectToCreate.TransformNoiseWords = $TransformNoiseWords.IsPresent + } + + if ($PSBoundParameters.ContainsKey('Trustworthy')) + { + $sqlDatabaseObjectToCreate.Trustworthy = $Trustworthy.IsPresent + } + + # Integer Properties + if ($PSBoundParameters.ContainsKey('ChangeTrackingRetentionPeriod')) + { + $sqlDatabaseObjectToCreate.ChangeTrackingRetentionPeriod = $ChangeTrackingRetentionPeriod + } + + if ($PSBoundParameters.ContainsKey('DefaultFullTextLanguage')) + { + $sqlDatabaseObjectToCreate.DefaultFullTextLanguage = $DefaultFullTextLanguage + } + + if ($PSBoundParameters.ContainsKey('DefaultLanguage')) + { + $sqlDatabaseObjectToCreate.DefaultLanguage = $DefaultLanguage + } + + if ($PSBoundParameters.ContainsKey('MaxDop')) + { + $sqlDatabaseObjectToCreate.MaxDop = $MaxDop + } + + if ($PSBoundParameters.ContainsKey('MaxDopForSecondary')) + { + $sqlDatabaseObjectToCreate.MaxDopForSecondary = $MaxDopForSecondary + } + + if ($PSBoundParameters.ContainsKey('MirroringRedoQueueMaxSize')) + { + $sqlDatabaseObjectToCreate.MirroringRedoQueueMaxSize = $MirroringRedoQueueMaxSize + } + + if ($PSBoundParameters.ContainsKey('MirroringTimeout')) + { + $sqlDatabaseObjectToCreate.MirroringTimeout = $MirroringTimeout + } + + if ($PSBoundParameters.ContainsKey('TargetRecoveryTime')) + { + $sqlDatabaseObjectToCreate.TargetRecoveryTime = $TargetRecoveryTime + } + + if ($PSBoundParameters.ContainsKey('TwoDigitYearCutoff')) + { + $sqlDatabaseObjectToCreate.TwoDigitYearCutoff = $TwoDigitYearCutoff + } + + # Long Integer Properties + if ($PSBoundParameters.ContainsKey('MaxSizeInBytes')) + { + $sqlDatabaseObjectToCreate.MaxSizeInBytes = $MaxSizeInBytes + } + + # String Properties + if ($PSBoundParameters.ContainsKey('FilestreamDirectoryName')) + { + $sqlDatabaseObjectToCreate.FilestreamDirectoryName = $FilestreamDirectoryName + } + + if ($PSBoundParameters.ContainsKey('MirroringPartner')) + { + $sqlDatabaseObjectToCreate.MirroringPartner = $MirroringPartner + } + + if ($PSBoundParameters.ContainsKey('MirroringPartnerInstance')) + { + $sqlDatabaseObjectToCreate.MirroringPartnerInstance = $MirroringPartnerInstance + } + + if ($PSBoundParameters.ContainsKey('MirroringWitness')) + { + $sqlDatabaseObjectToCreate.MirroringWitness = $MirroringWitness + } + + if ($PSBoundParameters.ContainsKey('PersistentVersionStoreFileGroup')) + { + $sqlDatabaseObjectToCreate.PersistentVersionStoreFileGroup = $PersistentVersionStoreFileGroup + } + + if ($PSBoundParameters.ContainsKey('PrimaryFilePath')) + { + $sqlDatabaseObjectToCreate.PrimaryFilePath = $PrimaryFilePath + } + + if ($PSBoundParameters.ContainsKey('RemoteDataArchiveCredential')) + { + $sqlDatabaseObjectToCreate.RemoteDataArchiveCredential = $RemoteDataArchiveCredential + } + + if ($PSBoundParameters.ContainsKey('RemoteDataArchiveEndpoint')) + { + $sqlDatabaseObjectToCreate.RemoteDataArchiveEndpoint = $RemoteDataArchiveEndpoint + } + + if ($PSBoundParameters.ContainsKey('RemoteDataArchiveLinkedServer')) + { + $sqlDatabaseObjectToCreate.RemoteDataArchiveLinkedServer = $RemoteDataArchiveLinkedServer + } + + if ($PSBoundParameters.ContainsKey('RemoteDatabaseName')) + { + $sqlDatabaseObjectToCreate.RemoteDatabaseName = $RemoteDatabaseName + } + + # Enum Properties + if ($PSBoundParameters.ContainsKey('ChangeTrackingRetentionPeriodUnits')) + { + $sqlDatabaseObjectToCreate.ChangeTrackingRetentionPeriodUnits = $ChangeTrackingRetentionPeriodUnits + } + + if ($PSBoundParameters.ContainsKey('ContainmentType')) + { + $sqlDatabaseObjectToCreate.ContainmentType = $ContainmentType + } + + if ($PSBoundParameters.ContainsKey('DelayedDurability')) + { + $sqlDatabaseObjectToCreate.DelayedDurability = $DelayedDurability + } + + if ($PSBoundParameters.ContainsKey('FilestreamNonTransactedAccess')) + { + $sqlDatabaseObjectToCreate.FilestreamNonTransactedAccess = $FilestreamNonTransactedAccess + } + + if ($PSBoundParameters.ContainsKey('MirroringSafetyLevel')) + { + $sqlDatabaseObjectToCreate.MirroringSafetyLevel = $MirroringSafetyLevel + } + + if ($PSBoundParameters.ContainsKey('PageVerify')) + { + $sqlDatabaseObjectToCreate.PageVerify = $PageVerify + } + + if ($PSBoundParameters.ContainsKey('UserAccess')) + { + $sqlDatabaseObjectToCreate.UserAccess = $UserAccess } } diff --git a/source/Public/Set-SqlDscDatabaseProperty.ps1 b/source/Public/Set-SqlDscDatabaseProperty.ps1 index 5209843cd3..133d5fc6ed 100644 --- a/source/Public/Set-SqlDscDatabaseProperty.ps1 +++ b/source/Public/Set-SqlDscDatabaseProperty.ps1 @@ -43,6 +43,7 @@ .PARAMETER AcceleratedRecoveryEnabled Specifies whether Accelerated Database Recovery (ADR) is enabled for the database. + This parameter requires SQL Server 2019 (version 15) or later. .PARAMETER AnsiNullDefault Specifies whether new columns allow NULL by default unless explicitly specified (when ON). @@ -106,6 +107,7 @@ .PARAMETER DataRetentionEnabled Specifies whether SQL Server data retention policy is enabled at the database level. + This parameter requires SQL Server 2017 (version 14) or later. .PARAMETER DateCorrelationOptimization Specifies whether date correlation optimization is enabled to speed up temporal joins. @@ -148,10 +150,12 @@ Specifies whether vardecimal compression is enabled. .PARAMETER LegacyCardinalityEstimation - Specifies whether the legacy cardinality estimator is enabled for the primary. + Specifies the legacy cardinality estimator setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). .PARAMETER LegacyCardinalityEstimationForSecondary - Specifies whether the legacy cardinality estimator is enabled for secondary replicas. + Specifies the legacy cardinality estimator setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). .PARAMETER LocalCursorsDefault Specifies whether cursors are local by default instead of global (when ON). @@ -193,22 +197,27 @@ Specifies the page verification setting (NONE, TORN_PAGE_DETECTION, CHECKSUM). .PARAMETER ParameterSniffing - Specifies whether parameter sniffing behavior is enabled on the primary. + Specifies the parameter sniffing setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). .PARAMETER ParameterSniffingForSecondary - Specifies whether parameter sniffing is enabled on secondary replicas. + Specifies the parameter sniffing setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). .PARAMETER PersistentVersionStoreFileGroup Specifies the filegroup used for the Persistent Version Store (PVS). + This parameter requires SQL Server 2019 (version 15) or later. .PARAMETER PrimaryFilePath Specifies the path of the primary data files directory. .PARAMETER QueryOptimizerHotfixes - Specifies whether query optimizer hotfixes are enabled on the primary. + Specifies the query optimizer hotfixes setting for the primary. + Valid values are Off, On, or Primary (for secondary replicas to use primary's setting). .PARAMETER QueryOptimizerHotfixesForSecondary - Specifies whether query optimizer hotfixes are enabled on secondary replicas. + Specifies the query optimizer hotfixes setting for secondary replicas. + Valid values are Off, On, or Primary (to use primary's setting). .PARAMETER QuotedIdentifiersEnabled Specifies whether identifiers can be delimited by double quotes (when ON). @@ -242,6 +251,7 @@ .PARAMETER TemporalHistoryRetentionEnabled Specifies whether automatic cleanup of system-versioned temporal history is enabled. + This parameter requires SQL Server 2017 (version 14) or later. .PARAMETER TransformNoiseWords Specifies how full-text noise word behavior is controlled during queries. @@ -253,7 +263,7 @@ Specifies the two-digit year cutoff used for date conversion. .PARAMETER UserAccess - Specifies the database user access mode (MULTI_USER, RESTRICTED_USER, SINGLE_USER). + Specifies the database user access mode. Valid values are Multiple, Restricted, and Single. .PARAMETER Force Specifies that the database should be modified without any confirmation. @@ -270,13 +280,13 @@ .EXAMPLE $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' $databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase' - Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -ReadOnly $false -AutoClose $false + Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -ReadOnly:$false -AutoClose:$false Sets multiple database properties at once using a database object. .EXAMPLE $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' - Set-SqlDscDatabaseProperty -ServerObject $serverObject -Name 'MyDatabase' -CompatibilityLevel 'Version160' -Trustworthy $false -Force + Set-SqlDscDatabaseProperty -ServerObject $serverObject -Name 'MyDatabase' -CompatibilityLevel 'Version160' -Trustworthy:$false -Force Sets the compatibility level and trustworthy property of the database without prompting for confirmation. @@ -350,179 +360,179 @@ function Set-SqlDscDatabaseProperty # Boolean Properties [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AcceleratedRecoveryEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiNullDefault, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiNullsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiPaddingEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiWarningsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ArithmeticAbortEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoClose, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoCreateIncrementalStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoCreateStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoShrink, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoUpdateStatisticsAsync, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoUpdateStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $BrokerEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ChangeTrackingAutoCleanUp, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ChangeTrackingEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $CloseCursorsOnCommitEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ConcatenateNullYieldsNull, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DatabaseOwnershipChaining, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DataRetentionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DateCorrelationOptimization, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $EncryptionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $HonorBrokerPriority, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsFullTextEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsParameterizationForced, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsReadCommittedSnapshotOn, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsSqlDw, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsVarDecimalStorageFormatEnabled, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $LegacyCardinalityEstimation, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $LegacyCardinalityEstimationForSecondary, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $LocalCursorsDefault, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $NestedTriggersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $NumericRoundAbortEnabled, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $ParameterSniffing, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $ParameterSniffingForSecondary, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $QueryOptimizerHotfixes, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $QueryOptimizerHotfixesForSecondary, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $QuotedIdentifiersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ReadOnly, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RecursiveTriggersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RemoteDataArchiveEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RemoteDataArchiveUseFederatedServiceAccount, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $TemporalHistoryRetentionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $TransformNoiseWords, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $Trustworthy, # Integer Properties @@ -772,6 +782,12 @@ function Set-SqlDscDatabaseProperty $currentValue = $sqlDatabaseObject.$parameterName $newValue = $boundParameters.$parameterName + # Convert SwitchParameter to Boolean for SMO properties + if ($newValue -is [System.Management.Automation.SwitchParameter]) + { + $newValue = $newValue.IsPresent + } + # Only update if the value is different if ($currentValue -ne $newValue) { diff --git a/source/Public/Test-SqlDscDatabaseProperty.ps1 b/source/Public/Test-SqlDscDatabaseProperty.ps1 index ad8f157f45..e344c2b2ff 100644 --- a/source/Public/Test-SqlDscDatabaseProperty.ps1 +++ b/source/Public/Test-SqlDscDatabaseProperty.ps1 @@ -460,7 +460,7 @@ Specifies the two-digit year cutoff used for date conversion. .PARAMETER UserAccess - Specifies the database user access mode (MULTI_USER, RESTRICTED_USER, SINGLE_USER). + Specifies the database user access mode (Multiple, Restricted, Single). .PARAMETER UserName Specifies the user name for the current connection context (as seen by SMO). @@ -486,9 +486,9 @@ .EXAMPLE $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance' - Test-SqlDscDatabaseProperty -ServerObject $serverObject -Name 'MyDatabase' -Owner 'sa' -AutoClose $false -Trustworthy $false + Test-SqlDscDatabaseProperty -ServerObject $serverObject -Name 'MyDatabase' -Owner 'sa' -AutoClose:$false -Trustworthy:$false - Tests multiple database properties at once. + Tests multiple database properties at once. Switch parameters can be explicitly set to $false using the colon syntax. .INPUTS `[Microsoft.SqlServer.Management.Smo.Database]` @@ -525,299 +525,299 @@ function Test-SqlDscDatabaseProperty # Boolean Properties [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AcceleratedRecoveryEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ActiveDirectory, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiNullDefault, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiNullsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiPaddingEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AnsiWarningsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ArithmeticAbortEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoClose, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoCreateIncrementalStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoCreateStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoShrink, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoUpdateStatisticsAsync, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $AutoUpdateStatisticsEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $BrokerEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $CaseSensitive, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ChangeTrackingAutoCleanUp, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ChangeTrackingEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $CloseCursorsOnCommitEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ConcatenateNullYieldsNull, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DatabaseOwnershipChaining, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DataRetentionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $DateCorrelationOptimization, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DelayedDurability] $DelayedDurability, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $EncryptionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $HasDatabaseEncryptionKey, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $HasFileInCloud, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $HasMemoryOptimizedObjects, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $HonorBrokerPriority, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsAccessible, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDatabaseSnapshot, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDatabaseSnapshotBase, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbAccessAdmin, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbBackupOperator, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbDataReader, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbDataWriter, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbDdlAdmin, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbDenyDataReader, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbDenyDataWriter, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbManager, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbOwner, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsDbSecurityAdmin, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsFabricDatabase, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsFullTextEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsLedger, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsLoginManager, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsMailHost, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsManagementDataWarehouse, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsMaxSizeApplicable, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsMirroringEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsParameterizationForced, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsReadCommittedSnapshotOn, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsSqlDw, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsSqlDwEdition, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsSystemObject, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsVarDecimalStorageFormatEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $IsVarDecimalStorageFormatSupported, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $LegacyCardinalityEstimation, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $LegacyCardinalityEstimationForSecondary, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $LocalCursorsDefault, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $NestedTriggersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $NumericRoundAbortEnabled, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $ParameterSniffing, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $ParameterSniffingForSecondary, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $QueryOptimizerHotfixes, [Parameter()] - [System.Boolean] + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff] $QueryOptimizerHotfixesForSecondary, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $QuotedIdentifiersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $ReadOnly, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RecursiveTriggersEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RemoteDataArchiveEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $RemoteDataArchiveUseFederatedServiceAccount, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $TemporalHistoryRetentionEnabled, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $TransformNoiseWords, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $Trustworthy, [Parameter()] - [System.Boolean] + [System.Management.Automation.SwitchParameter] $WarnOnRename, # Integer Properties @@ -1158,6 +1158,12 @@ function Test-SqlDscDatabaseProperty $expectedValue = $boundParameters.$parameterName $actualValue = $sqlDatabaseObject.$parameterName + # Convert SwitchParameter to Boolean for comparison with SMO properties + if ($expectedValue -is [System.Management.Automation.SwitchParameter]) + { + $expectedValue = $expectedValue.IsPresent + } + # Use a robust comparison that handles empty strings, nulls, and different types $valuesMatch = $false diff --git a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 index 91f1791aca..806fcac347 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -89,6 +89,118 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 $createdDb.RecoveryModel | Should -Be 'Simple' } + It 'Should create a database and verify default boolean properties' { + $testDbWithBoolProps = 'SqlDscTestDbBoolProps_' + (Get-Random) + + try + { + # Create database without specifying boolean properties - they should use defaults + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithBoolProps -Force -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $testDbWithBoolProps + # AutoClose and AutoShrink should be false by default + $result.AutoClose | Should -BeFalse + $result.AutoShrink | Should -BeFalse + $result.ReadOnly | Should -BeFalse + + # Verify the database exists with correct properties + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithBoolProps -ErrorAction 'Stop' + $createdDb.AutoClose | Should -BeFalse + $createdDb.AutoShrink | Should -BeFalse + $createdDb.ReadOnly | Should -BeFalse + } + finally + { + $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithBoolProps -ErrorAction 'SilentlyContinue' + if ($dbToRemove) + { + $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force + } + } + } + + It 'Should create a database with integer properties set during creation' { + $testDbWithIntProps = 'SqlDscTestDbIntProps_' + (Get-Random) + + try + { + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithIntProps -TargetRecoveryTime 60 -Force -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $testDbWithIntProps + $result.TargetRecoveryTime | Should -Be 60 + + # Verify the database exists with correct properties + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithIntProps -ErrorAction 'Stop' + $createdDb.TargetRecoveryTime | Should -Be 60 + } + finally + { + $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithIntProps -ErrorAction 'SilentlyContinue' + if ($dbToRemove) + { + $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force + } + } + } + + It 'Should create a database with enum properties set during creation' { + $testDbWithEnumProps = 'SqlDscTestDbEnumProps_' + (Get-Random) + + try + { + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithEnumProps -PageVerify 'Checksum' -UserAccess 'Multiple' -Force -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $testDbWithEnumProps + $result.PageVerify | Should -Be 'Checksum' + $result.UserAccess | Should -Be 'Multiple' + + # Verify the database exists with correct properties + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithEnumProps -ErrorAction 'Stop' + $createdDb.PageVerify | Should -Be 'Checksum' + $createdDb.UserAccess | Should -Be 'Multiple' + } + finally + { + $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithEnumProps -ErrorAction 'SilentlyContinue' + if ($dbToRemove) + { + $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force + } + } + } + + It 'Should create a database with multiple property types set during creation' { + $testDbWithMixedProps = 'SqlDscTestDbMixedProps_' + (Get-Random) + + try + { + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithMixedProps -RecoveryModel 'Simple' -TargetRecoveryTime 30 -PageVerify 'TornPageDetection' -Force -ErrorAction 'Stop' + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $testDbWithMixedProps + $result.RecoveryModel | Should -Be 'Simple' + $result.TargetRecoveryTime | Should -Be 30 + $result.PageVerify | Should -Be 'TornPageDetection' + + # Verify the database exists with correct properties + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithMixedProps -ErrorAction 'Stop' + $createdDb.RecoveryModel | Should -Be 'Simple' + $createdDb.TargetRecoveryTime | Should -Be 30 + $createdDb.PageVerify | Should -Be 'TornPageDetection' + } + finally + { + $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $testDbWithMixedProps -ErrorAction 'SilentlyContinue' + if ($dbToRemove) + { + $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force + } + } + } + It 'Should throw error when trying to create a database that already exists' { { New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' } | Should -Throw diff --git a/tests/Integration/Commands/Set-SqlDscDatabaseProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabaseProperty.Integration.Tests.ps1 index c732cae9c7..5af4360293 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabaseProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabaseProperty.Integration.Tests.ps1 @@ -86,25 +86,25 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag @('Integration_SQL2017', 'Integration } It 'Should set AutoClose successfully' { - $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoClose $true -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoClose -Force -ErrorAction 'Stop' # Verify the change $updatedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'Stop' $updatedDb.AutoClose | Should -BeTrue # Reset to default - $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoClose $false -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoClose:$false -Force -ErrorAction 'Stop' } It 'Should set AutoShrink successfully' { - $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoShrink $true -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoShrink -Force -ErrorAction 'Stop' # Verify the change $updatedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'Stop' $updatedDb.AutoShrink | Should -BeTrue # Reset to default - $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoShrink $false -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -AutoShrink:$false -Force -ErrorAction 'Stop' } It 'Should set PageVerify successfully' { @@ -119,7 +119,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag @('Integration_SQL2017', 'Integration } It 'Should set multiple properties successfully' { - $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -RecoveryModel 'Full' -AutoClose $false -AutoShrink $false -PageVerify 'Checksum' -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -ServerObject $script:serverObject -Name $script:testDatabaseName -RecoveryModel 'Full' -AutoClose:$false -AutoShrink:$false -PageVerify 'Checksum' -Force -ErrorAction 'Stop' # Verify the changes $updatedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'Stop' @@ -161,14 +161,14 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag @('Integration_SQL2017', 'Integration It 'Should set AutoClose using database object' { $databaseObject = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'Stop' - $null = Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -AutoClose $true -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -AutoClose -Force -ErrorAction 'Stop' # Verify the change $updatedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'Stop' $updatedDb.AutoClose | Should -BeTrue # Reset to default - $null = Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -AutoClose $false -Force -ErrorAction 'Stop' + $null = Set-SqlDscDatabaseProperty -DatabaseObject $databaseObject -AutoClose:$false -Force -ErrorAction 'Stop' } It 'Should set multiple properties using database object' { diff --git a/tests/Integration/Commands/Test-SqlDscDatabaseProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscDatabaseProperty.Integration.Tests.ps1 index 472da8e3ec..e7232ef0d7 100644 --- a/tests/Integration/Commands/Test-SqlDscDatabaseProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscDatabaseProperty.Integration.Tests.ps1 @@ -87,9 +87,10 @@ BeforeDiscovery { @{ PropertyName = 'AutoUpdateStatisticsEnabled'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @{ PropertyName = 'AutoUpdateStatisticsAsync'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @{ PropertyName = 'AutoCreateIncrementalStatisticsEnabled'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } - @{ PropertyName = 'ParameterSniffing'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } - @{ PropertyName = 'LegacyCardinalityEstimation'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } - @{ PropertyName = 'QueryOptimizerHotfixes'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } + # Database-scoped configuration properties (enum-based, tested via non-Boolean path) + @{ PropertyName = 'ParameterSniffing'; DatabaseName = $script:persistentTestDatabase } + @{ PropertyName = 'LegacyCardinalityEstimation'; DatabaseName = $script:persistentTestDatabase } + @{ PropertyName = 'QueryOptimizerHotfixes'; DatabaseName = $script:persistentTestDatabase } @{ PropertyName = 'AnsiNullDefault'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @{ PropertyName = 'ChangeTrackingEnabled'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @{ PropertyName = 'ChangeTrackingAutoCleanUp'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @@ -98,7 +99,8 @@ BeforeDiscovery { @{ PropertyName = 'TemporalHistoryRetentionEnabled'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } # TODO: AcceleratedRecoveryEnabled - Commented out because this property requires specific database configuration or SQL Server edition that is not available in the persistent test database # @{ PropertyName = 'AcceleratedRecoveryEnabled'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } - @{ PropertyName = 'DelayedDurability'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } + # Database-scoped configuration properties (enum-based, tested via non-Boolean path) + @{ PropertyName = 'DelayedDurability'; DatabaseName = $script:persistentTestDatabase } @{ PropertyName = 'HonorBrokerPriority'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } @{ PropertyName = 'TransformNoiseWords'; DatabaseName = $script:persistentTestDatabase; TestValue = $true } diff --git a/tests/Unit/Public/New-SqlDscDatabase.Tests.ps1 b/tests/Unit/Public/New-SqlDscDatabase.Tests.ps1 index d107b2003d..5ecc8ca2f9 100644 --- a/tests/Unit/Public/New-SqlDscDatabase.Tests.ps1 +++ b/tests/Unit/Public/New-SqlDscDatabase.Tests.ps1 @@ -74,6 +74,14 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' { $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'Collation' -Value $null -Force $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'CompatibilityLevel' -Value $null -Force $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'IsLedger' -Value $false -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'AutoClose' -Value $false -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'AutoShrink' -Value $false -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'PageVerify' -Value $null -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'ReadOnly' -Value $false -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'MaxDop' -Value $null -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'TargetRecoveryTime' -Value $null -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'ContainmentType' -Value $null -Force + $mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'DelayedDurability' -Value $null -Force $mockDatabaseObject | Add-Member -MemberType 'ScriptMethod' -Name 'Create' -Value { # Mock implementation } -Force @@ -114,13 +122,41 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' { } -PassThru -Force } -Force - $result = New-SqlDscDatabase -ServerObject $mockServerObject2022 -Name 'LedgerDatabase' -IsLedger $true -Force + $result = New-SqlDscDatabase -ServerObject $mockServerObject2022 -Name 'LedgerDatabase' -IsLedger -Force $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be 'LedgerDatabase' $result.IsLedger | Should -BeTrue } + It 'Should create a database with additional boolean properties set' { + $result = New-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabaseWithProps' -AutoClose -AutoShrink -Force + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be 'TestDatabaseWithProps' + $result.AutoClose | Should -BeTrue + $result.AutoShrink | Should -BeTrue + } + + It 'Should create a database with integer properties set' { + $result = New-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabaseWithIntProps' -MaxDop 4 -TargetRecoveryTime 60 -Force + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be 'TestDatabaseWithIntProps' + $result.MaxDop | Should -Be 4 + $result.TargetRecoveryTime | Should -Be 60 + } + + It 'Should create a database with enum properties set' { + $result = New-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabaseWithEnumProps' -ContainmentType 'Partial' -PageVerify 'Checksum' -DelayedDurability 'Allowed' -Force + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be 'TestDatabaseWithEnumProps' + $result.ContainmentType | Should -Be 'Partial' + $result.PageVerify | Should -Be 'Checksum' + $result.DelayedDurability | Should -Be 'Allowed' + } + It 'Should throw error when database already exists' { $mockServerObjectWithExistingDb = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' $mockServerObjectWithExistingDb | Add-Member -MemberType 'NoteProperty' -Name 'InstanceName' -Value 'TestInstance' -Force @@ -172,13 +208,12 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' { } It 'Should throw error when IsLedger is used on SQL Server version older than 2022' { - $errorRecord = { New-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDB' -IsLedger $true -Force } | + $errorRecord = { New-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDB' -IsLedger -Force } | Should -Throw -ExpectedMessage '*IsLedger is not supported*' -PassThru $errorRecord.Exception.Message | Should -BeLike '*IsLedger is not supported*' $errorRecord.FullyQualifiedErrorId | Should -Be 'NSD0007,New-SqlDscDatabase' $errorRecord.CategoryInfo.Category | Should -Be 'InvalidOperation' - $errorRecord.CategoryInfo.TargetName | Should -Be 'True' } } @@ -186,18 +221,47 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' { It 'Should have the correct parameters in parameter set Database' -ForEach @( @{ ExpectedParameterSetName = 'Database' - ExpectedParameters = '-ServerObject -Name [-Collation ] [-CatalogCollation ] [-CompatibilityLevel ] [-RecoveryModel ] [-OwnerName ] [-IsLedger ] [-FileGroup ] [-Force] [-Refresh] [-WhatIf] [-Confirm] []' + ExpectedCoreParameters = @('ServerObject', 'Name', 'Collation', 'CatalogCollation', 'CompatibilityLevel', 'RecoveryModel', 'OwnerName', 'IsLedger', 'FileGroup', 'Force', 'Refresh') } ) { - $result = (Get-Command -Name 'New-SqlDscDatabase').ParameterSets | - Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } | - Select-Object -Property @( - @{ Name = 'ParameterSetName'; Expression = { $_.Name } }, - @{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } } - ) + $parameterSet = (Get-Command -Name 'New-SqlDscDatabase').ParameterSets | + Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } - $result.ParameterSetName | Should -Be $ExpectedParameterSetName - $result.ParameterListAsString | Should -Be $ExpectedParameters + $parameterSet | Should -Not -BeNullOrEmpty + $parameterSet.Name | Should -Be $ExpectedParameterSetName + + # Verify core parameters are present + foreach ($paramName in $ExpectedCoreParameters) + { + $parameterSet.Parameters.Name | Should -Contain $paramName -Because "Parameter '$paramName' should be in the $ExpectedParameterSetName parameter set" + } + } + + It 'Should have additional database property parameters in Database parameter set' -ForEach @( + @{ + PropertyType = 'SwitchParameter' + SampleParameters = @('AutoClose', 'AutoShrink', 'ReadOnly', 'Trustworthy', 'EncryptionEnabled') + } + @{ + PropertyType = 'Integer' + SampleParameters = @('MaxDop', 'TargetRecoveryTime', 'DefaultLanguage') + } + @{ + PropertyType = 'String' + SampleParameters = @('PrimaryFilePath', 'FilestreamDirectoryName') + } + @{ + PropertyType = 'Enum' + SampleParameters = @('ContainmentType', 'DelayedDurability', 'PageVerify', 'UserAccess') + } + ) { + $databaseParameterSet = (Get-Command -Name 'New-SqlDscDatabase').ParameterSets | + Where-Object -FilterScript { $_.Name -eq 'Database' } + + foreach ($paramName in $SampleParameters) + { + $databaseParameterSet.Parameters.Name | Should -Contain $paramName -Because "$PropertyType parameter '$paramName' should be available in the Database parameter set" + } } It 'Should have the correct parameters in parameter set Snapshot' -ForEach @( diff --git a/tests/Unit/Public/Set-SqlDscDatabaseProperty.Tests.ps1 b/tests/Unit/Public/Set-SqlDscDatabaseProperty.Tests.ps1 index f0517c9843..6beae22344 100644 --- a/tests/Unit/Public/Set-SqlDscDatabaseProperty.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscDatabaseProperty.Tests.ps1 @@ -112,7 +112,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' { $mockDatabaseObject.AutoShrink = $false # Reset to initial value $mockDatabaseObject.PageVerify = 'Checksum' # Reset to initial value - $null = Set-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose $true -AutoShrink $true -PageVerify 'None' -Force + $null = Set-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose -AutoShrink -PageVerify 'None' -Force $mockDatabaseObject.AutoClose | Should -BeTrue $mockDatabaseObject.AutoShrink | Should -BeTrue @@ -329,7 +329,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should not call Alter() when all properties are already set' { $script:mockAlterCalled = $false - $null = Set-SqlDscDatabaseProperty -DatabaseObject $mockDatabaseObject -RecoveryModel 'Simple' -AutoClose $true -Force + $null = Set-SqlDscDatabaseProperty -DatabaseObject $mockDatabaseObject -RecoveryModel 'Simple' -AutoClose -Force $script:mockAlterCalled | Should -BeFalse -Because 'Alter() should not be called when all properties are already set' } @@ -366,7 +366,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should have the correct parameters in parameter set ServerObjectSet' -ForEach @( @{ ExpectedParameterSetName = 'ServerObjectSet' - ExpectedParameters = '-ServerObject -Name [-Refresh] [-AcceleratedRecoveryEnabled ] [-AnsiNullDefault ] [-AnsiNullsEnabled ] [-AnsiPaddingEnabled ] [-AnsiWarningsEnabled ] [-ArithmeticAbortEnabled ] [-AutoClose ] [-AutoCreateIncrementalStatisticsEnabled ] [-AutoCreateStatisticsEnabled ] [-AutoShrink ] [-AutoUpdateStatisticsAsync ] [-AutoUpdateStatisticsEnabled ] [-BrokerEnabled ] [-ChangeTrackingAutoCleanUp ] [-ChangeTrackingEnabled ] [-CloseCursorsOnCommitEnabled ] [-ConcatenateNullYieldsNull ] [-DatabaseOwnershipChaining ] [-DataRetentionEnabled ] [-DateCorrelationOptimization ] [-EncryptionEnabled ] [-HonorBrokerPriority ] [-IsFullTextEnabled ] [-IsParameterizationForced ] [-IsReadCommittedSnapshotOn ] [-IsSqlDw ] [-IsVarDecimalStorageFormatEnabled ] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault ] [-NestedTriggersEnabled ] [-NumericRoundAbortEnabled ] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled ] [-ReadOnly ] [-RecursiveTriggersEnabled ] [-RemoteDataArchiveEnabled ] [-RemoteDataArchiveUseFederatedServiceAccount ] [-TemporalHistoryRetentionEnabled ] [-TransformNoiseWords ] [-Trustworthy ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-MaxSizeInBytes ] [-Collation ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DelayedDurability ] [-FilestreamNonTransactedAccess ] [-MirroringSafetyLevel ] [-PageVerify ] [-RecoveryModel ] [-UserAccess ] [-Force] [-PassThru] [-WhatIf] [-Confirm] []' + ExpectedParameters = '-ServerObject -Name [-Refresh] [-AcceleratedRecoveryEnabled] [-AnsiNullDefault] [-AnsiNullsEnabled] [-AnsiPaddingEnabled] [-AnsiWarningsEnabled] [-ArithmeticAbortEnabled] [-AutoClose] [-AutoCreateIncrementalStatisticsEnabled] [-AutoCreateStatisticsEnabled] [-AutoShrink] [-AutoUpdateStatisticsAsync] [-AutoUpdateStatisticsEnabled] [-BrokerEnabled] [-ChangeTrackingAutoCleanUp] [-ChangeTrackingEnabled] [-CloseCursorsOnCommitEnabled] [-ConcatenateNullYieldsNull] [-DatabaseOwnershipChaining] [-DataRetentionEnabled] [-DateCorrelationOptimization] [-EncryptionEnabled] [-HonorBrokerPriority] [-IsFullTextEnabled] [-IsParameterizationForced] [-IsReadCommittedSnapshotOn] [-IsSqlDw] [-IsVarDecimalStorageFormatEnabled] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault] [-NestedTriggersEnabled] [-NumericRoundAbortEnabled] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled] [-ReadOnly] [-RecursiveTriggersEnabled] [-RemoteDataArchiveEnabled] [-RemoteDataArchiveUseFederatedServiceAccount] [-TemporalHistoryRetentionEnabled] [-TransformNoiseWords] [-Trustworthy] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-MaxSizeInBytes ] [-Collation ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DelayedDurability ] [-FilestreamNonTransactedAccess ] [-MirroringSafetyLevel ] [-PageVerify ] [-RecoveryModel ] [-UserAccess ] [-Force] [-PassThru] [-WhatIf] [-Confirm] []' } ) { $result = (Get-Command -Name 'Set-SqlDscDatabaseProperty').ParameterSets | @@ -383,7 +383,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should have the correct parameters in parameter set DatabaseObjectSet' -ForEach @( @{ ExpectedParameterSetName = 'DatabaseObjectSet' - ExpectedParameters = '-DatabaseObject [-AcceleratedRecoveryEnabled ] [-AnsiNullDefault ] [-AnsiNullsEnabled ] [-AnsiPaddingEnabled ] [-AnsiWarningsEnabled ] [-ArithmeticAbortEnabled ] [-AutoClose ] [-AutoCreateIncrementalStatisticsEnabled ] [-AutoCreateStatisticsEnabled ] [-AutoShrink ] [-AutoUpdateStatisticsAsync ] [-AutoUpdateStatisticsEnabled ] [-BrokerEnabled ] [-ChangeTrackingAutoCleanUp ] [-ChangeTrackingEnabled ] [-CloseCursorsOnCommitEnabled ] [-ConcatenateNullYieldsNull ] [-DatabaseOwnershipChaining ] [-DataRetentionEnabled ] [-DateCorrelationOptimization ] [-EncryptionEnabled ] [-HonorBrokerPriority ] [-IsFullTextEnabled ] [-IsParameterizationForced ] [-IsReadCommittedSnapshotOn ] [-IsSqlDw ] [-IsVarDecimalStorageFormatEnabled ] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault ] [-NestedTriggersEnabled ] [-NumericRoundAbortEnabled ] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled ] [-ReadOnly ] [-RecursiveTriggersEnabled ] [-RemoteDataArchiveEnabled ] [-RemoteDataArchiveUseFederatedServiceAccount ] [-TemporalHistoryRetentionEnabled ] [-TransformNoiseWords ] [-Trustworthy ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-MaxSizeInBytes ] [-Collation ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DelayedDurability ] [-FilestreamNonTransactedAccess ] [-MirroringSafetyLevel ] [-PageVerify ] [-RecoveryModel ] [-UserAccess ] [-Force] [-PassThru] [-WhatIf] [-Confirm] []' + ExpectedParameters = '-DatabaseObject [-AcceleratedRecoveryEnabled] [-AnsiNullDefault] [-AnsiNullsEnabled] [-AnsiPaddingEnabled] [-AnsiWarningsEnabled] [-ArithmeticAbortEnabled] [-AutoClose] [-AutoCreateIncrementalStatisticsEnabled] [-AutoCreateStatisticsEnabled] [-AutoShrink] [-AutoUpdateStatisticsAsync] [-AutoUpdateStatisticsEnabled] [-BrokerEnabled] [-ChangeTrackingAutoCleanUp] [-ChangeTrackingEnabled] [-CloseCursorsOnCommitEnabled] [-ConcatenateNullYieldsNull] [-DatabaseOwnershipChaining] [-DataRetentionEnabled] [-DateCorrelationOptimization] [-EncryptionEnabled] [-HonorBrokerPriority] [-IsFullTextEnabled] [-IsParameterizationForced] [-IsReadCommittedSnapshotOn] [-IsSqlDw] [-IsVarDecimalStorageFormatEnabled] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault] [-NestedTriggersEnabled] [-NumericRoundAbortEnabled] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled] [-ReadOnly] [-RecursiveTriggersEnabled] [-RemoteDataArchiveEnabled] [-RemoteDataArchiveUseFederatedServiceAccount] [-TemporalHistoryRetentionEnabled] [-TransformNoiseWords] [-Trustworthy] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-MaxSizeInBytes ] [-Collation ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DelayedDurability ] [-FilestreamNonTransactedAccess ] [-MirroringSafetyLevel ] [-PageVerify ] [-RecoveryModel ] [-UserAccess ] [-Force] [-PassThru] [-WhatIf] [-Confirm] []' } ) { $result = (Get-Command -Name 'Set-SqlDscDatabaseProperty').ParameterSets | diff --git a/tests/Unit/Public/Test-SqlDscDatabaseProperty.Tests.ps1 b/tests/Unit/Public/Test-SqlDscDatabaseProperty.Tests.ps1 index f164891192..ba4a68cadb 100644 --- a/tests/Unit/Public/Test-SqlDscDatabaseProperty.Tests.ps1 +++ b/tests/Unit/Public/Test-SqlDscDatabaseProperty.Tests.ps1 @@ -50,7 +50,7 @@ BeforeDiscovery { 'DatabaseOwnershipChaining' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'DataRetentionEnabled' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'DateCorrelationOptimization' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } - 'DelayedDurability' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } + 'DelayedDurability' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DelayedDurability]::Disabled; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DelayedDurability]::Disabled } 'EncryptionEnabled' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'HasDatabaseEncryptionKey' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'HasFileInCloud' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } @@ -84,15 +84,15 @@ BeforeDiscovery { 'IsSystemObject' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'IsVarDecimalStorageFormatEnabled' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'IsVarDecimalStorageFormatSupported' = @{ Type = 'Boolean'; TestValue = $true; ExpectedValue = $true } - 'LegacyCardinalityEstimation' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } - 'LegacyCardinalityEstimationForSecondary' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } + 'LegacyCardinalityEstimation' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off } + 'LegacyCardinalityEstimationForSecondary' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off } 'LocalCursorsDefault' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'NestedTriggersEnabled' = @{ Type = 'Boolean'; TestValue = $true; ExpectedValue = $true } 'NumericRoundAbortEnabled' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } - 'ParameterSniffing' = @{ Type = 'Boolean'; TestValue = $true; ExpectedValue = $true } - 'ParameterSniffingForSecondary' = @{ Type = 'Boolean'; TestValue = $true; ExpectedValue = $true } - 'QueryOptimizerHotfixes' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } - 'QueryOptimizerHotfixesForSecondary' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } + 'ParameterSniffing' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On } + 'ParameterSniffingForSecondary' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On } + 'QueryOptimizerHotfixes' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off } + 'QueryOptimizerHotfixesForSecondary' = @{ Type = 'Enum'; TestValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off; ExpectedValue = [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off } 'QuotedIdentifiersEnabled' = @{ Type = 'Boolean'; TestValue = $true; ExpectedValue = $true } 'ReadOnly' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } 'RecursiveTriggersEnabled' = @{ Type = 'Boolean'; TestValue = $false; ExpectedValue = $false } @@ -221,6 +221,10 @@ BeforeDiscovery { { [Microsoft.SqlServer.Management.Smo.ContainmentType]::Partial } + 'DelayedDurability' + { + [Microsoft.SqlServer.Management.Smo.DelayedDurability]::Allowed + } 'DatabaseEngineEdition' { [Microsoft.SqlServer.Management.Common.DatabaseEngineEdition]::Enterprise @@ -233,6 +237,30 @@ BeforeDiscovery { { [Microsoft.SqlServer.Management.Smo.FilestreamNonTransactedAccessType]::ReadOnly } + 'LegacyCardinalityEstimation' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On + } + 'LegacyCardinalityEstimationForSecondary' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On + } + 'ParameterSniffing' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off + } + 'ParameterSniffingForSecondary' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::Off + } + 'QueryOptimizerHotfixes' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On + } + 'QueryOptimizerHotfixesForSecondary' + { + [Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff]::On + } 'LogReuseWaitStatus' { [Microsoft.SqlServer.Management.Smo.LogReuseWaitStatus]::LogBackup @@ -390,13 +418,13 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { } It 'Should return true when boolean property matches' { - $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose $false + $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose:$false $result | Should -BeTrue } It 'Should return false when boolean property does not match' { - $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose $true + $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'TestDatabase' -AutoClose:$true $result | Should -BeFalse } @@ -531,13 +559,13 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should throw an exception when property does not exist on the database object' { # AcceleratedRecoveryEnabled is not added to the minimal database object - { Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled $true -ErrorAction 'Stop' } | + { Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled:$true -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage "The property 'AcceleratedRecoveryEnabled' does not exist on database 'MinimalDatabase'. This might be due to the property not being supported on this SQL Server version.*" } It 'Should continue testing other properties after encountering a missing property' { # Test with both a missing property and an existing property - $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled $true -Collation 'SQL_Latin1_General_CP1_CI_AS' -ErrorAction 'SilentlyContinue' + $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled:$true -Collation 'SQL_Latin1_General_CP1_CI_AS' -ErrorAction 'SilentlyContinue' # Should return true because the existing property (Collation) matches $result | Should -BeTrue @@ -545,7 +573,7 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should return false when a missing property is tested along with a non-matching property' { # Test with a missing property and a non-matching existing property - $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled $true -Collation 'Different_Collation' -ErrorAction 'SilentlyContinue' + $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObject -Name 'MinimalDatabase' -AcceleratedRecoveryEnabled:$true -Collation 'Different_Collation' -ErrorAction 'SilentlyContinue' # Should return false because the existing property (Collation) does not match $result | Should -BeFalse @@ -556,11 +584,11 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { It 'Should have the correct parameters in parameter set ' -ForEach @( @{ ExpectedParameterSetName = 'ServerObjectSet' - ExpectedParameters = '-ServerObject -Name [-Refresh] [-AcceleratedRecoveryEnabled ] [-ActiveDirectory ] [-AnsiNullDefault ] [-AnsiNullsEnabled ] [-AnsiPaddingEnabled ] [-AnsiWarningsEnabled ] [-ArithmeticAbortEnabled ] [-AutoClose ] [-AutoCreateIncrementalStatisticsEnabled ] [-AutoCreateStatisticsEnabled ] [-AutoShrink ] [-AutoUpdateStatisticsAsync ] [-AutoUpdateStatisticsEnabled ] [-BrokerEnabled ] [-CaseSensitive ] [-ChangeTrackingAutoCleanUp ] [-ChangeTrackingEnabled ] [-CloseCursorsOnCommitEnabled ] [-ConcatenateNullYieldsNull ] [-DatabaseOwnershipChaining ] [-DataRetentionEnabled ] [-DateCorrelationOptimization ] [-DelayedDurability ] [-EncryptionEnabled ] [-HasDatabaseEncryptionKey ] [-HasFileInCloud ] [-HasMemoryOptimizedObjects ] [-HonorBrokerPriority ] [-IsAccessible ] [-IsDatabaseSnapshot ] [-IsDatabaseSnapshotBase ] [-IsDbAccessAdmin ] [-IsDbBackupOperator ] [-IsDbDataReader ] [-IsDbDataWriter ] [-IsDbDdlAdmin ] [-IsDbDenyDataReader ] [-IsDbDenyDataWriter ] [-IsDbManager ] [-IsDbOwner ] [-IsDbSecurityAdmin ] [-IsFabricDatabase ] [-IsFullTextEnabled ] [-IsLedger ] [-IsLoginManager ] [-IsMailHost ] [-IsManagementDataWarehouse ] [-IsMaxSizeApplicable ] [-IsMirroringEnabled ] [-IsParameterizationForced ] [-IsReadCommittedSnapshotOn ] [-IsSqlDw ] [-IsSqlDwEdition ] [-IsSystemObject ] [-IsVarDecimalStorageFormatEnabled ] [-IsVarDecimalStorageFormatSupported ] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault ] [-NestedTriggersEnabled ] [-NumericRoundAbortEnabled ] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled ] [-ReadOnly ] [-RecursiveTriggersEnabled ] [-RemoteDataArchiveEnabled ] [-RemoteDataArchiveUseFederatedServiceAccount ] [-TemporalHistoryRetentionEnabled ] [-TransformNoiseWords ] [-Trustworthy ] [-WarnOnRename ] [-ActiveConnections ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-ID ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringRoleSequence ] [-MirroringSafetySequence ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-Version ] [-IndexSpaceUsage ] [-MaxSizeInBytes ] [-MemoryAllocatedToMemoryOptimizedObjectsInKB ] [-MemoryUsedByMemoryOptimizedObjectsInKB ] [-MirroringFailoverLogSequenceNumber ] [-PersistentVersionStoreSizeKB ] [-SpaceAvailable ] [-Size ] [-AvailabilityGroupName ] [-AzureServiceObjective ] [-CatalogCollation ] [-Collation ] [-DboLogin ] [-DefaultFileGroup ] [-DefaultFileStreamFileGroup ] [-DefaultFullTextCatalog ] [-DefaultSchema ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-Owner ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-UserName ] [-AzureEdition ] [-CreateDate ] [-LastBackupDate ] [-LastDifferentialBackupDate ] [-LastGoodCheckDbTime ] [-LastLogBackupDate ] [-DatabaseGuid ] [-MirroringID ] [-RecoveryForkGuid ] [-ServiceBrokerGuid ] [-AvailabilityDatabaseSynchronizationState ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DatabaseEngineEdition ] [-DatabaseEngineType ] [-FilestreamNonTransactedAccess ] [-LogReuseWaitStatus ] [-MirroringSafetyLevel ] [-MirroringStatus ] [-MirroringWitnessStatus ] [-PageVerify ] [-RecoveryModel ] [-ReplicationOptions ] [-SnapshotIsolationState ] [-State ] [-Status ] [-UserAccess ] []' + ExpectedParameters = '-ServerObject -Name [-Refresh] [-AcceleratedRecoveryEnabled] [-ActiveDirectory] [-AnsiNullDefault] [-AnsiNullsEnabled] [-AnsiPaddingEnabled] [-AnsiWarningsEnabled] [-ArithmeticAbortEnabled] [-AutoClose] [-AutoCreateIncrementalStatisticsEnabled] [-AutoCreateStatisticsEnabled] [-AutoShrink] [-AutoUpdateStatisticsAsync] [-AutoUpdateStatisticsEnabled] [-BrokerEnabled] [-CaseSensitive] [-ChangeTrackingAutoCleanUp] [-ChangeTrackingEnabled] [-CloseCursorsOnCommitEnabled] [-ConcatenateNullYieldsNull] [-DatabaseOwnershipChaining] [-DataRetentionEnabled] [-DateCorrelationOptimization] [-DelayedDurability ] [-EncryptionEnabled] [-HasDatabaseEncryptionKey] [-HasFileInCloud] [-HasMemoryOptimizedObjects] [-HonorBrokerPriority] [-IsAccessible] [-IsDatabaseSnapshot] [-IsDatabaseSnapshotBase] [-IsDbAccessAdmin] [-IsDbBackupOperator] [-IsDbDataReader] [-IsDbDataWriter] [-IsDbDdlAdmin] [-IsDbDenyDataReader] [-IsDbDenyDataWriter] [-IsDbManager] [-IsDbOwner] [-IsDbSecurityAdmin] [-IsFabricDatabase] [-IsFullTextEnabled] [-IsLedger] [-IsLoginManager] [-IsMailHost] [-IsManagementDataWarehouse] [-IsMaxSizeApplicable] [-IsMirroringEnabled] [-IsParameterizationForced] [-IsReadCommittedSnapshotOn] [-IsSqlDw] [-IsSqlDwEdition] [-IsSystemObject] [-IsVarDecimalStorageFormatEnabled] [-IsVarDecimalStorageFormatSupported] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault] [-NestedTriggersEnabled] [-NumericRoundAbortEnabled] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled] [-ReadOnly] [-RecursiveTriggersEnabled] [-RemoteDataArchiveEnabled] [-RemoteDataArchiveUseFederatedServiceAccount] [-TemporalHistoryRetentionEnabled] [-TransformNoiseWords] [-Trustworthy] [-WarnOnRename] [-ActiveConnections ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-ID ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringRoleSequence ] [-MirroringSafetySequence ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-Version ] [-IndexSpaceUsage ] [-MaxSizeInBytes ] [-MemoryAllocatedToMemoryOptimizedObjectsInKB ] [-MemoryUsedByMemoryOptimizedObjectsInKB ] [-MirroringFailoverLogSequenceNumber ] [-PersistentVersionStoreSizeKB ] [-SpaceAvailable ] [-Size ] [-AvailabilityGroupName ] [-AzureServiceObjective ] [-CatalogCollation ] [-Collation ] [-DboLogin ] [-DefaultFileGroup ] [-DefaultFileStreamFileGroup ] [-DefaultFullTextCatalog ] [-DefaultSchema ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-Owner ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-UserName ] [-AzureEdition ] [-CreateDate ] [-LastBackupDate ] [-LastDifferentialBackupDate ] [-LastGoodCheckDbTime ] [-LastLogBackupDate ] [-DatabaseGuid ] [-MirroringID ] [-RecoveryForkGuid ] [-ServiceBrokerGuid ] [-AvailabilityDatabaseSynchronizationState ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DatabaseEngineEdition ] [-DatabaseEngineType ] [-FilestreamNonTransactedAccess ] [-LogReuseWaitStatus ] [-MirroringSafetyLevel ] [-MirroringStatus ] [-MirroringWitnessStatus ] [-PageVerify ] [-RecoveryModel ] [-ReplicationOptions ] [-SnapshotIsolationState ] [-State ] [-Status ] [-UserAccess ] []' } @{ ExpectedParameterSetName = 'DatabaseObjectSet' - ExpectedParameters = '-DatabaseObject [-AcceleratedRecoveryEnabled ] [-ActiveDirectory ] [-AnsiNullDefault ] [-AnsiNullsEnabled ] [-AnsiPaddingEnabled ] [-AnsiWarningsEnabled ] [-ArithmeticAbortEnabled ] [-AutoClose ] [-AutoCreateIncrementalStatisticsEnabled ] [-AutoCreateStatisticsEnabled ] [-AutoShrink ] [-AutoUpdateStatisticsAsync ] [-AutoUpdateStatisticsEnabled ] [-BrokerEnabled ] [-CaseSensitive ] [-ChangeTrackingAutoCleanUp ] [-ChangeTrackingEnabled ] [-CloseCursorsOnCommitEnabled ] [-ConcatenateNullYieldsNull ] [-DatabaseOwnershipChaining ] [-DataRetentionEnabled ] [-DateCorrelationOptimization ] [-DelayedDurability ] [-EncryptionEnabled ] [-HasDatabaseEncryptionKey ] [-HasFileInCloud ] [-HasMemoryOptimizedObjects ] [-HonorBrokerPriority ] [-IsAccessible ] [-IsDatabaseSnapshot ] [-IsDatabaseSnapshotBase ] [-IsDbAccessAdmin ] [-IsDbBackupOperator ] [-IsDbDataReader ] [-IsDbDataWriter ] [-IsDbDdlAdmin ] [-IsDbDenyDataReader ] [-IsDbDenyDataWriter ] [-IsDbManager ] [-IsDbOwner ] [-IsDbSecurityAdmin ] [-IsFabricDatabase ] [-IsFullTextEnabled ] [-IsLedger ] [-IsLoginManager ] [-IsMailHost ] [-IsManagementDataWarehouse ] [-IsMaxSizeApplicable ] [-IsMirroringEnabled ] [-IsParameterizationForced ] [-IsReadCommittedSnapshotOn ] [-IsSqlDw ] [-IsSqlDwEdition ] [-IsSystemObject ] [-IsVarDecimalStorageFormatEnabled ] [-IsVarDecimalStorageFormatSupported ] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault ] [-NestedTriggersEnabled ] [-NumericRoundAbortEnabled ] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled ] [-ReadOnly ] [-RecursiveTriggersEnabled ] [-RemoteDataArchiveEnabled ] [-RemoteDataArchiveUseFederatedServiceAccount ] [-TemporalHistoryRetentionEnabled ] [-TransformNoiseWords ] [-Trustworthy ] [-WarnOnRename ] [-ActiveConnections ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-ID ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringRoleSequence ] [-MirroringSafetySequence ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-Version ] [-IndexSpaceUsage ] [-MaxSizeInBytes ] [-MemoryAllocatedToMemoryOptimizedObjectsInKB ] [-MemoryUsedByMemoryOptimizedObjectsInKB ] [-MirroringFailoverLogSequenceNumber ] [-PersistentVersionStoreSizeKB ] [-SpaceAvailable ] [-Size ] [-AvailabilityGroupName ] [-AzureServiceObjective ] [-CatalogCollation ] [-Collation ] [-DboLogin ] [-DefaultFileGroup ] [-DefaultFileStreamFileGroup ] [-DefaultFullTextCatalog ] [-DefaultSchema ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-Owner ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-UserName ] [-AzureEdition ] [-CreateDate ] [-LastBackupDate ] [-LastDifferentialBackupDate ] [-LastGoodCheckDbTime ] [-LastLogBackupDate ] [-DatabaseGuid ] [-MirroringID ] [-RecoveryForkGuid ] [-ServiceBrokerGuid ] [-AvailabilityDatabaseSynchronizationState ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DatabaseEngineEdition ] [-DatabaseEngineType ] [-FilestreamNonTransactedAccess ] [-LogReuseWaitStatus ] [-MirroringSafetyLevel ] [-MirroringStatus ] [-MirroringWitnessStatus ] [-PageVerify ] [-RecoveryModel ] [-ReplicationOptions ] [-SnapshotIsolationState ] [-State ] [-Status ] [-UserAccess ] []' + ExpectedParameters = '-DatabaseObject [-AcceleratedRecoveryEnabled] [-ActiveDirectory] [-AnsiNullDefault] [-AnsiNullsEnabled] [-AnsiPaddingEnabled] [-AnsiWarningsEnabled] [-ArithmeticAbortEnabled] [-AutoClose] [-AutoCreateIncrementalStatisticsEnabled] [-AutoCreateStatisticsEnabled] [-AutoShrink] [-AutoUpdateStatisticsAsync] [-AutoUpdateStatisticsEnabled] [-BrokerEnabled] [-CaseSensitive] [-ChangeTrackingAutoCleanUp] [-ChangeTrackingEnabled] [-CloseCursorsOnCommitEnabled] [-ConcatenateNullYieldsNull] [-DatabaseOwnershipChaining] [-DataRetentionEnabled] [-DateCorrelationOptimization] [-DelayedDurability ] [-EncryptionEnabled] [-HasDatabaseEncryptionKey] [-HasFileInCloud] [-HasMemoryOptimizedObjects] [-HonorBrokerPriority] [-IsAccessible] [-IsDatabaseSnapshot] [-IsDatabaseSnapshotBase] [-IsDbAccessAdmin] [-IsDbBackupOperator] [-IsDbDataReader] [-IsDbDataWriter] [-IsDbDdlAdmin] [-IsDbDenyDataReader] [-IsDbDenyDataWriter] [-IsDbManager] [-IsDbOwner] [-IsDbSecurityAdmin] [-IsFabricDatabase] [-IsFullTextEnabled] [-IsLedger] [-IsLoginManager] [-IsMailHost] [-IsManagementDataWarehouse] [-IsMaxSizeApplicable] [-IsMirroringEnabled] [-IsParameterizationForced] [-IsReadCommittedSnapshotOn] [-IsSqlDw] [-IsSqlDwEdition] [-IsSystemObject] [-IsVarDecimalStorageFormatEnabled] [-IsVarDecimalStorageFormatSupported] [-LegacyCardinalityEstimation ] [-LegacyCardinalityEstimationForSecondary ] [-LocalCursorsDefault] [-NestedTriggersEnabled] [-NumericRoundAbortEnabled] [-ParameterSniffing ] [-ParameterSniffingForSecondary ] [-QueryOptimizerHotfixes ] [-QueryOptimizerHotfixesForSecondary ] [-QuotedIdentifiersEnabled] [-ReadOnly] [-RecursiveTriggersEnabled] [-RemoteDataArchiveEnabled] [-RemoteDataArchiveUseFederatedServiceAccount] [-TemporalHistoryRetentionEnabled] [-TransformNoiseWords] [-Trustworthy] [-WarnOnRename] [-ActiveConnections ] [-ChangeTrackingRetentionPeriod ] [-DefaultFullTextLanguage ] [-DefaultLanguage ] [-ID ] [-MaxDop ] [-MaxDopForSecondary ] [-MirroringRedoQueueMaxSize ] [-MirroringRoleSequence ] [-MirroringSafetySequence ] [-MirroringTimeout ] [-TargetRecoveryTime ] [-TwoDigitYearCutoff ] [-Version ] [-IndexSpaceUsage ] [-MaxSizeInBytes ] [-MemoryAllocatedToMemoryOptimizedObjectsInKB ] [-MemoryUsedByMemoryOptimizedObjectsInKB ] [-MirroringFailoverLogSequenceNumber ] [-PersistentVersionStoreSizeKB ] [-SpaceAvailable ] [-Size ] [-AvailabilityGroupName ] [-AzureServiceObjective ] [-CatalogCollation ] [-Collation ] [-DboLogin ] [-DefaultFileGroup ] [-DefaultFileStreamFileGroup ] [-DefaultFullTextCatalog ] [-DefaultSchema ] [-FilestreamDirectoryName ] [-MirroringPartner ] [-MirroringPartnerInstance ] [-MirroringWitness ] [-Owner ] [-PersistentVersionStoreFileGroup ] [-PrimaryFilePath ] [-RemoteDataArchiveCredential ] [-RemoteDataArchiveEndpoint ] [-RemoteDataArchiveLinkedServer ] [-RemoteDatabaseName ] [-UserName ] [-AzureEdition ] [-CreateDate ] [-LastBackupDate ] [-LastDifferentialBackupDate ] [-LastGoodCheckDbTime ] [-LastLogBackupDate ] [-DatabaseGuid ] [-MirroringID ] [-RecoveryForkGuid ] [-ServiceBrokerGuid ] [-AvailabilityDatabaseSynchronizationState ] [-ChangeTrackingRetentionPeriodUnits ] [-CompatibilityLevel ] [-ContainmentType ] [-DatabaseEngineEdition ] [-DatabaseEngineType ] [-FilestreamNonTransactedAccess ] [-LogReuseWaitStatus ] [-MirroringSafetyLevel ] [-MirroringStatus ] [-MirroringWitnessStatus ] [-PageVerify ] [-RecoveryModel ] [-ReplicationOptions ] [-SnapshotIsolationState ] [-State ] [-Status ] [-UserAccess ] []' } ) { $result = (Get-Command -Name 'Test-SqlDscDatabaseProperty').ParameterSets | @@ -760,7 +788,7 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { # Test a combination of different property types $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObjectForAll -Name 'TestDatabase' ` -Collation 'SQL_Latin1_General_CP1_CI_AS' ` - -AutoClose $false ` + -AutoClose:$false ` -MaxDop 0 ` -RecoveryModel 'Full' ` -Owner 'sa' @@ -772,7 +800,7 @@ Describe 'Test-SqlDscDatabaseProperty' -Tag 'Public' { # Test a combination where one property doesn't match $result = Test-SqlDscDatabaseProperty -ServerObject $mockServerObjectForAll -Name 'TestDatabase' ` -Collation 'SQL_Latin1_General_CP1_CI_AS' ` - -AutoClose $true ` + -AutoClose:$true ` -MaxDop 0 ` -RecoveryModel 'Full' ` -Owner 'sa' diff --git a/tests/Unit/Stubs/SMO.cs b/tests/Unit/Stubs/SMO.cs index ea58a234a9..b124d67ad5 100644 --- a/tests/Unit/Stubs/SMO.cs +++ b/tests/Unit/Stubs/SMO.cs @@ -272,6 +272,13 @@ public enum DelayedDurability : int Forced = 2 } + public enum DatabaseScopedConfigurationOnOff : int + { + Off = 0, + On = 1, + Primary = 2 + } + public enum MirroringStatus : int { None = 0,