diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 0c13825d3..337ea35d0 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,10 +1,10 @@ **Details of the scenario you tried and the problem that is occurring:** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 57f54638e..7b84ac775 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,13 +3,13 @@ Thanks for submitting a Pull Request (PR) to this project. Your contribution to this project is greatly appreciated! Please make sure you have read the contributing section -at https://github.com/PowerShell/xSQLServer#contributing. +at https://github.com/PowerShell/SqlServerDsc#contributing. Please prefix the PR title with the resource name, -i.e. 'xSQLServerSetup: My short description' +i.e. 'SqlSetup: My short description' If this is a breaking change, then also prefix the PR title with 'BREAKING CHANGE:', -i.e. 'BREAKING CHANGE: xSQLServerSetup: My short description' +i.e. 'BREAKING CHANGE: SqlSetup: My short description' --> **Pull Request (PR) description** diff --git a/CHANGELOG.md b/CHANGELOG.md index 5955ccd51..b88a56987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,128 @@ -# Change log for xSQLServer +# Change log for SqlServerDsc ## Unreleased +## 10.0.0.0 + +- BREAKING CHANGE: Resource module has been renamed to SqlServerDsc + ([issue #916](https://github.com/PowerShell/SqlServerDsc/issues/916)). +- BREAKING CHANGE: Significant rename to reduce length of resource names + - See [issue #851](https://github.com/PowerShell/SqlServerDsc/issues/851) for a + complete table mapping rename changes. + - Impact to all resources. +- Changes to CONTRIBUTING.md + - Added details to the naming convention used in SqlServerDsc. +- Changes to SqlServerDsc + - The examples in the root of the Examples folder are obsolete. A note was + added to the comment-based help in each example stating it is obsolete. + This is a temporary measure until they are replaced + ([issue #904](https://github.com/PowerShell/SqlServerDsc/issues/904)). + - Added new common test (regression test) for validating the long path + issue for compiling resources in Azure Automation. + - Fix resources in alphabetical order in README.md ([issue #908](https://github.com/PowerShell/SqlServerDsc/issues/908)). +- Changes to SqlAG + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - BREAKING CHANGE: The read-only property SQLServerNetName was removed in favor + of EndpointHostName ([issue #924](https://github.com/PowerShell/SqlServerDsc/issues/924)). + Get-TargetResource will now return the value of property [NetName](https://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.netname(v=sql.105).aspx) + for the property EndpointHostName. +- Changes to SqlAGDatabase + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - Changed the Get-MatchingDatabaseNames function to be case insensitive when + matching database names ([issue #912](https://github.com/PowerShell/SqlServerDsc/issues/912)). +- Changes to SqlAGListener + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlAGReplica + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - BREAKING CHANGE: Parameters PrimaryReplicaSQLServer and PrimaryReplicaSQLInstanceName + has been renamed to PrimaryReplicaServerName and PrimaryReplicaInstanceName + respectively ([issue #922](https://github.com/PowerShell/SqlServerDsc/issues/922)). + - BREAKING CHANGE: The read-only property SQLServerNetName was removed in favor + of EndpointHostName ([issue #924](https://github.com/PowerShell/SqlServerDsc/issues/924)). + Get-TargetResource will now return the value of property [NetName](https://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.netname(v=sql.105).aspx) + for the property EndpointHostName. +- Changes to SqlAlwaysOnService + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabase + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes SqlDatabaseDefaultLocation + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseOwner + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabasePermission + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseRecoveryModel + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseRole + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlRS + - BREAKING CHANGE: Parameters RSSQLServer and RSSQLInstanceName has been renamed + to DatabaseServerName and DatabaseInstanceName respectively + ([issue #923](https://github.com/PowerShell/SqlServerDsc/issues/923)). +- Changes to SqlServerConfiguration + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerEndpoint + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerEndpointPermission + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - Now the examples files have a shorter name so that resources will not fail + to compile in Azure Automation ([issue #934](https://github.com/PowerShell/SqlServerDsc/issues/934)). +- Changes to SqlServerEndpointState + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerLogin + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerMaxDop + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerMemory + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerNetwork + - BREAKING CHANGE: Parameters SQLServer has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerPermission + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerRole + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerServiceAccount + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue #308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + ## 9.0.0.0 - Changes to xSQLServer diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c21594bcc..6c9ef1bb8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Contributing to xSQLServer +# Contributing to SqlServerDsc -If you are keen to make xSQLServer better, why not consider contributing your work +If you are keen to make SqlServerDsc better, why not consider contributing your work to the project? Every little change helps us make a better resource for everyone to use, and we would love to have contributions from the community. @@ -10,7 +10,7 @@ We follow all of the standard contribution guidelines for DSC resources [outlined in DscResources repository](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md), so please review these as a baseline for contributing. -## xSQLServer specific guidelines +## SqlServerDsc specific guidelines ### Automatic formatting with VS Code @@ -34,10 +34,74 @@ Those SQL Server products that are still supported can be listed at the ### Naming convention +The DSC resources contained in SqlServerDsc use the following naming convention: + +```naming +[][]{|} +``` + +The following list describes the components that make up a resource name and +lists possible names used for each of the components. The component names are +not limited to the names in this list. + +- **Module Identifier** + - **Sql** +- **Component** + - **\** - Database Engine _(No component abbreviation)_ + - **AS** - Analysis Services + - **IS** - Integration Services + - **RS** - Reporting Services +- **Action** _(not required)_ + - **Setup** + - **WaitFor** +- **Scope** - Where the action, feature, or property is being applied. + - **AG** (AvailabilityGroup) + - **Database** + - **Server** + - **ServiceAccount** + - **Windows** +- **Feature** + - **AlwaysOn** - This is for the overall AlwaysOn feature + - **Endpoint** + - **Firewall** + - **Network** + - **Script** +- **Property** _(not required)_ + - **Alias** + - **Configuration** + - **Database** + - **DatabaseMembership** + - **DefaultLocation** + - **Listener** + - **Login** + - **MaxDop** + - **Memory** + - **Owner** + - **Permission** + - **RecoveryModel** + - **Replica** + - **Replication** + - **Role** + - **SecureConnectionLevel** + - **Service** + - **State** + +#### Example of Resource Naming + +The `SqlServerEndpointPermission` resource name is built using the defined +naming structure using the following components. + +- **Module Identifier**: Sql +- **Component**: \ +- **Action**: \ +- **Scope**: Server +- **Feature**: Endpoint +- **Property**: Permission + #### mof-based resource All mof-based resource (with Get/Set/Test-TargetResource) should be prefixed with -'MSFT\_xSQLServer'. I.e. MSFT\_xSQLServerConfiguration +'MSFT\_Sql'. I.e. MSFT\_SqlDatabase Please note that not all places should contain the prefix 'MSFT\_'. @@ -49,14 +113,14 @@ This is to make those folders more user friendly, to resemble the name the user would use in the configuration file. ```Text -DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.psm1 -DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.schema.mof -DSCResources/MSFT_xSQLServerConfiguration/en-US/MSFT_xSQLServerConfiguration.strings.psd1 +DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 +DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof +DSCResources/MSFT_SqlServerConfiguration/en-US/MSFT_SqlServerConfiguration.strings.psd1 -Tests/Unit/MSFT_xSQLServerConfiguration.Tests.ps1 +Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 -Examples/Resources/xSQLServerConfiguration/1-AddConfigurationOption.ps1 -Examples/Resources/xSQLServerConfiguration/2-RemoveConfigurationOption.ps1 +Examples/Resources/SqlServerConfiguration/1-AddConfigurationOption.ps1 +Examples/Resources/SqlServerConfiguration/2-RemoveConfigurationOption.ps1 ``` ##### Schema mof file @@ -65,8 +129,8 @@ Please note that the `FriendlyName` in the schema mof file should not contain th prefix `MSFT\_`. ```powershell -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerConfiguration")] -class MSFT_xSQLServerConfiguration : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerConfiguration")] +class MSFT_SqlServerConfiguration : OMI_BaseResource { # Properties removed for readability. }; @@ -75,7 +139,7 @@ class MSFT_xSQLServerConfiguration : OMI_BaseResource #### Composite or class-based resource Any composite (with a Configuration) or class-based resources should be prefixed -with just 'xSQLServer' +with just 'Sql' ### Localization @@ -87,7 +151,7 @@ In each resource folder there should be, at least, a localization folder for english language 'en-US'. In the 'en-US' (and any other language folder) there should be a file named 'MSFT_ResourceName.strings.psd1', i.e. -'MSFT_xSQLServerSetup.strings.psd1'. +'MSFT_SqlSetup.strings.psd1'. At the top of each resource the localized strings should be loaded, see the helper function `Get-LocalizedData` for more information on how this is done. @@ -95,7 +159,7 @@ The localized string file should contain the following (beside the localization strings) ```powershell -# Localized resources for xSQLServerSetup +# Localized resources for SqlSetup ConvertFrom-StringData @' InstallingUsingPathMessage = Installing using path '{0}'. @@ -272,7 +336,7 @@ This should be used at the top of each resource like this. Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerSetup' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlSetup' ``` #### Old localization helper function @@ -280,9 +344,9 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerSetup' To be able to support localization we have added wrappers for the cmdlets `Write-Verbose` and `Write-Warning`, and also for creating a terminating error message. -The localized strings are placed in a file named 'xSQLServerHelper.strings.psd1' +The localized strings are placed in a file named 'SqlServerDscHelper.strings.psd1' which are located in each language folder in the root of the module. For English -language strings the folder is ['en-US'](https://github.com/PowerShell/xSQLServer/blob/dev/en-US). +language strings the folder is ['en-US'](https://github.com/PowerShell/SqlServerDsc/blob/dev/en-US). ##### New-TerminatingError @@ -305,7 +369,7 @@ Helper functions or wrapper functions that are used by the resource can preferab be placed in the resource module file. If the functions are of a type that could be used by more than one resource, then the functions can also be placed in the common -[xSQLServerHelper.psm1](https://github.com/PowerShell/xSQLServer/blob/dev/xSQLServerHelper.psm1) +[SqlServerDscHelper.psm1](https://github.com/PowerShell/SqlServerDsc/blob/dev/SqlServerDscHelper.psm1) module file. ### Tests @@ -340,12 +404,13 @@ When sending in a Pull Request (PR) all example files will be tested so they can be compiled to a .mof file. If the tests find any errors the build will fail. Before the test runs in AppVeyor the module will be copied to the first path of `$env:PSModulePath`. -To run this test locally, make sure you have the xSQLServer module deployed to a -path where it can be used. See `$env:PSModulePath` to view the existing paths. +To run this test locally, make sure you have the SqlServerDsc module +deployed to a path where it can be used. +See `$env:PSModulePath` to view the existing paths. #### Using SMO stub classes -There are [stub classes](https://github.com/PowerShell/xSQLServer/blob/dev/Tests/Unit/Stubs/SMO.cs) +There are [stub classes](https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Unit/Stubs/SMO.cs) for the SMO classes which can be used and improved on when creating tests where SMO classes are used in the code being tested. diff --git a/DSCResources/CommonResourceHelper.psm1 b/DSCResources/CommonResourceHelper.psm1 index 61e4f7676..bf18d83b8 100644 --- a/DSCResources/CommonResourceHelper.psm1 +++ b/DSCResources/CommonResourceHelper.psm1 @@ -204,7 +204,7 @@ function New-InvalidResultException For WindowsOptionalFeature: MSFT_WindowsOptionalFeature For Service: MSFT_ServiceResource For Registry: MSFT_RegistryResource - For Helper: xSQLServerHelper + For Helper: SqlServerDscHelper .PARAMETER ScriptRoot Optional. The root path where to expect to find the culture folder. This is only needed diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.psm1 b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 similarity index 96% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.psm1 rename to DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 index 1c87a2bb6..ecc67bd6a 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.psm1 +++ b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -9,10 +9,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configured. #> function Get-TargetResource @@ -27,15 +27,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName + $InstanceName ) # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Define current version for check compatibility $sqlMajorVersion = $serverObject.Version.Major @@ -56,8 +56,8 @@ function Get-TargetResource # Create the return object. Default ensure to Absent. $alwaysOnAvailabilityGroupResource = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName Ensure = 'Absent' IsActiveNode = $isActiveNode } @@ -76,7 +76,7 @@ function Get-TargetResource $alwaysOnAvailabilityGroupResource.HealthCheckTimeout = $availabilityGroup.HealthCheckTimeout $alwaysOnAvailabilityGroupResource.EndpointURL = $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].EndpointUrl $alwaysOnAvailabilityGroupResource.EndpointPort = $endpointPort - $alwaysOnAvailabilityGroupResource.SQLServerNetName = $serverObject.NetName + $alwaysOnAvailabilityGroupResource.EndpointHostName = $serverObject.NetName $alwaysOnAvailabilityGroupResource.Version = $sqlMajorVersion # Add properties that are only present in SQL 2016 or newer @@ -98,10 +98,10 @@ function Get-TargetResource .PARAMETER Name The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configured. .PARAMETER Ensure @@ -155,11 +155,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -235,12 +235,12 @@ function Set-TargetResource Import-SQLPSModule # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Determine if HADR is enabled on the instance. If not, throw an error if ( -not $serverObject.IsHadrEnabled ) { - throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $SQLInstanceName -ErrorCategory NotImplemented + throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $InstanceName -ErrorCategory NotImplemented } # Define current version for check compatibility @@ -265,12 +265,12 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $SQLInstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception + throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $InstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception } } else { - throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $SQLInstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable + throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $InstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable } } } @@ -284,7 +284,7 @@ function Set-TargetResource $endpoint = $serverObject.Endpoints | Where-Object { $_.EndpointType -eq 'DatabaseMirroring' } if ( -not $endpoint ) { - throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $SQLServer, $SQLInstanceName -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $ServerName, $InstanceName -ErrorCategory ObjectNotFound } if ( -not $EndpointHostName ) @@ -327,7 +327,7 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $SQLInstanceName -ErrorCategory OperationStopped -InnerException $_.Exception + throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception } # Set up the parameters for the new availability group @@ -477,10 +477,10 @@ function Set-TargetResource .PARAMETER Name The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configured. .PARAMETER Ensure @@ -534,11 +534,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -606,8 +606,8 @@ function Test-TargetResource ) $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName Name = $Name } @@ -622,7 +622,7 @@ function Test-TargetResource #> if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { - New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $result } @@ -647,8 +647,8 @@ function Test-TargetResource { $parametersToCheck = @( 'Name', - 'SQLServer', - 'SQLInstanceName', + 'ServerName', + 'InstanceName', 'Ensure', 'AutomatedBackupPreference', 'AvailabilityMode', @@ -700,7 +700,7 @@ function Test-TargetResource if ( -not $EndpointHostName ) { - $EndpointHostName = $getTargetResourceResult.SQLServerNetName + $EndpointHostName = $getTargetResourceResult.EndpointHostName } # Verify the hostname in the endpoint URL is correct diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.schema.mof b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof similarity index 92% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.schema.mof rename to DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof index 7cf156426..60031896c 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroup/MSFT_xSQLServerAlwaysOnAvailabilityGroup.schema.mof +++ b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAlwaysOnAvailabilityGroup")] -class MSFT_xSQLServerAlwaysOnAvailabilityGroup : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlAG")] +class MSFT_SqlAG : OMI_BaseResource { [Key, Description("The name of the availability group.")] String Name; - [Required, Description("Hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; + [Required, Description("Hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; [Write, Description("Specifies if the availability group should be present or absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Specifies the automated backup preference for the availability group. Default is None"), ValueMap{"Primary","SecondaryOnly","Secondary","None"}, Values{"Primary","SecondaryOnly","Secondary","None"}] String AutomatedBackupPreference; [Write, Description("Specifies the replica availability mode. Default is 'AsynchronousCommit'."), ValueMap{"AsynchronousCommit","SynchronousCommit"}, Values{"AsynchronousCommit","SynchronousCommit"}] String AvailabilityMode; @@ -20,7 +20,6 @@ class MSFT_xSQLServerAlwaysOnAvailabilityGroup : OMI_BaseResource [Write, Description("Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server Instance.")] Boolean ProcessOnlyOnActiveNode; [Read, Description("Gets the Endpoint URL of the availability group replica endpoint.")] String EndpointUrl; [Read, Description("Gets the port the database mirroring endpoint is listening on.")] UInt32 EndpointPort; - [Read, Description("Gets the hostname the SQL Server instance is listening on.")] String SQLServerNetName; [Read, Description("Gets the major version of the SQL Server instance.")] UInt32 Version; [Read, Description("Determines if the current node is actively hosting the SQL Server instance.")] Boolean IsActiveNode; }; diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.psm1 b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 similarity index 97% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.psm1 rename to DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 index 5e4cc5283..86ab2da0b 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.psm1 +++ b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 @@ -1,11 +1,11 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlAGDatabase' <# .SYNOPSIS @@ -14,12 +14,12 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerAlwaysOn .PARAMETER DatabaseName The name of the database(s) to add to the availability group. This accepts wildcards. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance where the primary replica of the availability group lives. If the availability group is not currently on this instance, the resource will attempt to connect to the instance where the primary replica lives. @@ -43,11 +43,11 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [System.String] @@ -61,8 +61,8 @@ function Get-TargetResource # Create an object that reflects the current configuration $currentConfiguration = @{ DatabaseName = @() - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName AvailabilityGroupName = '' BackupPath = '' Ensure = '' @@ -72,7 +72,7 @@ function Get-TargetResource } # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Is this node actively hosting the SQL instance? $currentConfiguration.IsActiveNode = Test-ActiveNode -ServerObject $serverObject @@ -102,12 +102,12 @@ function Get-TargetResource .PARAMETER DatabaseName The name of the database(s) to add to the availability group. This accepts wildcards. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance where the primary replica of the availability group lives. If the availability group is not currently on this instance, the resource will attempt to connect to the instance where the primary replica lives. @@ -159,11 +159,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [System.String] @@ -194,7 +194,7 @@ function Set-TargetResource Import-SQLPSModule # Connect to the defined instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Get the Availability Group $availabilityGroup = $serverObject.AvailabilityGroups[$AvailabilityGroupName] @@ -568,12 +568,12 @@ function Set-TargetResource .PARAMETER DatabaseName The name of the database(s) to add to the availability group. This accepts wildcards. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance where the primary replica of the availability group lives. If the availability group is not currently on this instance, the resource will attempt to connect to the instance where the primary replica lives. @@ -625,11 +625,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [System.String] @@ -661,8 +661,8 @@ function Test-TargetResource $getTargetResourceParameters = @{ DatabaseName = $DatabaseName - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName AvailabilityGroupName = $AvailabilityGroupName BackupPath = $BackupPath } @@ -674,12 +674,12 @@ function Test-TargetResource #> if ( $ProcessOnlyOnActiveNode -and -not $currentConfiguration.IsActiveNode ) { - Write-Verbose -Message ( $script:localizedData.NotActiveNode -f $env:COMPUTERNAME,$SQLInstanceName ) + Write-Verbose -Message ( $script:localizedData.NotActiveNode -f $env:COMPUTERNAME,$InstanceName ) return $configurationInDesiredState } # Connect to the defined instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Get the Availability Group if it exists if ( -not [string]::IsNullOrEmpty($currentConfiguration.AvailabilityGroupName) ) @@ -930,7 +930,9 @@ function Get-MatchingDatabaseNames foreach ( $dbName in $DatabaseName ) { - $matchingDatabaseNames += $ServerObject.Databases | Where-Object -FilterScript { $_.Name -like $dbName } | Select-Object -ExpandProperty Name + $matchingDatabaseNames += $ServerObject.Databases | + Where-Object -FilterScript { $_.Name -ilike $dbName } | + Select-Object -ExpandProperty Name } return $matchingDatabaseNames diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.schema.mof b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.schema.mof similarity index 90% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.schema.mof rename to DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.schema.mof index 0df29e907..1a9628f19 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.schema.mof +++ b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership")] -class MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlAGDatabase")] +class MSFT_SqlAGDatabase : OMI_BaseResource { [Required, Description("The name of the database(s) to add to the availability group. This accepts wildcards.")] String DatabaseName[]; - [Key, Description("Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; [Key, Description("The name of the availability group in which to manage the database membership(s).")] String AvailabilityGroupName; [Required, Description("The path used to seed the availability group replicas. This should be a path that is accessible by all of the replicas")] String BackupPath; [Write, Description("Specifies the membership of the database(s) in the availability group. The options are: Present: The defined database(s) are added to the availability group. All other databases that may be a member of the availability group are ignored. Absent: The defined database(s) are removed from the availability group. All other databases that may be a member of the availability group are ignored. The default is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.strings.psd1 b/DSCResources/MSFT_SqlAGDatabase/en-US/MSFT_SqlAGDatabase.strings.psd1 similarity index 92% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.strings.psd1 rename to DSCResources/MSFT_SqlAGDatabase/en-US/MSFT_SqlAGDatabase.strings.psd1 index 4a29519a9..112cf9e1e 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.strings.psd1 +++ b/DSCResources/MSFT_SqlAGDatabase/en-US/MSFT_SqlAGDatabase.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership +# Localized resources for SqlAGDatabase ConvertFrom-StringData @' AddingDatabasesToAvailabilityGroup = Adding the following databases to the '{0}' availability group: {1}. diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/about_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.help.txt b/DSCResources/MSFT_SqlAGDatabase/en-US/about_SqlAGDatabase.help.txt similarity index 98% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/about_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.help.txt rename to DSCResources/MSFT_SqlAGDatabase/en-US/about_SqlAGDatabase.help.txt index eaab5b464..706886d20 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/en-US/about_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.help.txt +++ b/DSCResources/MSFT_SqlAGDatabase/en-US/about_SqlAGDatabase.help.txt @@ -4,12 +4,12 @@ SYNOPSIS PARAMETER DatabaseName The name of the database(s) to add to the availability group. This accepts wildcards. -PARAMETER SQLServer +PARAMETER ServerName Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives. -PARAMETER SQLInstanceName +PARAMETER InstanceName Name of the SQL instance where the primary replica of the availability group lives. If the availability group is not currently on this instance, the resource will attempt to connect to the instance where the primary replica lives. diff --git a/DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.psm1 b/DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.psm1 similarity index 87% rename from DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.psm1 rename to DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.psm1 index fd0b2e382..37c5d768b 100644 --- a/DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.psm1 +++ b/DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.psm1 @@ -1,6 +1,6 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` - -Force + -ChildPath 'SqlServerDscHelper.psm1') ` + -Force <# .SYNOPSIS Returns the current state of the Availability Group listener. @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName The SQL Server instance name of the primary replica. Default value is 'MSSQLSERVER'. - .PARAMETER NodeName + .PARAMETER ServerName The host name or FQDN of the primary replica. .PARAMETER Name @@ -29,10 +29,10 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter(Mandatory = $true)] - [ValidateLength(1,15)] + [ValidateLength(1, 15)] [System.String] $Name, @@ -43,7 +43,7 @@ function Get-TargetResource try { - $availabilityGroupListener = Get-SQLAlwaysOnAvailabilityGroupListener -Name $Name -AvailabilityGroup $AvailabilityGroup -NodeName $NodeName -InstanceName $InstanceName + $availabilityGroupListener = Get-SQLAlwaysOnAvailabilityGroupListener -Name $Name -AvailabilityGroup $AvailabilityGroup -ServerName $ServerName -InstanceName $InstanceName if ($null -ne $availabilityGroupListener) { @@ -77,14 +77,14 @@ function Get-TargetResource } return @{ - InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName - Name = [System.String] $Name - Ensure = [System.String] $ensure + InstanceName = [System.String] $InstanceName + ServerName = [System.String] $ServerName + Name = [System.String] $Name + Ensure = [System.String] $ensure AvailabilityGroup = [System.String] $AvailabilityGroup - IpAddress = [System.String[]] $ipAddress - Port = [System.UInt16] $port - DHCP = [System.Boolean] $dhcp + IpAddress = [System.String[]] $ipAddress + Port = [System.UInt16] $port + DHCP = [System.Boolean] $dhcp } } @@ -95,7 +95,7 @@ function Get-TargetResource .PARAMETER InstanceName The SQL Server instance name of the primary replica. Default value is 'MSSQLSERVER'. - .PARAMETER NodeName + .PARAMETER ServerName The host name or FQDN of the primary replica. .PARAMETER Name @@ -127,15 +127,15 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter(Mandatory = $true)] - [ValidateLength(1,15)] + [ValidateLength(1, 15)] [System.String] $Name, [Parameter()] - [ValidateSet('Present','Absent')] + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present', @@ -157,9 +157,9 @@ function Set-TargetResource ) $parameters = @{ - InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName - Name = [System.String] $Name + InstanceName = [System.String] $InstanceName + ServerName = [System.String] $ServerName + Name = [System.String] $Name AvailabilityGroup = [System.String] $AvailabilityGroup } @@ -172,13 +172,13 @@ function Set-TargetResource { New-VerboseMessage -Message "Create listener on $AvailabilityGroup" - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $availabilityGroupObject = $sqlServerObject.AvailabilityGroups[$AvailabilityGroup] if ($availabilityGroupObject) { $newListenerParams = @{ - Name = $Name + Name = $Name InputObject = $availabilityGroupObject } @@ -213,14 +213,14 @@ function Set-TargetResource } else { - throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup,$InstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound } } else { New-VerboseMessage -Message "Remove listener from $AvailabilityGroup" - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $availabilityGroupObject = $sqlServerObject.AvailabilityGroups[$AvailabilityGroup] if ($availabilityGroupObject) @@ -237,7 +237,7 @@ function Set-TargetResource } else { - throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup,$InstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound } } } @@ -260,11 +260,11 @@ function Set-TargetResource # No new IP-address if ($null -eq $IpAddress -or -not ( Compare-Object -ReferenceObject $IpAddress -DifferenceObject $availabilityGroupListenerState.IpAddress)) { - $ipAddressEqual = $true + $ipAddressEqual = $true } else { - throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '),$($availabilityGroupListenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation + throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '), $($availabilityGroupListenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation } } @@ -273,7 +273,7 @@ function Set-TargetResource throw New-TerminatingError -ErrorType AvailabilityGroupListenerDHCPChangeError -FormatArgs @( $DHCP, $($availabilityGroupListenerState.DHCP) ) -ErrorCategory InvalidOperation } - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $availabilityGroupObject = $sqlServerObject.AvailabilityGroups[$AvailabilityGroup] if ($availabilityGroupObject) @@ -291,7 +291,7 @@ function Set-TargetResource $setListenerParams = @{ InputObject = $availabilityGroupListenerObject - Port = $Port + Port = $Port } Set-SqlAvailabilityGroupListener @setListenerParams -ErrorAction Stop | Out-Null @@ -313,7 +313,7 @@ function Set-TargetResource $setListenerParams = @{ InputObject = $availabilityGroupListenerObject - StaticIp = $newIpAddress + StaticIp = $newIpAddress } Add-SqlAvailabilityGroupListenerStaticIp @setListenerParams -ErrorAction Stop | Out-Null @@ -331,7 +331,7 @@ function Set-TargetResource } else { - throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup,$InstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound } } } @@ -349,7 +349,7 @@ function Set-TargetResource .PARAMETER InstanceName The SQL Server instance name of the primary replica. Default value is 'MSSQLSERVER'. - .PARAMETER NodeName + .PARAMETER ServerName The host name or FQDN of the primary replica. .PARAMETER Name @@ -382,15 +382,15 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter(Mandatory = $true)] - [ValidateLength(1,15)] + [ValidateLength(1, 15)] [System.String] $Name, [Parameter()] - [ValidateSet('Present','Absent')] + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present', @@ -412,9 +412,9 @@ function Test-TargetResource ) $parameters = @{ - InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName - Name = [System.String] $Name + InstanceName = [System.String] $InstanceName + ServerName = [System.String] $ServerName + Name = [System.String] $Name AvailabilityGroup = [System.String] $AvailabilityGroup } @@ -479,12 +479,12 @@ function Get-SQLAlwaysOnAvailabilityGroupListener [Parameter(Mandatory = $true)] [System.String] - $NodeName + $ServerName ) Write-Debug "Connecting to availability group $Name as $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)" - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $availabilityGroupObject = $sqlServerObject.AvailabilityGroups[$AvailabilityGroup] if ($availabilityGroupObject) @@ -493,7 +493,7 @@ function Get-SQLAlwaysOnAvailabilityGroupListener } else { - throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup,$InstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs @($AvailabilityGroup, $InstanceName) -ErrorCategory ObjectNotFound } return $availabilityGroupListener diff --git a/DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.schema.mof b/DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.schema.mof similarity index 87% rename from DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.schema.mof rename to DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.schema.mof index 29c9c83df..781c88df1 100644 --- a/DSCResources/MSFT_xSQLServerAvailabilityGroupListener/MSFT_xSQLServerAvailabilityGroupListener.schema.mof +++ b/DSCResources/MSFT_SqlAGListener/MSFT_SqlAGListener.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAvailabilityGroupListener")] -class MSFT_xSQLServerAvailabilityGroupListener : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlAGListener")] +class MSFT_SqlAGListener : OMI_BaseResource { [Key, Description("The SQL Server instance name of the primary replica.")] String InstanceName; - [Required, Description("The host name or FQDN of the primary replica.")] String NodeName; + [Required, Description("The host name or FQDN of the primary replica.")] String ServerName; [Required, Description("The name of the availability group listener, max 15 characters. This name will be used as the Virtual Computer Object (VCO).")] String Name; [Write, Description("If the availability group listener should be present or absent. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Key, Description("The name of the availability group to which the availability group listener is or will be connected.")] String AvailabilityGroup; diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.psm1 b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 similarity index 94% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.psm1 rename to DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 index 1aba2bbf2..e08ee08ed 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.psm1 +++ b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -12,10 +12,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. #> function Get-TargetResource @@ -34,15 +34,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName + $InstanceName ) # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Is this node actively hosting the SQL instance? $isActiveNode = Test-ActiveNode -ServerObject $serverObject @@ -68,10 +68,10 @@ function Get-TargetResource IsActiveNode = $isActiveNode ReadOnlyRoutingConnectionUrl = '' ReadOnlyRoutingList = @() - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName EndpointPort = $endpointPort - SQLServerNetName = $serverObject.NetName + EndpointHostName = $serverObject.NetName } # Get the availability group @@ -114,16 +114,16 @@ function Get-TargetResource .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. - .PARAMETER PrimaryReplicaSQLServer + .PARAMETER PrimaryReplicaServerName Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it. - .PARAMETER PrimaryReplicaSQLInstanceName + .PARAMETER PrimaryReplicaInstanceName Name of the SQL instance where the primary replica lives. .PARAMETER Ensure @@ -172,19 +172,19 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [String] - $PrimaryReplicaSQLServer, + $PrimaryReplicaServerName, [Parameter()] [String] - $PrimaryReplicaSQLInstanceName, + $PrimaryReplicaInstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -236,12 +236,12 @@ function Set-TargetResource Import-SQLPSModule # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Determine if HADR is enabled on the instance. If not, throw an error if ( -not $serverObject.IsHadrEnabled ) { - throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $SQLInstanceName -ErrorCategory NotImplemented + throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $InstanceName -ErrorCategory NotImplemented } # Get the Availability Group if it exists @@ -288,7 +288,7 @@ function Set-TargetResource $endpoint = $serverObject.Endpoints | Where-Object { $_.EndpointType -eq 'DatabaseMirroring' } if ( -not $endpoint ) { - throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $SQLServer, $SQLInstanceName -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $ServerName, $InstanceName -ErrorCategory ObjectNotFound } # If a hostname for the endpoint was not specified, define it now. @@ -377,13 +377,13 @@ function Set-TargetResource } else { - throw New-TerminatingError -ErrorType ReplicaNotFound -FormatArgs $Name, $SQLInstanceName -ErrorCategory ResourceUnavailable + throw New-TerminatingError -ErrorType ReplicaNotFound -FormatArgs $Name, $InstanceName -ErrorCategory ResourceUnavailable } } else { # Connect to the instance that is supposed to house the primary replica - $primaryReplicaServerObject = Connect-SQL -SQLServer $PrimaryReplicaSQLServer -SQLInstanceName $PrimaryReplicaSQLInstanceName + $primaryReplicaServerObject = Connect-SQL -SQLServer $PrimaryReplicaServerName -SQLInstanceName $PrimaryReplicaInstanceName # Verify the Availability Group exists on the supplied primary replica $primaryReplicaAvailabilityGroup = $primaryReplicaServerObject.AvailabilityGroups[$AvailabilityGroupName] @@ -437,7 +437,7 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $Name, $SQLInstanceName -ErrorCategory OperationStopped -InnerException $_.Exception + throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception } # Join the Availability Group Replica to the Availability Group @@ -453,7 +453,7 @@ function Set-TargetResource # The Availability Group doesn't exist on the primary replica else { - throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs $AvailabilityGroupName, $PrimaryReplicaSQLInstanceName -ErrorCategory ResourceUnavailable + throw New-TerminatingError -ErrorType AvailabilityGroupNotFound -FormatArgs $AvailabilityGroupName, $PrimaryReplicaInstanceName -ErrorCategory ResourceUnavailable } } } @@ -470,16 +470,16 @@ function Set-TargetResource .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. - .PARAMETER PrimaryReplicaSQLServer + .PARAMETER PrimaryReplicaServerName Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it. - .PARAMETER PrimaryReplicaSQLInstanceName + .PARAMETER PrimaryReplicaInstanceName Name of the SQL instance where the primary replica lives. .PARAMETER Ensure @@ -528,19 +528,19 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [String] - $PrimaryReplicaSQLServer, + $PrimaryReplicaServerName, [Parameter()] [String] - $PrimaryReplicaSQLInstanceName, + $PrimaryReplicaInstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -590,8 +590,8 @@ function Test-TargetResource ) $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName Name = $Name AvailabilityGroupName = $AvailabilityGroupName } @@ -608,7 +608,7 @@ function Test-TargetResource if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { # Use localization if the resource has been converted - New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $result } @@ -631,8 +631,8 @@ function Test-TargetResource $parametersToCheck = @( 'Name', 'AvailabilityGroupName', - 'SQLServer', - 'SQLInstanceName', + 'ServerName', + 'InstanceName', 'Ensure', 'AvailabilityMode', 'BackupPriority', @@ -672,7 +672,7 @@ function Test-TargetResource if ( -not $EndpointHostName ) { - $EndpointHostName = $getTargetResourceResult.SQLServerNetName + $EndpointHostName = $getTargetResourceResult.EndpointHostName } # Verify the hostname in the endpoint URL is correct diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.schema.mof b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof similarity index 86% rename from DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.schema.mof rename to DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof index d6aba9b0b..43d1a02b9 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.schema.mof +++ b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof @@ -1,12 +1,12 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAlwaysOnAvailabilityGroupReplica")] -class MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlAGReplica")] +class MSFT_SqlAGReplica : OMI_BaseResource { - [Key, Description("The name of the availability group replica. For named instances this must be in the following format SQLServer\\InstanceName.")] String Name; + [Key, Description("The name of the availability group replica. For named instances this must be in the following format ServerName\\InstanceName.")] String Name; [Key, Description("The name of the availability group.")] String AvailabilityGroupName; - [Required, Description("Hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; - [Write, Description("Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it.")] String PrimaryReplicaSQLServer; - [Write, Description("Name of the SQL instance where the primary replica lives.")] String PrimaryReplicaSQLInstanceName; + [Required, Description("Hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; + [Write, Description("Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it.")] String PrimaryReplicaServerName; + [Write, Description("Name of the SQL instance where the primary replica lives.")] String PrimaryReplicaInstanceName; [Write, Description("Specifies if the availability group replica should be present or absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Specifies the replica availability mode. Default is 'AsynchronousCommit'."), ValueMap{"AsynchronousCommit","SynchronousCommit"}, Values{"AsynchronousCommit","SynchronousCommit"}] String AvailabilityMode; [Write, Description("Specifies the desired priority of the replicas in performing backups. The acceptable values for this parameter are: integers from 0 through 100. Of the set of replicas which are online and available, the replica that has the highest priority performs the backup. Default is 50.")] UInt32 BackupPriority; @@ -19,6 +19,5 @@ class MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica : OMI_BaseResource [Write, Description("Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.")] Boolean ProcessOnlyOnActiveNode; [Read, Description("Output the network port the endpoint is listening on. Used by Get-TargetResource.")] Uint16 EndpointPort; [Read, Description("Output the endpoint URL of the Availability Group Replica. Used by Get-TargetResource.")] String EndpointUrl; - [Read, Description("Output the NetName property from the SQL Server object. Used by Get-TargetResource.")] String SqlServerNetName; [Read, Description("Determines if the current node is actively hosting the SQL Server instance.")] Boolean IsActiveNode; }; diff --git a/DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.psm1 b/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 similarity index 99% rename from DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.psm1 rename to DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 index 4f7aac8f4..dd4f15bc5 100644 --- a/DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.psm1 +++ b/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 @@ -1,4 +1,4 @@ -Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -ChildPath 'xSQLServerHelper.psm1') -Force +Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -ChildPath 'SqlServerDscHelper.psm1') -Force function Get-TargetResource { diff --git a/DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.schema.mof b/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof similarity index 90% rename from DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.schema.mof rename to DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof index 241daec8e..2878dc822 100644 --- a/DSCResources/MSFT_xSQLServerAlias/MSFT_xSQLServerAlias.schema.mof +++ b/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAlias")] -class MSFT_xSQLServerAlias : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlAlias")] +class MSFT_SqlAlias : OMI_BaseResource { [Key, Description("The name of Alias (e.g. svr01\\inst01).")] String Name; [Write, Description("Protocol to use when connecting. Valid values are 'TCP' or 'NP' (Named Pipes). Default value is 'TCP'."), ValueMap{"TCP","NP"}, Values{"TCP","NP"}] String Protocol; diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.psm1 b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 similarity index 83% rename from DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.psm1 rename to DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 index 1e1b509de..054c1a7fd 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.psm1 +++ b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -14,10 +14,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare *** Not used in this function *** - .PARAMETER SQLServer + .PARAMETER ServerName The hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Get-TargetResource @@ -33,14 +33,14 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName + $InstanceName ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $isAlwaysOnEnabled = [System.Boolean] $sqlServerObject.IsHadrEnabled if ($isAlwaysOnEnabled -eq $true) @@ -52,7 +52,7 @@ function Get-TargetResource $statusString = 'disabled' } - New-VerboseMessage -Message ( 'SQL Always On is {0} on "{1}\{2}".' -f $statusString, $SQLServer, $SQLInstanceName ) + New-VerboseMessage -Message ( 'SQL Always On is {0} on "{1}\{2}".' -f $statusString, $ServerName, $InstanceName ) return @{ IsHadrEnabled = $isAlwaysOnEnabled @@ -68,10 +68,10 @@ function Get-TargetResource availability and disaster recovery (HADR) property enabled ('Present') or disabled ('Absent'). - .PARAMETER SQLServer + .PARAMETER ServerName The hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER RestartTimeout @@ -89,11 +89,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.Uint32] @@ -101,13 +101,13 @@ function Set-TargetResource ) # Build the instance name to allow the Enable/Disable-Always On to connect to the instance - if ($SQLInstanceName -eq "MSSQLSERVER") + if ($InstanceName -eq "MSSQLSERVER") { - $serverInstance = $SQLServer + $serverInstance = $ServerName } else { - $serverInstance = "$SQLServer\$SQLInstanceName" + $serverInstance = "$ServerName\$InstanceName" } Import-SQLPSModule @@ -128,10 +128,10 @@ function Set-TargetResource } } - New-VerboseMessage -Message ( 'SQL Always On has been {0} on "{1}\{2}". Restarting the service.' -f @{Absent = 'disabled'; Present = 'enabled'}[$Ensure], $SQLServer, $SQLInstanceName ) + New-VerboseMessage -Message ( 'SQL Always On has been {0} on "{1}\{2}". Restarting the service.' -f @{Absent = 'disabled'; Present = 'enabled'}[$Ensure], $ServerName, $InstanceName ) # Now restart the SQL service so that all dependent services are also returned to their previous state - Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -Timeout $RestartTimeout + Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout # Verify always on was set if ( -not ( Test-TargetResource @PSBoundParameters ) ) @@ -150,10 +150,10 @@ function Set-TargetResource availability and disaster recovery (HADR) property enabled ('Present') or disabled ('Absent'). - .PARAMETER SQLServer + .PARAMETER ServerName The hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER RestartTimeout @@ -174,11 +174,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.Uint32] @@ -187,9 +187,9 @@ function Test-TargetResource # Determine the current state of Always On $getTargetResourceParameters = @{ - Ensure = $Ensure - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + Ensure = $Ensure + ServerName = $ServerName + InstanceName = $InstanceName } $state = Get-TargetResource @getTargetResourceParameters @@ -200,7 +200,7 @@ function Test-TargetResource # Determine whether the value matches the desired state $desiredStateMet = $state.IsHadrEnabled -eq $hadrDesiredState - New-VerboseMessage -Message ( 'SQL Always On is in the desired state for "{0}\{1}": {2}.' -f $SQLServer, $SQLInstanceName, $desiredStateMet ) + New-VerboseMessage -Message ( 'SQL Always On is in the desired state for "{0}\{1}": {2}.' -f $ServerName, $InstanceName, $desiredStateMet ) return $desiredStateMet } diff --git a/DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.schema.mof b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof similarity index 77% rename from DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.schema.mof rename to DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof index 6c46028ee..9eb0dec2e 100644 --- a/DSCResources/MSFT_xSQLServerAlwaysOnService/MSFT_xSQLServerAlwaysOnService.schema.mof +++ b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerAlwaysOnService")] -class MSFT_xSQLServerAlwaysOnService : OMI_BaseResource -{ - [Required, Description("An enumerated value that describes if the SQL Server should have Always On high availability and disaster recovery (HADR) property enabled ('Present') or disabled ('Absent')."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Key, Description("The hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; - [Write, Description("The length of time, in seconds, to wait for the service to restart. Default is 120 seconds.")] Uint32 RestartTimeout; - [Read, Description("Returns the status of AlwaysOn high availability and disaster recovery (HADR).")] Boolean IsHadrEnabled; -}; +[ClassVersion("1.0.0.0"), FriendlyName("SqlAlwaysOnService")] +class MSFT_SqlAlwaysOnService : OMI_BaseResource +{ + [Required, Description("An enumerated value that describes if the SQL Server should have Always On high availability and disaster recovery (HADR) property enabled ('Present') or disabled ('Absent')."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Key, Description("The hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; + [Write, Description("The length of time, in seconds, to wait for the service to restart. Default is 120 seconds.")] Uint32 RestartTimeout; + [Read, Description("Returns the status of AlwaysOn high availability and disaster recovery (HADR).")] Boolean IsHadrEnabled; +}; diff --git a/DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.psm1 b/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 similarity index 88% rename from DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.psm1 rename to DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 index c57be31e7..5e48b7448 100644 --- a/DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.psm1 +++ b/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -12,10 +12,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name The name of database to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation @@ -43,12 +43,12 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] @@ -56,7 +56,7 @@ function Get-TargetResource $Collation ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -79,11 +79,11 @@ function Get-TargetResource } $returnValue = @{ - Name = $Name - Ensure = $Ensure - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Collation = $sqlDatabaseCollation + Name = $Name + Ensure = $Ensure + ServerName = $ServerName + InstanceName = $InstanceName + Collation = $sqlDatabaseCollation } $returnValue @@ -100,10 +100,10 @@ function Get-TargetResource .PARAMETER Name The name of database to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation @@ -129,12 +129,12 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] @@ -142,7 +142,7 @@ function Set-TargetResource $Collation ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -156,7 +156,7 @@ function Set-TargetResource elseif ($Collation -notin $sqlServerObject.EnumCollations().Name) { throw New-TerminatingError -ErrorType InvalidCollationError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Collation) ` + -FormatArgs @($ServerName, $InstanceName, $Name, $Collation) ` -ErrorCategory InvalidOperation } @@ -174,7 +174,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType UpdateDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name) ` + -FormatArgs @($ServerName, $InstanceName, $Name) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -195,7 +195,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType CreateDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name) ` + -FormatArgs @($ServerName, $InstanceName, $Name) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -216,7 +216,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType DropDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name) ` + -FormatArgs @($ServerName, $InstanceName, $Name) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -235,10 +235,10 @@ function Set-TargetResource .PARAMETER Name The name of database to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation @@ -265,12 +265,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] diff --git a/DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.schema.mof b/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof similarity index 77% rename from DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.schema.mof rename to DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof index 67b6e6f29..1164ca056 100644 --- a/DSCResources/MSFT_xSQLServerDatabase/MSFT_xSQLServerDatabase.schema.mof +++ b/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerDatabase")] -class MSFT_xSQLServerDatabase : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabase")] +class MSFT_SqlDatabase : OMI_BaseResource { [Key, Description("The name of the SQL database.")] String Name; [Write, Description("An enumerated value that describes if the database is added (Present) or dropped (Absent). Valid values are 'Present' or 'Absent'. Default Value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Write, Description("The name of the SQL collation to use for the new database. Defaults to server collation.")] String Collation; }; diff --git a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.psm1 b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 similarity index 85% rename from DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.psm1 rename to DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 index 1327685ca..c623091c8 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.psm1 +++ b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 @@ -1,20 +1,20 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath 'CommonResourceHelper.psm1') + -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerDatabaseDefaultLocation' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseDefaultLocation' <# .SYNOPSIS Returns the current path to the the desired default location for the Data, Log, or Backup files. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Type @@ -33,12 +33,12 @@ Function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('Data', 'Log', 'Backup')] @@ -51,10 +51,10 @@ Function Get-TargetResource $Path ) - Write-Verbose -Message ($script:localizedData.GetCurrentPath -f $Type, $SQLInstanceName) + Write-Verbose -Message ($script:localizedData.GetCurrentPath -f $Type, $InstanceName) # Connect to the instance - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Is this node actively hosting the SQL instance? $isActiveNode = Test-ActiveNode -ServerObject $sqlServerObject @@ -79,11 +79,11 @@ Function Get-TargetResource } return @{ - SqlInstanceName = $SQLInstanceName - SqlServer = $SQLServer - Type = $Type - Path = $currentPath - IsActiveNode = $isActiveNode + InstanceName = $InstanceName + ServerName = $ServerName + Type = $Type + Path = $currentPath + IsActiveNode = $isActiveNode } } @@ -91,10 +91,10 @@ Function Get-TargetResource .SYNOPSIS This function sets the current path for the default SQL Instance location for the Data, Log, or Backups files. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Type @@ -119,12 +119,12 @@ Function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('Data', 'Log', 'Backup')] @@ -153,7 +153,7 @@ Function Set-TargetResource else { Write-Verbose -Message ($script:localizedData.SettingDefaultPath -f $Type) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Check which default location is being updated switch ($Type) @@ -187,8 +187,8 @@ Function Set-TargetResource if ($RestartService) { - Write-Verbose -Message ($script:localizedData.RestartSqlServer -f $SqlServer, $SQLInstanceName) - Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + Write-Verbose -Message ($script:localizedData.RestartSqlServer -f $ServerName, $InstanceName) + Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName } } catch @@ -207,10 +207,10 @@ Function Set-TargetResource .SYNOPSIS This function tests the current path to the default database location for the Data, Log, or Backups files. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Type @@ -235,12 +235,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('Data', 'Log', 'Backup')] @@ -264,10 +264,10 @@ function Test-TargetResource Write-Verbose -Message ($script:localizedData.TestingCurrentPath -f $Type) $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer - Type = $Type - Path = $Path + InstanceName = $InstanceName + ServerName = $ServerName + Type = $Type + Path = $Path } $isDefaultPathInDesiredState = $true @@ -279,7 +279,7 @@ function Test-TargetResource #> if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { - Write-Verbose -Message ($script:localizedData.NotActiveClusterNode -f $env:COMPUTERNAME,$SQLInstanceName ) + Write-Verbose -Message ($script:localizedData.NotActiveClusterNode -f $env:COMPUTERNAME, $InstanceName ) } elseif ($getTargetResourceResult.Path -ne $Path) { diff --git a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.schema.mof b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof similarity index 82% rename from DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.schema.mof rename to DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof index 5d78b6822..f49a2d941 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/MSFT_xSQLServerDatabaseDefaultLocation.schema.mof +++ b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerDatabaseDefaultLocation")] -class MSFT_xSQLServerDatabaseDefaultLocation : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabaseDefaultLocation")] +class MSFT_SqlDatabaseDefaultLocation : OMI_BaseResource { - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Key, Description("The type of database default location to be configured. { Data | Log | Backup }"), ValueMap{"Data","Log","Backup"}, Values{"Data","Log","Backup"}] String Type; [Required, Description("The path to the default directory to be configured.")] String Path; [Write, Description("If set to $true then SQL Server and dependent services will be restarted if a change to the default location is made. The defaul value is $false.")] Boolean RestartService; diff --git a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/en-US/MSFT_xSQLServerDatabaseDefaultLocation.strings.psd1 b/DSCResources/MSFT_SqlDatabaseDefaultLocation/en-US/MSFT_SqlDatabaseDefaultLocation.strings.psd1 similarity index 91% rename from DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/en-US/MSFT_xSQLServerDatabaseDefaultLocation.strings.psd1 rename to DSCResources/MSFT_SqlDatabaseDefaultLocation/en-US/MSFT_SqlDatabaseDefaultLocation.strings.psd1 index ac3fdf9ce..ee9cf93cd 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseDefaultLocation/en-US/MSFT_xSQLServerDatabaseDefaultLocation.strings.psd1 +++ b/DSCResources/MSFT_SqlDatabaseDefaultLocation/en-US/MSFT_SqlDatabaseDefaultLocation.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for MSFT_xSQLServerDatabaseDefaultLocation +# Localized resources for MSFT_SqlDatabaseDefaultLocation ConvertFrom-StringData @' GetCurrentPath = Getting default path for '{0}' for instance '{1}'. diff --git a/DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.psm1 b/DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.psm1 similarity index 79% rename from DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.psm1 rename to DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.psm1 index 271e4a836..fd0c03a1d 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.psm1 +++ b/DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -11,10 +11,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name The name of the login that will become a owner of the desired sql database. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Get-TargetResource @@ -36,16 +36,16 @@ function Get-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) Write-Verbose -Message "Getting owner of database $Database" - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -53,7 +53,7 @@ function Get-TargetResource if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) ) { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Database, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } @@ -65,16 +65,16 @@ function Get-TargetResource catch { throw New-TerminatingError -ErrorType FailedToGetOwnerDatabase ` - -FormatArgs @($Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidOperation } } $returnValue = @{ - Database = $Database - Name = $sqlDatabaseOwner - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + Database = $Database + Name = $sqlDatabaseOwner + ServerName = $ServerName + InstanceName = $InstanceName } $returnValue @@ -90,10 +90,10 @@ function Get-TargetResource .PARAMETER Name The name of the login that will become a owner of the desired sql database. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Set-TargetResource @@ -114,29 +114,29 @@ function Set-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) Write-Verbose -Message "Setting owner $Name of database $Database" - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { # Check database exists if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) ) { - throw New-TerminatingError -ErrorType NoDatabase -FormatArgs @($Database, $SQLServer, $SQLInstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType NoDatabase -FormatArgs @($Database, $ServerName, $InstanceName) -ErrorCategory ObjectNotFound } # Check login exists if ( -not ($sqlServerObject.Logins[$Name]) ) { - throw New-TerminatingError -ErrorType LoginNotFound -FormatArgs @($Name, $SQLServer, $SQLInstanceName) -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType LoginNotFound -FormatArgs @($Name, $ServerName, $InstanceName) -ErrorCategory ObjectNotFound } try @@ -147,7 +147,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType FailedToSetOwnerDatabase ` - -FormatArgs @($Name, $Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -164,10 +164,10 @@ function Set-TargetResource .PARAMETER Name The name of the login that will become a owner of the desired sql database. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Test-TargetResource @@ -189,12 +189,12 @@ function Test-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) Write-Verbose -Message "Testing owner $Name of database $Database" diff --git a/DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.schema.mof b/DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.schema.mof similarity index 64% rename from DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.schema.mof rename to DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.schema.mof index 552d22629..c488b2e42 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseOwner/MSFT_xSQLServerDatabaseOwner.schema.mof +++ b/DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerDatabaseOwner")] -class MSFT_xSQLServerDatabaseOwner : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabaseOwner")] +class MSFT_SqlDatabaseOwner : OMI_BaseResource { [Key, Description("The name of database to be configured.")] String Database; [Required, Description("The name of the login that will become a owner of the desired sql database.")] String Name; - [Write, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Write, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Write, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Write, Description("The name of the SQL instance to be configured.")] String InstanceName; }; diff --git a/DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.psm1 b/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 similarity index 89% rename from DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.psm1 rename to DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 index 684fe53ef..3cbb9981a 100644 --- a/DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.psm1 +++ b/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -17,10 +17,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Permissions This is a list that represents a SQL Server set of database permissions - .PARAMETER SQLServer + .PARAMETER ServerName This is the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is the SQL instance for the database #> function Get-TargetResource @@ -52,15 +52,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName + $InstanceName ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -96,7 +96,7 @@ function Get-TargetResource catch { throw New-TerminatingError -ErrorType FailedToEnumDatabasePermissions ` - -FormatArgs @($Name, $Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -105,7 +105,7 @@ function Get-TargetResource else { throw New-TerminatingError -ErrorType LoginNotFound ` - -FormatArgs @($Name, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound ` -InnerException $_.Exception } @@ -113,7 +113,7 @@ function Get-TargetResource else { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidResult ` -InnerException $_.Exception } @@ -135,8 +135,8 @@ function Get-TargetResource Name = $Name PermissionState = $PermissionState Permissions = $getSqlDatabasePermissionResult - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } $returnValue @@ -161,10 +161,10 @@ function Get-TargetResource .PARAMETER Permissions This is a list that represents a SQL Server set of database permissions - .PARAMETER SQLServer + .PARAMETER ServerName This is the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is the SQL instance for the database #> function Set-TargetResource @@ -200,15 +200,15 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -230,7 +230,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType AddLoginDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Database) ` + -FormatArgs @($ServerName, $InstanceName, $Name, $Database) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -252,7 +252,7 @@ function Set-TargetResource 'Present' { New-VerboseMessage -Message ('{0} the permissions ''{1}'' to the database {2} on the server {3}\{4}' ` - -f $PermissionState, ($Permissions -join ','), $Database, $SQLServer, $SQLInstanceName) + -f $PermissionState, ($Permissions -join ','), $Database, $ServerName, $InstanceName) switch ($PermissionState) { @@ -276,7 +276,7 @@ function Set-TargetResource 'Absent' { New-VerboseMessage -Message ('Revoking {0} permissions {1} to the database {2} on the server {3}\{4}' ` - -f $PermissionState, ($Permissions -join ','), $Database, $SQLServer, $SQLInstanceName) + -f $PermissionState, ($Permissions -join ','), $Database, $ServerName, $InstanceName) if ($PermissionState -eq 'GrantWithGrant') { @@ -292,7 +292,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType FailedToSetPermissionDatabase ` - -FormatArgs @($Name, $Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -301,7 +301,7 @@ function Set-TargetResource else { throw New-TerminatingError -ErrorType LoginNotFound ` - -FormatArgs @($Name, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound ` -InnerException $_.Exception } @@ -309,7 +309,7 @@ function Set-TargetResource else { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Database, $ServerName, $InstanceName) ` -ErrorCategory InvalidResult ` -InnerException $_.Exception } @@ -335,10 +335,10 @@ function Set-TargetResource .PARAMETER Permissions This is a list that represents a SQL Server set of database permissions - .PARAMETER SQLServer + .PARAMETER ServerName This is the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is the SQL instance for the database #> function Test-TargetResource @@ -375,18 +375,18 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) Write-Verbose -Message "Testing permissions for user $Name in database $Database." $getTargetResourceParameters = @{ - SQLInstanceName = $PSBoundParameters.SQLInstanceName - SQLServer = $PSBoundParameters.SQLServer + InstanceName = $PSBoundParameters.InstanceName + ServerName = $PSBoundParameters.ServerName Database = $PSBoundParameters.Database Name = $PSBoundParameters.Name PermissionState = $PSBoundParameters.PermissionState diff --git a/DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.schema.mof b/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof similarity index 80% rename from DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.schema.mof rename to DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof index 01c4b8cb8..8b4fe7c04 100644 --- a/DSCResources/MSFT_xSQLServerDatabasePermission/MSFT_xSQLServerDatabasePermission.schema.mof +++ b/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof @@ -1,11 +1,11 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerDatabasePermission")] -class MSFT_xSQLServerDatabasePermission : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabasePermission")] +class MSFT_SqlDatabasePermission : OMI_BaseResource { [Write, Description("If the values should be present or absent. Valid values are 'Present' or 'Absent'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Key, Description("The name of the database.")] String Database; [Key, Description("The name of the user that should be granted or denied the permission.")] String Name; [Key, Description("The state of the permission. Valid values are 'Grant' or 'Deny'."), ValueMap{"Grant","Deny","GrantWithGrant"}, Values{"Grant","Deny","GrantWithGrant"}] String PermissionState; [Required, Description("The set of permissions for the SQL database.")] String Permissions[]; - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; }; diff --git a/DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.psm1 b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 similarity index 84% rename from DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.psm1 rename to DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 index 74f084cef..651504f47 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.psm1 +++ b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -11,10 +11,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER RecoveryModel This is the RecoveryModel of the SQL database - .PARAMETER SQLServer + .PARAMETER ServerName This is a the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is a the SQL instance for the database #> function Get-TargetResource @@ -32,12 +32,12 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -45,7 +45,7 @@ function Get-TargetResource $Name ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -60,16 +60,16 @@ function Get-TargetResource else { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Name, $sqlServer, $sqlInstanceName) ` + -FormatArgs @($Name, $ServerName, $InstanceName) ` -ErrorCategory InvalidResult } } $returnValue = @{ - Name = $Name - RecoveryModel = $sqlDatabaseRecoveryModel - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + Name = $Name + RecoveryModel = $sqlDatabaseRecoveryModel + ServerName = $ServerName + InstanceName = $InstanceName } $returnValue @@ -85,10 +85,10 @@ function Get-TargetResource .PARAMETER RecoveryModel This is the RecoveryModel of the SQL database - .PARAMETER SQLServer + .PARAMETER ServerName This is a the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is a the SQL instance for the database #> function Set-TargetResource @@ -105,12 +105,12 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -118,7 +118,7 @@ function Set-TargetResource $Name ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -137,7 +137,7 @@ function Set-TargetResource else { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Name, $sqlServer, $sqlInstanceName) ` + -FormatArgs @($Name, $ServerName, $InstanceName) ` -ErrorCategory InvalidResult } } @@ -153,10 +153,10 @@ function Set-TargetResource .PARAMETER RecoveryModel This is the RecoveryModel of the SQL database - .PARAMETER SQLServer + .PARAMETER ServerName This is a the SQL Server for the database - .PARAMETER SQLInstanceName + .PARAMETER InstanceName This is a the SQL instance for the database #> function Test-TargetResource @@ -174,12 +174,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.schema.mof b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof similarity index 65% rename from DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.schema.mof rename to DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof index 0ffb09a92..8e5225522 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseRecoveryModel/MSFT_xSQLServerDatabaseRecoveryModel.schema.mof +++ b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0"), FriendlyName("xSQLServerDatabaseRecoveryModel")] -class MSFT_xSQLServerDatabaseRecoveryModel : OMI_BaseResource +[ClassVersion("1.0"), FriendlyName("SqlDatabaseRecoveryModel")] +class MSFT_SqlDatabaseRecoveryModel : OMI_BaseResource { [Key, Description("The SQL database name")] String Name; [Required, Description("The recovery model to use for the database."), ValueMap{"Full","Simple","BulkLogged"}, Values{"Full","Simple","BulkLogged"}] String RecoveryModel; - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; }; diff --git a/DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.psm1 b/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 similarity index 85% rename from DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.psm1 rename to DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 index 61f7f3f6b..d762dec66 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.psm1 +++ b/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -12,10 +12,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name Specifies the name of the login that evaluated if it is member of the role(s). - .PARAMETER SQLServer + .PARAMETER ServerName Specifies the SQL server on which the instance exist. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Specifies the SQL instance in which the database exist. .PARAMETER Database @@ -38,12 +38,12 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -58,7 +58,7 @@ function Get-TargetResource Write-Verbose -Message "Getting SQL Database role for $Name" - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -66,7 +66,7 @@ function Get-TargetResource if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) ) { throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Database, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } @@ -76,7 +76,7 @@ function Get-TargetResource if ( -not ($sqlDatabaseObject.Roles[$currentRole]) ) { throw New-TerminatingError -ErrorType RoleNotFound ` - -FormatArgs @($currentRole, $Database, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($currentRole, $Database, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } } @@ -85,7 +85,7 @@ function Get-TargetResource if ( -not ($sqlServerObject.Logins[$Name]) ) { throw New-TerminatingError -ErrorType LoginNotFound ` - -FormatArgs @($Name, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($Name, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } @@ -99,14 +99,14 @@ function Get-TargetResource if ($sqlDatabaseUser.IsMember($currentRole)) { New-VerboseMessage -Message ("The login '$Name' is a member of the role '$currentRole' on the " + ` - "database '$Database', on the instance $SQLServer\$SQLInstanceName") + "database '$Database', on the instance $ServerName\$InstanceName") $grantedRole += $currentRole } else { New-VerboseMessage -Message ("The login '$Name' is not a member of the role '$currentRole' on the " + ` - "database '$Database', on the instance $SQLServer\$SQLInstanceName") + "database '$Database', on the instance $ServerName\$InstanceName") } } @@ -118,17 +118,17 @@ function Get-TargetResource else { New-VerboseMessage -Message ("The login '$Name' is not a user of the database " + ` - "'$Database' on the instance $SQLServer\$SQLInstanceName") + "'$Database' on the instance $ServerName\$InstanceName") } } $returnValue = @{ - Ensure = $ensure - Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Database = $Database - Role = $grantedRole + Ensure = $ensure + Name = $Name + ServerName = $ServerName + InstanceName = $InstanceName + Database = $Database + Role = $grantedRole } $returnValue @@ -147,10 +147,10 @@ function Get-TargetResource Specifies the name of the login that evaluated if it is member of the role(s), if it is not it will be added. If the login does not exist as a user, a user will be created using the login. - .PARAMETER SQLServer + .PARAMETER ServerName Specifies the SQL server on which the instance exist. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Specifies the SQL instance in which the database exist. .PARAMETER Database @@ -178,12 +178,12 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -198,7 +198,7 @@ function Set-TargetResource Write-Verbose -Message "Setting SQL Database role for $Name" - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -214,7 +214,7 @@ function Set-TargetResource try { New-VerboseMessage -Message ("Adding the login '$Name' as a user of the database " + ` - "'$Database', on the instance $SQLServer\$SQLInstanceName") + "'$Database', on the instance $ServerName\$InstanceName") $sqlDatabaseUser = New-Object -TypeName Microsoft.SqlServer.Management.Smo.User ` -ArgumentList $sqlDatabaseObject, $Name @@ -224,7 +224,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType AddLoginDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Database) ` + -FormatArgs @($ServerName, $InstanceName, $Name, $Database) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -236,7 +236,7 @@ function Set-TargetResource try { New-VerboseMessage -Message ("Adding the login '$Name' to the role '$currentRole' on the " + ` - "database '$Database', on the instance $SQLServer\$SQLInstanceName") + "database '$Database', on the instance $ServerName\$InstanceName") $sqlDatabaseRole = $sqlDatabaseObject.Roles[$currentRole] $sqlDatabaseRole.AddMember($Name) @@ -244,7 +244,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType AddMemberDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Role, $Database) ` + -FormatArgs @($ServerName, $InstanceName, $Name, $Role, $Database) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -258,7 +258,7 @@ function Set-TargetResource foreach ($currentRole in $Role) { New-VerboseMessage -Message ("Removing the login '$Name' to the role '$currentRole' on the " + ` - "database '$Database', on the instance $SQLServer\$SQLInstanceName") + "database '$Database', on the instance $ServerName\$InstanceName") $sqlDatabaseRole = $sqlDatabaseObject.Roles[$currentRole] $sqlDatabaseRole.DropMember($Name) @@ -267,7 +267,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType DropMemberDatabaseSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $Name, $Role, $Database) ` + -FormatArgs @($ServerName, $InstanceName, $Name, $Role, $Database) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -286,10 +286,10 @@ function Set-TargetResource .PARAMETER Name Specifies the name of the login that evaluated if it is member of the role(s). - .PARAMETER SQLServer + .PARAMETER ServerName Specifies the SQL server on which the instance exist. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Specifies the SQL instance in which the database exist. .PARAMETER Database @@ -318,12 +318,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -339,11 +339,11 @@ function Test-TargetResource Write-Verbose -Message "Testing SQL Database role for $Name" $getTargetResourceParameters = @{ - SQLInstanceName = $PSBoundParameters.SQLInstanceName - SQLServer = $PSBoundParameters.SQLServer - Role = $PSBoundParameters.Role - Database = $PSBoundParameters.Database - Name = $PSBoundParameters.Name + InstanceName = $PSBoundParameters.InstanceName + ServerName = $PSBoundParameters.ServerName + Role = $PSBoundParameters.Role + Database = $PSBoundParameters.Database + Name = $PSBoundParameters.Name } $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters diff --git a/DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.schema.mof b/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof similarity index 80% rename from DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.schema.mof rename to DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof index ef07952f9..85d405360 100644 --- a/DSCResources/MSFT_xSQLServerDatabaseRole/MSFT_xSQLServerDatabaseRole.schema.mof +++ b/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof @@ -1,10 +1,10 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerDatabaseRole")] -class MSFT_xSQLServerDatabaseRole : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabaseRole")] +class MSFT_SqlDatabaseRole : OMI_BaseResource { [Write, Description("If 'Present' (the default value) then the login (user) will be added to the role(s). If 'Absent' then the login (user) will be removed from the role(s)."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Key, Description("The name of the login that will become a member, or removed as a member, of the role(s).")] String Name; - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Key, Description("The database in which the login (user) and role(s) exist.")] String Database; [Required, Description("One or more roles to which the login (user) will be added or removed.")] String Role[]; }; diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 similarity index 86% rename from DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 rename to DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 index 10e37433e..3459bb1ea 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 +++ b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -9,10 +9,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName Name of the SQL Server Reporting Services instance to be configured. - .PARAMETER RSSQLServer + .PARAMETER DatabaseServerName Name of the SQL Server to host the Reporting Service database. - .PARAMETER RSSQLInstanceName + .PARAMETER DatabaseInstanceName Name of the SQL Server instance to host the Reporting Service database. #> function Get-TargetResource @@ -27,11 +27,11 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $RSSQLServer, + $DatabaseServerName, [Parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName + $DatabaseInstanceName ) $reportingServicesData = Get-ReportingServicesData -InstanceName $InstanceName @@ -40,13 +40,13 @@ function Get-TargetResource { if ( $reportingServicesData.Configuration.DatabaseServerName.Contains('\') ) { - $RSSQLServer = $reportingServicesData.Configuration.DatabaseServerName.Split('\')[0] - $RSSQLInstanceName = $reportingServicesData.Configuration.DatabaseServerName.Split('\')[1] + $DatabaseServerName = $reportingServicesData.Configuration.DatabaseServerName.Split('\')[0] + $DatabaseInstanceName = $reportingServicesData.Configuration.DatabaseServerName.Split('\')[1] } else { - $RSSQLServer = $reportingServicesData.Configuration.DatabaseServerName - $RSSQLInstanceName = 'MSSQLSERVER' + $DatabaseServerName = $reportingServicesData.Configuration.DatabaseServerName + $DatabaseInstanceName = 'MSSQLSERVER' } $isInitialized = $reportingServicesData.Configuration.IsInitialized @@ -90,8 +90,8 @@ function Get-TargetResource return @{ InstanceName = $InstanceName - RSSQLServer = $RSSQLServer - RSSQLInstanceName = $RSSQLInstanceName + DatabaseServerName = $DatabaseServerName + DatabaseInstanceName = $DatabaseInstanceName ReportServerVirtualDirectory = $reportServerVirtualDirectory ReportsVirtualDirectory = $reportsVirtualDirectory ReportServerReservedUrl = $reportServerReservedUrl @@ -107,10 +107,10 @@ function Get-TargetResource .PARAMETER InstanceName Name of the SQL Server Reporting Services instance to be configured. - .PARAMETER RSSQLServer + .PARAMETER DatabaseServerName Name of the SQL Server to host the Reporting Service database. - .PARAMETER RSSQLInstanceName + .PARAMETER DatabaseInstanceName Name of the SQL Server instance to host the Reporting Service database. .PARAMETER ReportServerVirtualDirectory @@ -136,11 +136,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $RSSQLServer, + $DatabaseServerName, [Parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName, + $DatabaseInstanceName, [Parameter()] [System.String] @@ -194,13 +194,13 @@ function Set-TargetResource $reportingServicesDatabaseName = "ReportServer`$$InstanceName" } - if ( $RSSQLInstanceName -eq 'MSSQLSERVER' ) + if ( $DatabaseInstanceName -eq 'MSSQLSERVER' ) { - $reportingServicesConnection = $RSSQLServer + $reportingServicesConnection = $DatabaseServerName } else { - $reportingServicesConnection = "$RSSQLServer\$RSSQLInstanceName" + $reportingServicesConnection = "$DatabaseServerName\$DatabaseInstanceName" } $wmiOperatingSystem = Get-WMIObject -Class Win32_OperatingSystem -Namespace 'root/cimv2' -ErrorAction SilentlyContinue @@ -213,7 +213,7 @@ function Set-TargetResource if ( -not $reportingServicesData.Configuration.IsInitialized ) { - New-VerboseMessage -Message "Initializing Reporting Services on $RSSQLServer\$RSSQLInstanceName." + New-VerboseMessage -Message "Initializing Reporting Services on $DatabaseServerName\$DatabaseInstanceName." # If no Report Server reserved URLs have been specified, use the default one. if ( $null -eq $ReportServerReservedUrl ) @@ -229,20 +229,20 @@ function Set-TargetResource if ( $reportingServicesData.Configuration.VirtualDirectoryReportServer -ne $ReportServerVirtualDirectory ) { - New-VerboseMessage -Message "Setting report server virtual directory on $RSSQLServer\$RSSQLInstanceName to $ReportServerVirtualDirectory." + New-VerboseMessage -Message "Setting report server virtual directory on $DatabaseServerName\$DatabaseInstanceName to $ReportServerVirtualDirectory." $null = $reportingServicesData.Configuration.SetVirtualDirectory('ReportServerWebService', $ReportServerVirtualDirectory, $language) $ReportServerReservedUrl | ForEach-Object -Process { - New-VerboseMessage -Message "Adding report server URL reservation on $RSSQLServer\$RSSQLInstanceName`: $_." + New-VerboseMessage -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." $null = $reportingServicesData.Configuration.ReserveURL('ReportServerWebService', $_, $language) } } if ( $reportingServicesData.Configuration.VirtualDirectoryReportManager -ne $ReportsVirtualDirectory ) { - New-VerboseMessage -Message "Setting reports virtual directory on $RSSQLServer\$RSSQLInstanceName to $ReportServerVirtualDirectory." + New-VerboseMessage -Message "Setting reports virtual directory on $DatabaseServerName\$DatabaseInstanceName to $ReportServerVirtualDirectory." $null = $reportingServicesData.Configuration.SetVirtualDirectory($reportingServicesData.ReportsApplicationName, $ReportsVirtualDirectory, $language) $ReportsReservedUrl | ForEach-Object -Process { - New-VerboseMessage -Message "Adding reports URL reservation on $RSSQLServer\$RSSQLInstanceName`: $_." + New-VerboseMessage -Message "Adding reports URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." $null = $reportingServicesData.Configuration.ReserveURL($reportingServicesData.ReportsApplicationName, $_, $language) } } @@ -251,8 +251,8 @@ function Set-TargetResource # Determine RS service account $reportingServicesServiceAccountUserName = (Get-WmiObject -Class Win32_Service | Where-Object -FilterScript { - $_.Name -eq $reportingServicesServiceName - }).StartName + $_.Name -eq $reportingServicesServiceName + }).StartName $reportingServicesDatabaseRightsScript = $reportingServicesData.Configuration.GenerateDatabaseRightsScript($reportingServicesServiceAccountUserName, $reportingServicesDatabaseName, $false, $true) <# @@ -272,9 +272,9 @@ function Set-TargetResource else { $getTargetResourceParameters = @{ - InstanceName = $InstanceName - RSSQLServer = $RSSQLServer - RSSQLInstanceName = $RSSQLInstanceName + InstanceName = $InstanceName + DatabaseServerName = $DatabaseServerName + DatabaseInstanceName = $DatabaseInstanceName } $currentConfig = Get-TargetResource @getTargetResourceParameters @@ -300,7 +300,7 @@ function Set-TargetResource if ( -not [string]::IsNullOrEmpty($ReportServerVirtualDirectory) -and ($ReportServerVirtualDirectory -ne $currentConfig.ReportServerVirtualDirectory) ) { - New-VerboseMessage -Message "Setting report server virtual directory on $RSSQLServer\$RSSQLInstanceName to $ReportServerVirtualDirectory." + New-VerboseMessage -Message "Setting report server virtual directory on $DatabaseServerName\$DatabaseInstanceName to $ReportServerVirtualDirectory." $currentConfig.ReportServerReservedUrl | ForEach-Object -Process { $null = $reportingServicesData.Configuration.RemoveURL('ReportServerWebService', $_, $language) @@ -315,7 +315,7 @@ function Set-TargetResource if ( -not [string]::IsNullOrEmpty($ReportsVirtualDirectory) -and ($ReportsVirtualDirectory -ne $currentConfig.ReportsVirtualDirectory) ) { - New-VerboseMessage -Message "Setting reports virtual directory on $RSSQLServer\$RSSQLInstanceName to $ReportServerVirtualDirectory." + New-VerboseMessage -Message "Setting reports virtual directory on $DatabaseServerName\$DatabaseInstanceName to $ReportServerVirtualDirectory." $currentConfig.ReportsReservedUrl | ForEach-Object -Process { $null = $reportingServicesData.Configuration.RemoveURL($reportingServicesData.ReportsApplicationName, $_, $language) @@ -340,7 +340,7 @@ function Set-TargetResource } $ReportServerReservedUrl | ForEach-Object -Process { - New-VerboseMessage -Message "Adding report server URL reservation on $RSSQLServer\$RSSQLInstanceName`: $_." + New-VerboseMessage -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." $null = $reportingServicesData.Configuration.ReserveURL('ReportServerWebService', $_, $language) } } @@ -357,7 +357,7 @@ function Set-TargetResource } $ReportsReservedUrl | ForEach-Object -Process { - New-VerboseMessage -Message "Adding reports URL reservation on $RSSQLServer\$RSSQLInstanceName`: $_." + New-VerboseMessage -Message "Adding reports URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." $null = $reportingServicesData.Configuration.ReserveURL($reportingServicesData.ReportsApplicationName, $_, $language) } } @@ -377,10 +377,10 @@ function Set-TargetResource .PARAMETER InstanceName Name of the SQL Server Reporting Services instance to be configured. - .PARAMETER RSSQLServer + .PARAMETER DatabaseServerName Name of the SQL Server to host the Reporting Service database. - .PARAMETER RSSQLInstanceName + .PARAMETER DatabaseInstanceName Name of the SQL Server instance to host the Reporting Service database. .PARAMETER ReportServerVirtualDirectory @@ -407,11 +407,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $RSSQLServer, + $DatabaseServerName, [Parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName, + $DatabaseInstanceName, [Parameter()] [System.String] @@ -433,28 +433,28 @@ function Test-TargetResource $result = $true $getTargetResourceParameters = @{ - InstanceName = $InstanceName - RSSQLServer = $RSSQLServer - RSSQLInstanceName = $RSSQLInstanceName + InstanceName = $InstanceName + DatabaseServerName = $DatabaseServerName + DatabaseInstanceName = $DatabaseInstanceName } $currentConfig = Get-TargetResource @getTargetResourceParameters if ( -not $currentConfig.IsInitialized ) { - New-VerboseMessage -Message "Reporting services $RSSQLServer\$RSSQLInstanceName are not initialized." + New-VerboseMessage -Message "Reporting services $DatabaseServerName\$DatabaseInstanceName are not initialized." $result = $false } if ( -not [string]::IsNullOrEmpty($ReportServerVirtualDirectory) -and ($ReportServerVirtualDirectory -ne $currentConfig.ReportServerVirtualDirectory) ) { - New-VerboseMessage -Message "Report server virtual directory on $RSSQLServer\$RSSQLInstanceName is $($currentConfig.ReportServerVirtualDir), should be $ReportServerVirtualDirectory." + New-VerboseMessage -Message "Report server virtual directory on $DatabaseServerName\$DatabaseInstanceName is $($currentConfig.ReportServerVirtualDir), should be $ReportServerVirtualDirectory." $result = $false } if ( -not [string]::IsNullOrEmpty($ReportsVirtualDirectory) -and ($ReportsVirtualDirectory -ne $currentConfig.ReportsVirtualDirectory) ) { - New-VerboseMessage -Message "Reports virtual directory on $RSSQLServer\$RSSQLInstanceName is $($currentConfig.ReportsVirtualDir), should be $ReportsVirtualDirectory." + New-VerboseMessage -Message "Reports virtual directory on $DatabaseServerName\$DatabaseInstanceName is $($currentConfig.ReportsVirtualDir), should be $ReportsVirtualDirectory." $result = $false } @@ -465,7 +465,7 @@ function Test-TargetResource if ( ($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) { - New-VerboseMessage -Message "Report server reserved URLs on $RSSQLServer\$RSSQLInstanceName are $($currentConfig.ReportServerReservedUrl -join ', '), should be $($ReportServerReservedUrl -join ', ')." + New-VerboseMessage -Message "Report server reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportServerReservedUrl -join ', '), should be $($ReportServerReservedUrl -join ', ')." $result = $false } @@ -476,7 +476,7 @@ function Test-TargetResource if ( ($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) { - New-VerboseMessage -Message "Reports reserved URLs on $RSSQLServer\$RSSQLInstanceName are $($currentConfig.ReportsReservedUrl -join ', ')), should be $($ReportsReservedUrl -join ', ')." + New-VerboseMessage -Message "Reports reserved URLs on $DatabaseServerName\$DatabaseInstanceName are $($currentConfig.ReportsReservedUrl -join ', ')), should be $($ReportsReservedUrl -join ', ')." $result = $false } diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof similarity index 80% rename from DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof rename to DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof index ff03fb317..7c72fd50a 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof +++ b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerRSConfig")] -class MSFT_xSQLServerRSConfig : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlRS")] +class MSFT_SqlRS : OMI_BaseResource { [Key, Description("Name of the SQL Server Reporting Services instance to be configured.")] String InstanceName; - [Required, Description("Name of the SQL Server to host the Reporting Service database.")] String RSSQLServer; - [Required, Description("Name of the SQL Server instance to host the Reporting Service database.")] String RSSQLInstanceName; + [Required, Description("Name of the SQL Server to host the Reporting Service database.")] String DatabaseServerName; + [Required, Description("Name of the SQL Server instance to host the Reporting Service database.")] String DatabaseInstanceName; [Write, Description("Report Server Web Service virtual directory. Optional.")] String ReportServerVirtualDirectory; [Write, Description("Report Manager/Report Web App virtual directory name. Optional.")] String ReportsVirtualDirectory; [Write, Description("Report Server URL reservations. Optional. If not specified, 'http://+:80' URL reservation will be used.")] String ReportServerReservedUrl[]; diff --git a/DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.psm1 b/DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.psm1 similarity index 97% rename from DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.psm1 rename to DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.psm1 index e6319223c..e20d298f3 100644 --- a/DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.psm1 +++ b/DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.psm1 @@ -2,7 +2,7 @@ $currentPath = Split-Path -Parent $MyInvocation.MyCommand.Path Write-Debug -Message "CurrentPath: $currentPath" # Load Common Code -Import-Module $currentPath\..\..\xSQLServerHelper.psm1 -Verbose:$false -ErrorAction Stop +Import-Module $currentPath\..\..\SqlServerDscHelper.psm1 -Verbose:$false -ErrorAction Stop function Get-TargetResource { diff --git a/DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.schema.mof b/DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.schema.mof similarity index 72% rename from DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.schema.mof rename to DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.schema.mof index 9539097ed..370766edf 100644 --- a/DSCResources/MSFT_xSQLServerRSSecureConnectionLevel/MSFT_xSQLServerRSSecureConnectionLevel.schema.mof +++ b/DSCResources/MSFT_SqlRSSecureConnectionLevel/MSFT_SqlRSSecureConnectionLevel.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerRSSecureConnectionLevel")] -class MSFT_xSQLServerRSSecureConnectionLevel : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlRSSecureConnectionLevel")] +class MSFT_SqlRSSecureConnectionLevel : OMI_BaseResource { [Key, Description("SQL instance to set secure connection level for.")] String InstanceName; [Key, Description("SQL Server Reporting Service secure connection level.")] Uint16 SecureConnectionLevel; diff --git a/DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.psm1 b/DSCResources/MSFT_SqlScript/MSFT_SqlScript.psm1 similarity index 99% rename from DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.psm1 rename to DSCResources/MSFT_SqlScript/MSFT_SqlScript.psm1 index bb31a336d..2b0cf0b70 100644 --- a/DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.psm1 +++ b/DSCResources/MSFT_SqlScript/MSFT_SqlScript.psm1 @@ -1,5 +1,5 @@ $script:currentPath = Split-Path -Path $MyInvocation.MyCommand.Path -Parent -Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $script:currentPath -Parent) -Parent) -ChildPath 'xSQLServerHelper.psm1') +Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $script:currentPath -Parent) -Parent) -ChildPath 'SqlServerDscHelper.psm1') <# .SYNOPSIS diff --git a/DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.schema.mof b/DSCResources/MSFT_SqlScript/MSFT_SqlScript.schema.mof similarity index 95% rename from DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.schema.mof rename to DSCResources/MSFT_SqlScript/MSFT_SqlScript.schema.mof index e827564e6..3627db5b2 100644 --- a/DSCResources/MSFT_xSQLServerScript/MSFT_xSQLServerScript.schema.mof +++ b/DSCResources/MSFT_SqlScript/MSFT_SqlScript.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerScript")] -class MSFT_xSQLServerScript : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlScript")] +class MSFT_SqlScript : OMI_BaseResource { [Key, Description("The name of an instance of the Database Engine. For a default instance, only specify the computer name. For a named instance, use the format ComputerName\\InstanceName")] String ServerInstance; [Key, Description("Path to the T-SQL file that will perform Set action.")] String SetFilePath; diff --git a/DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.psm1 b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 similarity index 85% rename from DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.psm1 rename to DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 index 1cb38ac73..a0dd9f081 100644 --- a/DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.psm1 +++ b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 @@ -1,15 +1,15 @@ # Load Common Code Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS Gets the current value of a SQL configuration option - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. Default is 'MSSQLSERVER' .PARAMETER OptionName @@ -33,11 +33,11 @@ function Get-TargetResource param( [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [String] @@ -56,7 +56,7 @@ function Get-TargetResource $RestartTimeout = 120 ) - $sql = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sql = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName ## get the configuration option $option = $sql.Configuration.Properties | Where-Object { $_.DisplayName -eq $OptionName } @@ -67,12 +67,12 @@ function Get-TargetResource } return @{ - SqlServer = $SQLServer - SQLInstanceName = $SQLInstanceName - OptionName = $option.DisplayName - OptionValue = $option.ConfigValue - RestartService = $RestartService - RestartTimeout = $RestartTimeout + ServerName = $ServerName + InstanceName = $InstanceName + OptionName = $option.DisplayName + OptionValue = $option.ConfigValue + RestartService = $RestartService + RestartTimeout = $RestartTimeout } } @@ -80,10 +80,10 @@ function Get-TargetResource .SYNOPSIS Sets the value of a SQL configuration option - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. Default is 'MSSQLSERVER' .PARAMETER OptionName @@ -104,11 +104,11 @@ function Set-TargetResource param( [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [String] @@ -127,7 +127,7 @@ function Set-TargetResource $RestartTimeout = 120 ) - $sql = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sql = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName ## get the configuration option $option = $sql.Configuration.Properties | Where-Object { $_.DisplayName -eq $OptionName } @@ -147,7 +147,7 @@ function Set-TargetResource elseif (($option.IsDynamic -eq $false) -and ($RestartService -eq $true)) { New-VerboseMessage -Message 'Configuration option has been updated, restarting instance...' - Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -Timeout $RestartTimeout + Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout } else { @@ -159,10 +159,10 @@ function Set-TargetResource .SYNOPSIS Determines whether a SQL configuration option value is properly set - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. Default is 'MSSQLSERVER' .PARAMETER OptionName @@ -186,11 +186,11 @@ function Test-TargetResource param( [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [String] diff --git a/DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.schema.mof b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof similarity index 77% rename from DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.schema.mof rename to DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof index e90976a76..d334e283f 100644 --- a/DSCResources/MSFT_xSQLServerConfiguration/MSFT_xSQLServerConfiguration.schema.mof +++ b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerConfiguration")] -class MSFT_xSQLServerConfiguration : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerConfiguration")] +class MSFT_SqlServerConfiguration : OMI_BaseResource { - [Key, Description("The hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; [Key, Description("The name of the SQL configuration option to be checked.")] String OptionName; [Required, Description("The desired value of the SQL configuration option.")] Sint32 OptionValue; [Write, Description("Determines whether the instance should be restarted after updating the configuration option.")] Boolean RestartService; diff --git a/DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.psm1 b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 similarity index 87% rename from DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.psm1 rename to DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 index 0e33fc9f5..464a6dc0a 100644 --- a/DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.psm1 +++ b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -8,10 +8,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER EndpointName The name of the endpoint. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Get-TargetResource @@ -26,26 +26,26 @@ function Get-TargetResource [Parameter()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName + $InstanceName ) $getTargetResourceReturnValues = @{ - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Ensure = 'Absent' - EndpointName = '' - Port = '' - IpAddress = '' + ServerName = $ServerName + InstanceName = $InstanceName + Ensure = 'Absent' + EndpointName = '' + Port = '' + IpAddress = '' } - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { - Write-Verbose -Message ('Connected to {0}\{1}' -f $SQLServer, $SQLInstanceName) + Write-Verbose -Message ('Connected to {0}\{1}' -f $ServerName, $InstanceName) $endpointObject = $sqlServerObject.Endpoints[$EndpointName] if ($endpointObject.Name -eq $EndpointName) @@ -73,7 +73,7 @@ function Get-TargetResource else { throw New-TerminatingError -ErrorType NotConnectedToInstance ` - -FormatArgs @($SQLServer, $SQLInstanceName) ` + -FormatArgs @($ServerName, $InstanceName) ` -ErrorCategory InvalidOperation } @@ -93,10 +93,10 @@ function Get-TargetResource .PARAMETER Port The network port the endpoint is listening on. Default value is 5022. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER IpAddress @@ -122,20 +122,20 @@ function Set-TargetResource [Parameter()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.String] $IpAddress = '0.0.0.0' ) - $getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -ServerName $ServerName -InstanceName $InstanceName - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { if ($Ensure -eq 'Present' -and $getTargetResourceResult.Ensure -eq 'Absent') @@ -196,7 +196,7 @@ function Set-TargetResource else { throw New-TerminatingError -ErrorType NotConnectedToInstance ` - -FormatArgs @($SQLServer, $SQLInstanceName) ` + -FormatArgs @($ServerName, $InstanceName) ` -ErrorCategory InvalidOperation } } @@ -214,10 +214,10 @@ function Set-TargetResource .PARAMETER Port The network port the endpoint is listening on. Default value is 5022. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER IpAddress @@ -244,18 +244,18 @@ function Test-TargetResource [Parameter()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.String] $IpAddress = '0.0.0.0' ) - $getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -ServerName $ServerName -InstanceName $InstanceName if ($getTargetResourceResult.Ensure -eq $Ensure) { $result = $true diff --git a/DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.schema.mof b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.schema.mof similarity index 75% rename from DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.schema.mof rename to DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.schema.mof index 737bb8dbf..05c85cfab 100644 --- a/DSCResources/MSFT_xSQLServerEndpoint/MSFT_xSQLServerEndpoint.schema.mof +++ b/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.schema.mof @@ -1,10 +1,10 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerEndpoint")] -class MSFT_xSQLServerEndpoint : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerEndpoint")] +class MSFT_SqlServerEndpoint : OMI_BaseResource { [Key, Description("The name of the endpoint.")] String EndpointName; [Write, Description("If the endpoint should be present or absent. Default values is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("The network port the endpoint is listening on. Default value is 5022.")] Uint16 Port; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Write, Description("The network IP address the endpoint is listening on. Default the endpoint will listen on any valid IP address.")] String IpAddress; }; diff --git a/DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.psm1 b/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 similarity index 92% rename from DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.psm1 rename to DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 index 94c538a5f..1d2b104d9 100644 --- a/DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.psm1 +++ b/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -29,7 +29,7 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter(Mandatory = $true)] [System.String] @@ -42,7 +42,7 @@ function Get-TargetResource try { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] if ( $null -ne $endpointObject ) @@ -75,7 +75,7 @@ function Get-TargetResource return @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Ensure = [System.String] $Ensure Name = [System.String] $Name Principal = [System.String] $Principal @@ -90,7 +90,7 @@ function Get-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Ensure @@ -116,7 +116,7 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -139,7 +139,7 @@ function Set-TargetResource $parameters = @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name Principal = [System.String] $Principal } @@ -147,7 +147,7 @@ function Set-TargetResource $getTargetResourceResult = Get-TargetResource @parameters if ($getTargetResourceResult.Ensure -ne $Ensure) { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] if ($null -ne $endpointObject) @@ -184,7 +184,7 @@ function Set-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Ensure @@ -211,7 +211,7 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $NodeName, + $ServerName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -234,7 +234,7 @@ function Test-TargetResource $parameters = @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name Principal = [System.String] $Principal } diff --git a/DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.schema.mof b/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof similarity index 80% rename from DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.schema.mof rename to DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof index d50707093..c7b02df36 100644 --- a/DSCResources/MSFT_xSQLServerEndpointPermission/MSFT_xSQLServerEndpointPermission.schema.mof +++ b/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerEndpointPermission")] -class MSFT_xSQLServerEndpointPermission : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerEndpointPermission")] +class MSFT_SqlServerEndpointPermission : OMI_BaseResource { [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; - [Required, Description("The host name of the SQL Server to be configured.")] String NodeName; + [Required, Description("The host name of the SQL Server to be configured.")] String ServerName; [Write, Description("If the permission should be present or absent. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Required, Description("The name of the endpoint.")] String Name; [Key, Description("The login to which permission will be set.")] String Principal; diff --git a/DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.psm1 b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 similarity index 89% rename from DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.psm1 rename to DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 index 1ba8d3232..b1deecd0c 100644 --- a/DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.psm1 +++ b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -26,7 +26,7 @@ function Get-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -37,7 +37,7 @@ function Get-TargetResource try { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] if ($null -ne $endpointObject) @@ -56,7 +56,7 @@ function Get-TargetResource return @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name State = [System.String] $currentState } @@ -69,7 +69,7 @@ function Get-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -89,7 +89,7 @@ function Set-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -103,7 +103,7 @@ function Set-TargetResource $parameters = @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Name = [System.String] $Name } @@ -114,7 +114,7 @@ function Set-TargetResource { New-VerboseMessage -Message ('Changing state of endpoint ''{0}''' -f $Name) - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $endpointObject = $sqlServerObject.Endpoints[$Name] @@ -143,7 +143,7 @@ function Set-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Name @@ -164,7 +164,7 @@ function Test-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -178,7 +178,7 @@ function Test-TargetResource $parameters = @{ InstanceName = $InstanceName - NodeName = $NodeName + ServerName = $ServerName Name = $Name } diff --git a/DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.schema.mof b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof similarity index 70% rename from DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.schema.mof rename to DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof index 14edfab02..61062db7b 100644 --- a/DSCResources/MSFT_xSQLServerEndpointState/MSFT_xSQLServerEndpointState.schema.mof +++ b/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerEndpointState")] -class MSFT_xSQLServerEndpointState : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerEndpointState")] +class MSFT_SqlServerEndpointState : OMI_BaseResource { [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String NodeName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Key, Description("The name of the endpoint.")] String Name; [Write, Description("The state of the endpoint. Valid states are Started, Stopped or Disabled. Default value is 'Started'."), ValueMap{"Started","Stopped","Disabled"}, Values{"Started","Stopped","Disabled"}] String State; }; diff --git a/DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.psm1 b/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 similarity index 89% rename from DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.psm1 rename to DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 index c968c945b..c5c2582ce 100644 --- a/DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.psm1 +++ b/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# @@ -9,10 +9,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name The name of the login to retrieve. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to retrieve the login from. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to retrieve the login from. #> function Get-TargetResource @@ -27,17 +27,17 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName + $InstanceName ) - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName Write-Verbose 'Getting SQL logins' - New-VerboseMessage -Message "Getting the login '$Name' from '$SQLServer\$SQLInstanceName'" + New-VerboseMessage -Message "Getting the login '$Name' from '$ServerName\$InstanceName'" $login = $serverObject.Logins[$Name] @@ -50,15 +50,15 @@ function Get-TargetResource $Ensure = 'Absent' } - New-VerboseMessage -Message "The login '$Name' is $ensure from the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "The login '$Name' is $ensure from the '$ServerName\$InstanceName' instance." $returnValue = @{ - Ensure = $Ensure - Name = $Name - LoginType = $login.LoginType - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Disabled = $login.IsDisabled + Ensure = $Ensure + Name = $Name + LoginType = $login.LoginType + ServerName = $ServerName + InstanceName = $InstanceName + Disabled = $login.IsDisabled } if ( $login.LoginType -eq 'SqlLogin' ) @@ -84,10 +84,10 @@ function Get-TargetResource .PARAMETER LoginType The type of login to create. Default is 'WindowsUser' - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to create the login on. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to create the login on. .PARAMETER LoginCredential @@ -134,11 +134,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.Management.Automation.PSCredential] @@ -161,7 +161,7 @@ function Set-TargetResource $Disabled ) - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName switch ( $Ensure ) { @@ -175,14 +175,14 @@ function Set-TargetResource { if ( $login.PasswordExpirationEnabled -ne $LoginPasswordExpirationEnabled ) { - New-VerboseMessage -Message "Setting PasswordExpirationEnabled to '$LoginPasswordExpirationEnabled' for the login '$Name' on the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "Setting PasswordExpirationEnabled to '$LoginPasswordExpirationEnabled' for the login '$Name' on the '$ServerName\$InstanceName' instance." $login.PasswordExpirationEnabled = $LoginPasswordExpirationEnabled Update-SQLServerLogin -Login $login } if ( $login.PasswordPolicyEnforced -ne $LoginPasswordPolicyEnforced ) { - New-VerboseMessage -Message "Setting PasswordPolicyEnforced to '$LoginPasswordPolicyEnforced' for the login '$Name' on the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "Setting PasswordPolicyEnforced to '$LoginPasswordPolicyEnforced' for the login '$Name' on the '$ServerName\$InstanceName' instance." $login.PasswordPolicyEnforced = $LoginPasswordPolicyEnforced Update-SQLServerLogin -Login $login } @@ -196,7 +196,7 @@ function Set-TargetResource if ( $PSBoundParameters.ContainsKey('Disabled') -and ($login.IsDisabled -ne $Disabled) ) { - New-VerboseMessage -Message "Setting IsDisabled to '$Disabled' for the login '$Name' on the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "Setting IsDisabled to '$Disabled' for the login '$Name' on the '$ServerName\$InstanceName' instance." if ( $Disabled ) { $login.Disable() @@ -220,7 +220,7 @@ function Set-TargetResource throw New-TerminatingError -ErrorType LoginCredentialNotFound -FormatArgs $Name -ErrorCategory ObjectNotFound } - New-VerboseMessage -Message "Adding the login '$Name' to the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "Adding the login '$Name' to the '$ServerName\$InstanceName' instance." $login = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login -ArgumentList $serverObject, $Name $login.LoginType = $LoginType @@ -232,7 +232,7 @@ function Set-TargetResource # Verify the instance is in Mixed authentication mode if ( $serverObject.LoginMode -notmatch 'Mixed|Integrated' ) { - throw New-TerminatingError -ErrorType IncorrectLoginMode -FormatArgs $SQLServer, $SQLInstanceName, $serverObject.LoginMode -ErrorCategory NotImplemented + throw New-TerminatingError -ErrorType IncorrectLoginMode -FormatArgs $ServerName, $InstanceName, $serverObject.LoginMode -ErrorCategory NotImplemented } $login.PasswordPolicyEnforced = $LoginPasswordPolicyEnforced @@ -267,7 +267,7 @@ function Set-TargetResource { if ( $serverObject.Logins[$Name] ) { - New-VerboseMessage -Message "Dropping the login '$Name' from the '$SQLServer\$SQLInstanceName' instance." + New-VerboseMessage -Message "Dropping the login '$Name' from the '$ServerName\$InstanceName' instance." Remove-SQLServerLogin -Login $serverObject.Logins[$Name] } } @@ -287,10 +287,10 @@ function Set-TargetResource .PARAMETER LoginType The type of login. Default is 'WindowsUser' - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance. .PARAMETER LoginCredential @@ -337,11 +337,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [System.Management.Automation.PSCredential] @@ -368,16 +368,16 @@ function Test-TargetResource $testPassed = $true $getParams = @{ - Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + Name = $Name + ServerName = $ServerName + InstanceName = $InstanceName } $loginInfo = Get-TargetResource @getParams if ( $Ensure -ne $loginInfo.Ensure ) { - New-VerboseMessage -Message "The login '$Name' on the instance '$SQLServer\$SQLInstanceName' is $($loginInfo.Ensure) rather than $Ensure" + New-VerboseMessage -Message "The login '$Name' on the instance '$ServerName\$InstanceName' is $($loginInfo.Ensure) rather than $Ensure" $testPassed = $false } @@ -385,13 +385,13 @@ function Test-TargetResource { if ( $LoginType -ne $loginInfo.LoginType ) { - New-VerboseMessage -Message "The login '$Name' on the instance '$SQLServer\$SQLInstanceName' is a $($loginInfo.LoginType) rather than $LoginType" + New-VerboseMessage -Message "The login '$Name' on the instance '$ServerName\$InstanceName' is a $($loginInfo.LoginType) rather than $LoginType" $testPassed = $false } if ( $PSBoundParameters.ContainsKey('Disabled') -and ($loginInfo.Disabled -ne $Disabled) ) { - New-VerboseMessage -Message "The login '$Name' on the instance '$SQLServer\$SQLInstanceName' has IsDisabled set to $($loginInfo.Disabled) rather than $Disabled" + New-VerboseMessage -Message "The login '$Name' on the instance '$ServerName\$InstanceName' has IsDisabled set to $($loginInfo.Disabled) rather than $Disabled" $testPassed = $false } @@ -399,13 +399,13 @@ function Test-TargetResource { if ( $LoginPasswordExpirationEnabled -ne $loginInfo.LoginPasswordExpirationEnabled ) { - New-VerboseMessage -Message "The login '$Name' on the instance '$SQLServer\$SQLInstanceName' has PasswordExpirationEnabled set to $($loginInfo.LoginPasswordExpirationEnabled) rather than $LoginPasswordExpirationEnabled" + New-VerboseMessage -Message "The login '$Name' on the instance '$ServerName\$InstanceName' has PasswordExpirationEnabled set to $($loginInfo.LoginPasswordExpirationEnabled) rather than $LoginPasswordExpirationEnabled" $testPassed = $false } if ( $LoginPasswordPolicyEnforced -ne $loginInfo.LoginPasswordPolicyEnforced ) { - New-VerboseMessage -Message "The login '$Name' on the instance '$SQLServer\$SQLInstanceName' has PasswordPolicyEnforced set to $($loginInfo.LoginPasswordPolicyEnforced) rather than $LoginPasswordPolicyEnforced" + New-VerboseMessage -Message "The login '$Name' on the instance '$ServerName\$InstanceName' has PasswordPolicyEnforced set to $($loginInfo.LoginPasswordPolicyEnforced) rather than $LoginPasswordPolicyEnforced" $testPassed = $false } @@ -416,7 +416,7 @@ function Test-TargetResource try { - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -SetupCredential $userCred + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName -SetupCredential $userCred } catch { diff --git a/DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.schema.mof b/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof similarity index 91% rename from DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.schema.mof rename to DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof index 51f15fc66..f687e0963 100644 --- a/DSCResources/MSFT_xSQLServerLogin/MSFT_xSQLServerLogin.schema.mof +++ b/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof @@ -1,13 +1,13 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerLogin")] -class MSFT_xSQLServerLogin : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerLogin")] +class MSFT_SqlServerLogin : OMI_BaseResource { [Write, Description("The specified login is Present or Absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Key, Description("The name of the login.")] String Name; [Write, Description("The type of login to be created. If LoginType is 'WindowsUser' or 'WindowsGroup' then provide the name in the format DOMAIN\name. Default is WindowsUser. Unsupported login types are Certificate, AsymmetricKey, ExternalUser, and ExternalGroup."), ValueMap{"WindowsUser","WindowsGroup","SqlLogin","Certificate","AsymmetricKey","ExternalUser","ExternalGroup"}, Values{"WindowsUser","WindowsGroup","SqlLogin","Certificate","AsymmetricKey","ExternalUser","ExternalGroup"}] String LoginType; - [Key, Description("The hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; [Write, EmbeddedInstance("MSFT_Credential"), Description("If LoginType is 'SqlLogin' then a PSCredential is needed for the password to the login.")] String LoginCredential; [Write, Description("Specifies if the login is required to have its password change on the next login. Only applies to SQL Logins. Default is $true.")] Boolean LoginMustChangePassword; [Write, Description("Specifies if the login password is required to expire in accordance to the operating system security policy. Only applies to SQL Logins. Default is $true.")] Boolean LoginPasswordExpirationEnabled; diff --git a/DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.psm1 b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 similarity index 86% rename from DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.psm1 rename to DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 index 1eb7d49f7..d3ee9f2d8 100644 --- a/DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.psm1 +++ b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 @@ -1,14 +1,14 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS This function gets the max degree of parallelism server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Get-TargetResource @@ -20,15 +20,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME + $ServerName = $env:COMPUTERNAME ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Is this node actively hosting the SQL instance? $isActiveNode = Test-ActiveNode -ServerObject $sqlServerObject @@ -40,10 +40,10 @@ function Get-TargetResource } $returnValue = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer - MaxDop = $currentMaxDop - IsActiveNode = $isActiveNode + InstanceName = $InstanceName + ServerName = $ServerName + MaxDop = $currentMaxDop + IsActiveNode = $isActiveNode } $returnValue @@ -53,10 +53,10 @@ function Get-TargetResource .SYNOPSIS This function sets the max degree of parallelism server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Ensure @@ -82,12 +82,12 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -108,7 +108,7 @@ function Set-TargetResource $ProcessOnlyOnActiveNode ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -122,7 +122,7 @@ function Set-TargetResource if ($MaxDop) { throw New-TerminatingError -ErrorType MaxDopParamMustBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } @@ -151,7 +151,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType MaxDopSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $targetMaxDop) ` + -FormatArgs @($ServerName, $InstanceName, $targetMaxDop) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -162,10 +162,10 @@ function Set-TargetResource .SYNOPSIS This function tests the max degree of parallelism server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Ensure @@ -191,12 +191,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -220,8 +220,8 @@ function Test-TargetResource Write-Verbose -Message 'Testing the max degree of parallelism server configuration option' $parameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName } $currentValues = Get-TargetResource @parameters @@ -235,7 +235,7 @@ function Test-TargetResource #> if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { - New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $isMaxDopInDesiredState } @@ -256,7 +256,7 @@ function Test-TargetResource if ($MaxDop) { throw New-TerminatingError -ErrorType MaxDopParamMustBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } diff --git a/DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.schema.mof b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.schema.mof similarity index 85% rename from DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.schema.mof rename to DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.schema.mof index 91efe692c..330b67f28 100644 --- a/DSCResources/MSFT_xSQLServerMaxDop/MSFT_xSQLServerMaxDop.schema.mof +++ b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.schema.mof @@ -1,11 +1,11 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerMaxDop")] -class MSFT_xSQLServerMaxDop : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerMaxDop")] +class MSFT_SqlServerMaxDop : OMI_BaseResource { [Write, Description("When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured when parameter DynamicAlloc is set to $true. When set to 'Absent' max degree of parallelism will be set to 0 which means no limit in number of processors used in parallel plan execution."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("If set to $true then max degree of parallelism will be dynamically configured. When this is set parameter is set to $true, the parameter MaxDop must be set to $null or not be configured.")] Boolean DynamicAlloc; [Write, Description("A numeric value to limit the number of processors used in parallel plan execution.")] Sint32 MaxDop; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Write, Description("Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance.")] Boolean ProcessOnlyOnActiveNode; [Read, Description("Determines if the current node is actively hosting the SQL Server instance.")] Boolean IsActiveNode; }; diff --git a/DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.psm1 b/DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.psm1 similarity index 90% rename from DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.psm1 rename to DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.psm1 index db6ac74b7..cce13e64b 100644 --- a/DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.psm1 +++ b/DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.psm1 @@ -1,13 +1,13 @@ -Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -ChildPath 'xSQLServerHelper.psm1') -Force +Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -ChildPath 'SqlServerDscHelper.psm1') -Force <# .SYNOPSIS This function gets the value of the min and max memory server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> @@ -20,15 +20,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME + $ServerName = $env:COMPUTERNAME ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -41,11 +41,11 @@ function Get-TargetResource } $returnValue = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer - MinMemory = $minMemory - MaxMemory = $maxMemory - IsActiveNode = $isActiveNode + InstanceName = $InstanceName + ServerName = $ServerName + MinMemory = $minMemory + MaxMemory = $maxMemory + IsActiveNode = $isActiveNode } $returnValue @@ -55,10 +55,10 @@ function Get-TargetResource .SYNOPSIS This function sets the value for the min and max memory server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Ensure @@ -87,12 +87,12 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -116,7 +116,7 @@ function Set-TargetResource $ProcessOnlyOnActiveNode ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -130,7 +130,7 @@ function Set-TargetResource if ($MaxMemory) { throw New-TerminatingError -ErrorType MaxMemoryParamMustBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } @@ -142,7 +142,7 @@ function Set-TargetResource if (-not $MaxMemory) { throw New-TerminatingError -ErrorType MaxMemoryParamMustNotBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } } @@ -173,7 +173,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType AlterServerMemoryFailed ` - -FormatArgs @($SQLServer, $SQLInstanceName) ` + -FormatArgs @($ServerName, $InstanceName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -184,10 +184,10 @@ function Set-TargetResource .SYNOPSIS This function tests the value of the min and max memory server configuration option. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Ensure @@ -216,12 +216,12 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet("Present", "Absent")] @@ -248,8 +248,8 @@ function Test-TargetResource Write-Verbose -Message 'Testing the values of the minimum and maximum memory server configuration option set to be used by the instance.' $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName } $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters @@ -265,7 +265,7 @@ function Test-TargetResource if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { # Use localization if the resource has been converted - New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $isServerMemoryInDesiredState } @@ -293,7 +293,7 @@ function Test-TargetResource if ($MaxMemory) { throw New-TerminatingError -ErrorType MaxMemoryParamMustBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } @@ -305,7 +305,7 @@ function Test-TargetResource if (-not $MaxMemory) { throw New-TerminatingError -ErrorType MaxMemoryParamMustNotBeNull ` - -FormatArgs @( $SQLServer, $SQLInstanceName ) ` + -FormatArgs @( $ServerName, $InstanceName ) ` -ErrorCategory InvalidArgument } } diff --git a/DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.schema.mof b/DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.schema.mof similarity index 86% rename from DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.schema.mof rename to DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.schema.mof index 4f6bbb202..158f0ccc5 100644 --- a/DSCResources/MSFT_xSQLServerMemory/MSFT_xSQLServerMemory.schema.mof +++ b/DSCResources/MSFT_SqlServerMemory/MSFT_SqlServerMemory.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerMemory")] -class MSFT_xSQLServerMemory : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerMemory")] +class MSFT_SqlServerMemory : OMI_BaseResource { - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String SQLServer; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("When set to 'Present' then min and max memory will be set to either the value in parameter MinMemory and MaxMemory or dynamically configured when parameter DynamicAlloc is set to $true. When set to 'Absent' min and max memory will be set to default values. Default value is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("If set to $true then max memory will be dynamically configured. When this is set parameter is set to $true, the parameter MaxMemory must be set to $null or not be configured. Default value is $false.")] Boolean DynamicAlloc; [Write, Description("Minimum amount of memory, in MB, in the buffer pool used by the instance of SQL Server.")] Sint32 MinMemory; diff --git a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 similarity index 96% rename from DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 rename to DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 index 23309fd95..b90c0be63 100644 --- a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 +++ b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 @@ -1,10 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') -Force + -ChildPath 'SqlServerDscHelper.psm1') -Force Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` -ChildPath 'CommonResourceHelper.psm1') # Load localized string data -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerNetwork' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerNetwork' <# .SYNOPSIS @@ -67,7 +67,7 @@ function Get-TargetResource .SYNOPSIS Sets the SQL Server network properties. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName @@ -105,7 +105,7 @@ function Set-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -223,7 +223,7 @@ function Set-TargetResource if ($RestartService -and $isRestartNeeded) { - Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $InstanceName -Timeout $RestartTimeout + Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout } } finally @@ -236,7 +236,7 @@ function Set-TargetResource .SYNOPSIS Sets the SQL Server network properties. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. Not used in Test-TargetResource. @@ -280,7 +280,7 @@ function Test-TargetResource [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] diff --git a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.schema.mof similarity index 87% rename from DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof rename to DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.schema.mof index 7f21b4f58..1ce38653c 100644 --- a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof +++ b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerNetwork")] -class MSFT_xSQLServerNetwork : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerNetwork")] +class MSFT_SqlServerNetwork : OMI_BaseResource { [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Required, Description("The name of network protocol to be configured. Only tcp is currently supported."), ValueMap{"Tcp"}, Values{"Tcp"}] String ProtocolName; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String SQLServer; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("Enables or disables the network protocol.")] Boolean IsEnabled; [Write, Description("Specifies whether the SQL Server instance should use a dynamic port. Value cannot be set to 'True' if TcpPort is set to a non-empty string.")] Boolean TcpDynamicPort; [Write, Description("The TCP port(s) that SQL Server should be listening on. If the IP address should listen on more than one port, list all ports separated with a comma ('1433,1500,1501'). To use this parameter set TcpDynamicPorts to 'False'.")] String TcpPort; diff --git a/DSCResources/MSFT_xSQLServerNetwork/en-US/MSFT_xSQLServerNetwork.strings.psd1 b/DSCResources/MSFT_SqlServerNetwork/en-US/MSFT_SqlServerNetwork.strings.psd1 similarity index 93% rename from DSCResources/MSFT_xSQLServerNetwork/en-US/MSFT_xSQLServerNetwork.strings.psd1 rename to DSCResources/MSFT_SqlServerNetwork/en-US/MSFT_SqlServerNetwork.strings.psd1 index d19f1e234..2454c12de 100644 --- a/DSCResources/MSFT_xSQLServerNetwork/en-US/MSFT_xSQLServerNetwork.strings.psd1 +++ b/DSCResources/MSFT_SqlServerNetwork/en-US/MSFT_SqlServerNetwork.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for xSQLServerNetwork +# Localized resources for SqlServerNetwork ConvertFrom-StringData @' GetNetworkProtocol = Getting network protocol [{0}] for SQL instance [{1}]. diff --git a/DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.psm1 b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 similarity index 94% rename from DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.psm1 rename to DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 index c0c0f1e62..afb59b289 100644 --- a/DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.psm1 +++ b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Principal @@ -29,7 +29,7 @@ function Get-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -45,7 +45,7 @@ function Get-TargetResource try { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Gets a set of permissions granted based on the desired permissions in $Permission $desiredPermissionSet = Get-SQLServerPermissionSet -Permission $Permission @@ -82,7 +82,7 @@ function Get-TargetResource return @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Ensure = [System.String] $ensure Principal = [System.String] $Principal Permission = [System.String[]] $grantedPermission @@ -96,7 +96,7 @@ function Get-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Ensure @@ -119,7 +119,7 @@ function Set-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -138,7 +138,7 @@ function Set-TargetResource $getTargetResourceParameters = @{ InstanceName = [System.String] $InstanceName - NodeName = [System.String] $NodeName + ServerName = [System.String] $ServerName Principal = [System.String] $Principal Permission = [System.String[]] $Permission } @@ -149,7 +149,7 @@ function Set-TargetResource { try { - $sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $permissionSet = Get-SQLServerPermissionSet -Permission $Permission @@ -184,7 +184,7 @@ function Set-TargetResource .PARAMETER InstanceName The name of the SQL instance to be configured. - .PARAMETER NodeName + .PARAMETER ServerName The host name of the SQL Server to be configured. .PARAMETER Ensure @@ -208,7 +208,7 @@ function Test-TargetResource [Parameter()] [System.String] - $NodeName = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -227,7 +227,7 @@ function Test-TargetResource $getTargetResourceParameters = @{ InstanceName = $InstanceName - NodeName = $NodeName + ServerName = $ServerName Principal = $Principal Permission = $Permission } diff --git a/DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.schema.mof b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.schema.mof similarity index 81% rename from DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.schema.mof rename to DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.schema.mof index d67969841..169c7c14f 100644 --- a/DSCResources/MSFT_xSQLServerPermission/MSFT_xSQLServerPermission.schema.mof +++ b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerPermission")] -class MSFT_xSQLServerPermission : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerPermission")] +class MSFT_SqlServerPermission : OMI_BaseResource { [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; - [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String NodeName; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("If the permission should be present or absent. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Key, Description("The login to which permission will be set.")] String Principal; [Write, Description("The permission to set for the login. Valid values are ConnectSql, AlterAnyAvailabilityGroup, ViewServerState or AlterAnyEndPoint."), ValueMap{"ConnectSql","AlterAnyAvailabilityGroup","ViewServerState","AlterAnyEndPoint"}, Values{"ConnectSql","AlterAnyAvailabilityGroup","ViewServerState","AlterAnyEndPoint"}] String Permission[]; diff --git a/DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.psm1 b/DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.psm1 similarity index 99% rename from DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.psm1 rename to DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.psm1 index 482653263..a7f09403c 100644 --- a/DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.psm1 +++ b/DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.psm1 @@ -1,4 +1,4 @@ -$dom = [AppDomain]::CreateDomain('xSQLServerReplication') +$dom = [AppDomain]::CreateDomain('SqlServerReplication') function Get-TargetResource { diff --git a/DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.schema.mof b/DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.schema.mof similarity index 88% rename from DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.schema.mof rename to DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.schema.mof index 609bc1aaf..1e4332e8d 100644 --- a/DSCResources/MSFT_xSQLServerReplication/MSFT_xSQLServerReplication.schema.mof +++ b/DSCResources/MSFT_SqlServerReplication/MSFT_SqlServerReplication.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerReplication")] -class MSFT_xSQLServerReplication : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerReplication")] +class MSFT_SqlServerReplication : OMI_BaseResource { [Key, Description("SQL Server instance name where replication distribution will be configured")] String InstanceName; [Write, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; diff --git a/DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.psm1 b/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 similarity index 91% rename from DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.psm1 rename to DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 index 8c01065db..1ea9d0168 100644 --- a/DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.psm1 +++ b/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# .SYNOPSIS @@ -17,10 +17,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER ServerRoleName The name of server role to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Get-TargetResource @@ -49,15 +49,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName + $InstanceName ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName $ensure = 'Present' if ($sqlServerObject) @@ -72,7 +72,7 @@ function Get-TargetResource catch { throw New-TerminatingError -ErrorType EnumMemberNamesServerRoleGetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $ServerRoleName) ` + -FormatArgs @($ServerName, $InstanceName, $ServerRoleName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -82,7 +82,7 @@ function Get-TargetResource if ($MembersToInclude -or $MembersToExclude) { throw New-TerminatingError -ErrorType MembersToIncludeAndExcludeParamMustBeNull ` - -FormatArgs @($SQLServer, $SQLInstanceName) ` + -FormatArgs @($ServerName, $InstanceName) ` -ErrorCategory InvalidArgument } @@ -131,8 +131,8 @@ function Get-TargetResource MembersToInclude = $MembersToInclude MembersToExclude = $MembersToExclude ServerRoleName = $ServerRoleName - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } $returnValue } @@ -157,10 +157,10 @@ function Get-TargetResource .PARAMETER ServerRoleName The name of server role to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Set-TargetResource @@ -193,15 +193,15 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName + $InstanceName ) - $sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName if ($sqlServerObject) { @@ -224,7 +224,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType DropServerRoleSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $ServerRoleName) ` + -FormatArgs @($ServerName, $InstanceName, $ServerRoleName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -248,7 +248,7 @@ function Set-TargetResource catch { throw New-TerminatingError -ErrorType CreateServerRoleSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $ServerRoleName) ` + -FormatArgs @($ServerName, $InstanceName, $ServerRoleName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -259,7 +259,7 @@ function Set-TargetResource if ($MembersToInclude -or $MembersToExclude) { throw New-TerminatingError -ErrorType MembersToIncludeAndExcludeParamMustBeNull ` - -FormatArgs @($SQLServer, $SQLInstanceName) ` + -FormatArgs @($ServerName, $InstanceName) ` -ErrorCategory InvalidArgument } @@ -342,10 +342,10 @@ function Set-TargetResource .PARAMETER ServerRoleName The name of server role to be created or dropped. - .PARAMETER SQLServer + .PARAMETER ServerName The host name of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance to be configured. #> function Test-TargetResource @@ -379,19 +379,19 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName + $InstanceName ) Write-Verbose -Message "Testing SQL Server role $ServerRoleName properties." $getTargetResourceParameters = @{ - SQLInstanceName = $PSBoundParameters.SQLInstanceName - SQLServer = $PSBoundParameters.SQLServer + InstanceName = $PSBoundParameters.InstanceName + ServerName = $PSBoundParameters.ServerName ServerRoleName = $PSBoundParameters.ServerRoleName Members = $PSBoundParameters.Members MembersToInclude = $PSBoundParameters.MembersToInclude @@ -463,7 +463,7 @@ function Add-SqlDscServerRoleMember if ( -not ($SqlServerObject.Logins[$LoginName]) ) { throw New-TerminatingError -ErrorType LoginNotFound ` - -FormatArgs @($LoginName, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($LoginName, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } @@ -476,7 +476,7 @@ function Add-SqlDscServerRoleMember catch { throw New-TerminatingError -ErrorType AddMemberServerRoleSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $ServerRoleName, $LoginName) ` + -FormatArgs @($ServerName, $InstanceName, $ServerRoleName, $LoginName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } @@ -519,7 +519,7 @@ function Remove-SqlDscServerRoleMember if ( -not ($SqlServerObject.Logins[$LoginName]) ) { throw New-TerminatingError -ErrorType LoginNotFound ` - -FormatArgs @($LoginName, $SQLServer, $SQLInstanceName) ` + -FormatArgs @($LoginName, $ServerName, $InstanceName) ` -ErrorCategory ObjectNotFound } @@ -532,7 +532,7 @@ function Remove-SqlDscServerRoleMember catch { throw New-TerminatingError -ErrorType DropMemberServerRoleSetError ` - -FormatArgs @($SQLServer, $SQLInstanceName, $ServerRoleName, $LoginName) ` + -FormatArgs @($ServerName, $InstanceName, $ServerRoleName, $LoginName) ` -ErrorCategory InvalidOperation ` -InnerException $_.Exception } diff --git a/DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.schema.mof b/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof similarity index 86% rename from DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.schema.mof rename to DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof index d7c1a397b..4ed3b2286 100644 --- a/DSCResources/MSFT_xSQLServerRole/MSFT_xSQLServerRole.schema.mof +++ b/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof @@ -1,9 +1,9 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerRole")] -class MSFT_xSQLServerRole : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServerRole")] +class MSFT_SqlServerRole : OMI_BaseResource { [Key, Description("The name of of SQL role to add or remove.")] String ServerRoleName; - [Key, Description("The host name of the SQL Server to be configured.")] String SQLServer; - [Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName; + [Key, Description("The host name of the SQL Server to be configured.")] String ServerName; + [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; [Write, Description("An enumerated value that describes if the server role is added (Present) or dropped (Absent). Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("The members the server role should have. This parameter will replace all the current server role members with the specified members.")] String Members[]; [Write, Description("The members the server role should include. This parameter will only add members to a server role. Can not be used at the same time as parameter Members.")] String MembersToInclude[]; diff --git a/DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.psm1 b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 similarity index 81% rename from DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.psm1 rename to DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 index db2f4b304..b3f0a0af6 100644 --- a/DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.psm1 +++ b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 @@ -1,19 +1,19 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') + -ChildPath 'SqlServerDscHelper.psm1') Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerServiceAccount' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServiceAccount' <# .SYNOPSIS Gets the service account for the specified instance. - .PARAMETER SQLServer + .PARAMETER ServerName Host name of the SQL Server to manage. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance. .PARAMETER ServiceType @@ -25,7 +25,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerServiceA Credential of the service account that should be used. .EXAMPLE - Get-TargetResource -SQLServer $env:COMPUTERNAME -SQLInstanceName MSSQLSERVER -ServiceType SqlServer -ServiceAccount $account + Get-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account #> function Get-TargetResource { @@ -35,11 +35,11 @@ function Get-TargetResource ( [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('DatabaseEngine', 'SQLServerAgent', 'Search', 'IntegrationServices', 'AnalysisServices', 'ReportingServices', 'SQLServerBrowser', 'NotificationServices')] @@ -52,24 +52,24 @@ function Get-TargetResource ) # Get the SMO Service object instance - $serviceObject = Get-ServiceObject -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -ServiceType $ServiceType + $serviceObject = Get-ServiceObject -ServerName $ServerName -InstanceName $InstanceName -ServiceType $ServiceType # If no service was found, throw an exception if (-not $serviceObject) { - $errorMessage = $script:localizedData.ServiceNotFound -f $ServiceType, $SQLServer, $SQLInstanceName + $errorMessage = $script:localizedData.ServiceNotFound -f $ServiceType, $ServerName, $InstanceName New-ObjectNotFoundException -Message $errorMessage } # Local accounts will start with a '.' - # Replace a domain of '.' with the value for $SQLServer - $serviceAccountName = $serviceObject.ServiceAccount -ireplace '^([\.])\\(.*)$', "$SQLServer\`$2" + # Replace a domain of '.' with the value for $ServerName + $serviceAccountName = $serviceObject.ServiceAccount -ireplace '^([\.])\\(.*)$', "$ServerName\`$2" # Return a hashtable with the service information return @{ - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - ServiceType = $serviceObject.Type + ServerName = $ServerName + InstanceName = $InstanceName + ServiceType = $serviceObject.Type ServiceAccount = $serviceAccountName } } @@ -78,10 +78,10 @@ function Get-TargetResource .SYNOPSIS Tests whether the specified instance's service account is correctly configured. - .PARAMETER SQLServer + .PARAMETER ServerName Host name of the SQL Server to manage. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance. .PARAMETER ServiceType @@ -98,7 +98,7 @@ function Get-TargetResource Forces the service account to be updated. .EXAMPLE - Test-TargetResource -SQLServer $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType SqlServer -ServiceAccount $account + Test-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account #> function Test-TargetResource @@ -109,11 +109,11 @@ function Test-TargetResource ( [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('DatabaseEngine', 'SQLServerAgent', 'Search', 'IntegrationServices', 'AnalysisServices', 'ReportingServices', 'SQLServerBrowser', 'NotificationServices')] @@ -140,8 +140,8 @@ function Test-TargetResource } # Get the current state - $currentState = Get-TargetResource -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -ServiceType $ServiceType -ServiceAccount $ServiceAccount - New-VerboseMessage -Message ($script:localizedData.CurrentServiceAccount -f $currentState.ServiceAccount, $SQLServer, $SQLInstanceName) + $currentState = Get-TargetResource -ServerName $ServerName -InstanceName $InstanceName -ServiceType $ServiceType -ServiceAccount $ServiceAccount + New-VerboseMessage -Message ($script:localizedData.CurrentServiceAccount -f $currentState.ServiceAccount, $ServerName, $InstanceName) return ($currentState.ServiceAccount -ieq $ServiceAccount.UserName) } @@ -150,10 +150,10 @@ function Test-TargetResource .SYNOPSIS Sets the SQL Server service account to the desired state. - .PARAMETER SQLServer + .PARAMETER ServerName Host name of the SQL Server to manage. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance. .PARAMETER ServiceType @@ -170,7 +170,7 @@ function Test-TargetResource Forces the service account to be updated. .EXAMPLE - Set-TargetResource -SQLServer $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType SqlServer -ServiceAccount $account + Set-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account #> function Set-TargetResource { @@ -179,11 +179,11 @@ function Set-TargetResource ( [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('DatabaseEngine', 'SQLServerAgent', 'Search', 'IntegrationServices', 'AnalysisServices', 'ReportingServices', 'SQLServerBrowser', 'NotificationServices')] @@ -204,12 +204,12 @@ function Set-TargetResource ) # Get the Service object - $serviceObject = Get-ServiceObject -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -ServiceType $ServiceType + $serviceObject = Get-ServiceObject -ServerName $ServerName -InstanceName $InstanceName -ServiceType $ServiceType # If no service was found, throw an exception if (-not $serviceObject) { - $errorMessage = $script:localizedData.ServiceNotFound -f $ServiceType, $SQLServer, $SQLInstanceName + $errorMessage = $script:localizedData.ServiceNotFound -f $ServiceType, $ServerName, $InstanceName New-ObjectNotFoundException -Message $errorMessage } @@ -220,14 +220,14 @@ function Set-TargetResource } catch { - $errorMessage = $script:localizedData.SetServiceAccountFailed -f $SQLServer, $SQLInstanceName, $_.Message + $errorMessage = $script:localizedData.SetServiceAccountFailed -f $ServerName, $InstanceName, $_.Message New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ } if ($RestartService) { - New-VerboseMessage -Message ($script:localizedData.RestartingService -f $SQLInstanceName) - Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + New-VerboseMessage -Message ($script:localizedData.RestartingService -f $InstanceName) + Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName } } @@ -235,10 +235,10 @@ function Set-TargetResource .SYNOPSIS Gets an SMO Service object instance for the requested service and type. - .PARAMETER SQLServer + .PARAMETER ServerName Host name of the SQL Server to manage. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance. .PARAMETER ServiceType @@ -246,7 +246,7 @@ function Set-TargetResource DatabaseEngine, SQLServerAgent, Search, IntegrationServices, AnalysisServices, ReportingServices, SQLServerBrowser, NotificationServices. .EXAMPLE - Get-ServiceObject -SQLServer $env:COMPUTERNAME -SQLInstanceName MSSQLSERVER -ServiceType SqlServer + Get-ServiceObject -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine #> function Get-ServiceObject { @@ -255,11 +255,11 @@ function Get-ServiceObject ( [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateSet('DatabaseEngine', 'SQLServerAgent', 'Search', 'IntegrationServices', 'AnalysisServices', 'ReportingServices', 'SQLServerBrowser', 'NotificationServices')] @@ -270,20 +270,20 @@ function Get-ServiceObject # Load the SMO libraries Import-SQLPSModule - $verboseMessage = $script:localizedData.ConnectingToWmi -f $SQLServer + $verboseMessage = $script:localizedData.ConnectingToWmi -f $ServerName New-VerboseMessage -Message $verboseMessage # Connect to SQL WMI - $managedComputer = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $SQLServer + $managedComputer = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $ServerName # Change the regex pattern for a default instance - if ($SQLInstanceName -ieq 'MSSQLServer') + if ($InstanceName -ieq 'MSSQLServer') { $serviceNamePattern = '^MSSQLServer$' } else { - $serviceNamePattern = ('\${0}$' -f $SQLInstanceName) + $serviceNamePattern = ('\${0}$' -f $InstanceName) } # Get the proper enum value diff --git a/DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.schema.mof b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof similarity index 74% rename from DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.schema.mof rename to DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof index feb42c03f..a19f16a84 100644 --- a/DSCResources/MSFT_xSQLServerServiceAccount/MSFT_xSQLServerServiceAccount.schema.mof +++ b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof @@ -1,8 +1,8 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerServiceAccount")] -class MSFT_xSQLServerServiceAccount : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlServiceAccount")] +class MSFT_SqlServiceAccount : OMI_BaseResource { - [Key, Description("Hostname of the SQL Server.")] String SQLServer; - [Key, Description("Name of the SQL instance.")] String SQLInstanceName; + [Key, Description("Hostname of the SQL Server.")] String ServerName; + [Key, Description("Name of the SQL instance.")] String InstanceName; [Key, Description("Type of service being managed."), ValueMap {"DatabaseEngine","SQLServerAgent","Search","IntegrationServices","AnalysisServices","ReportingServices","SQLServerBrowser","NotificationServices"}, Values {"DatabaseEngine","SQLServerAgent","Search","IntegrationServices","AnalysisServices","ReportingServices","SQLServerBrowser","NotificationServices"}] String ServiceType; [Required, EmbeddedInstance("MSFT_Credential"), Description("The service account that should be used when running the service.")] String ServiceAccount; [Write, Description("Determines whether the service is automatically restarted.")] Boolean RestartService; diff --git a/DSCResources/MSFT_xSQLServerServiceAccount/en-US/MSFT_xSQLServerServiceAccount.strings.psd1 b/DSCResources/MSFT_SqlServiceAccount/en-US/MSFT_SqlServiceAccount.strings.psd1 similarity index 92% rename from DSCResources/MSFT_xSQLServerServiceAccount/en-US/MSFT_xSQLServerServiceAccount.strings.psd1 rename to DSCResources/MSFT_SqlServiceAccount/en-US/MSFT_SqlServiceAccount.strings.psd1 index c18e0b70e..f7929ba27 100644 --- a/DSCResources/MSFT_xSQLServerServiceAccount/en-US/MSFT_xSQLServerServiceAccount.strings.psd1 +++ b/DSCResources/MSFT_SqlServiceAccount/en-US/MSFT_SqlServiceAccount.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for xSQLServerServiceAccount +# Localized resources for SqlServiceAccount ConvertFrom-StringData @' ForceServiceAccountUpdate = Force specified, skipping tests. With this configuration, Test-TargetResource will always return 'False'. diff --git a/DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.psm1 b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 similarity index 99% rename from DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.psm1 rename to DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 index 7f9cbbf2b..6685b9c03 100644 --- a/DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.psm1 +++ b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 @@ -1,10 +1,10 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') + -ChildPath 'SqlServerDscHelper.psm1') Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xSQLServerSetup' +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlSetup' <# .SYNOPSIS diff --git a/DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.schema.mof b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.schema.mof similarity index 98% rename from DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.schema.mof rename to DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.schema.mof index 18ae419a0..b937d47af 100644 --- a/DSCResources/MSFT_xSQLServerSetup/MSFT_xSQLServerSetup.schema.mof +++ b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerSetup")] -class MSFT_xSQLServerSetup : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlSetup")] +class MSFT_SqlSetup : OMI_BaseResource { [Write, Description("The action to be performed. Default value is 'Install'."), ValueMap{"Install","InstallFailoverCluster","AddNode","PrepareFailoverCluster","CompleteFailoverCluster"}, Values{"Install","InstallFailoverCluster","AddNode","PrepareFailoverCluster","CompleteFailoverCluster"}] String Action; [Write, Description("The path to the root of the source files for installation. I.e and UNC path to a shared resource. Environment variables can be used in the path.")] String SourcePath; diff --git a/DSCResources/MSFT_xSQLServerSetup/en-US/MSFT_xSQLServerSetup.strings.psd1 b/DSCResources/MSFT_SqlSetup/en-US/MSFT_SqlSetup.strings.psd1 similarity index 99% rename from DSCResources/MSFT_xSQLServerSetup/en-US/MSFT_xSQLServerSetup.strings.psd1 rename to DSCResources/MSFT_SqlSetup/en-US/MSFT_SqlSetup.strings.psd1 index 98a2174af..9530fcfbf 100644 --- a/DSCResources/MSFT_xSQLServerSetup/en-US/MSFT_xSQLServerSetup.strings.psd1 +++ b/DSCResources/MSFT_SqlSetup/en-US/MSFT_SqlSetup.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for xSQLServerSetup +# Localized resources for SqlSetup ConvertFrom-StringData @' UsingPath = Using path '{0}'. diff --git a/DSCResources/MSFT_xSQLServerSetup/sv-SE/MSFT_xSQLServerSetup.strings.psd1 b/DSCResources/MSFT_SqlSetup/sv-SE/MSFT_SqlSetup.strings.psd1 similarity index 99% rename from DSCResources/MSFT_xSQLServerSetup/sv-SE/MSFT_xSQLServerSetup.strings.psd1 rename to DSCResources/MSFT_SqlSetup/sv-SE/MSFT_SqlSetup.strings.psd1 index 2011dec31..ed61272c7 100644 --- a/DSCResources/MSFT_xSQLServerSetup/sv-SE/MSFT_xSQLServerSetup.strings.psd1 +++ b/DSCResources/MSFT_SqlSetup/sv-SE/MSFT_SqlSetup.strings.psd1 @@ -1,4 +1,4 @@ -# Swedish localized resources for xSQLServerSetup +# Swedish localized resources for SqlSetup ConvertFrom-StringData @' UsingPath = Använder sökväg '{0}'. diff --git a/DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.psm1 b/DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.psm1 similarity index 99% rename from DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.psm1 rename to DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.psm1 index e69cd82b6..253dd405e 100644 --- a/DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.psm1 +++ b/DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.psm1 @@ -1,5 +1,5 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` - -ChildPath 'xSQLServerHelper.psm1') ` + -ChildPath 'SqlServerDscHelper.psm1') ` -Force <# diff --git a/DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.schema.mof b/DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.schema.mof similarity index 85% rename from DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.schema.mof rename to DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.schema.mof index 1562c36ef..759e43071 100644 --- a/DSCResources/MSFT_xWaitForAvailabilityGroup/MSFT_xWaitForAvailabilityGroup.schema.mof +++ b/DSCResources/MSFT_SqlWaitForAG/MSFT_SqlWaitForAG.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xWaitForAvailabilityGroup")] -class MSFT_xWaitForAvailabilityGroup : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlWaitForAG")] +class MSFT_SqlWaitForAG : OMI_BaseResource { [Key, Description("Name of the cluster role/group to look for (normally the same as the Availability Group name).")] String Name; [Write, Description("The interval, in seconds, to check for the presence of the cluster role/group. Default value is 20 seconds. When the cluster role/group has been found the resource will wait for this amount of time once more before returning.")] Uint64 RetryIntervalSec; diff --git a/DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.psm1 b/DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.psm1 similarity index 99% rename from DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.psm1 rename to DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.psm1 index 4f47d5100..bdd0037a3 100644 --- a/DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.psm1 +++ b/DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.psm1 @@ -1,5 +1,5 @@ $script:currentPath = Split-Path -Path $MyInvocation.MyCommand.Path -Parent -Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $script:currentPath -Parent) -Parent) -ChildPath 'xSQLServerHelper.psm1') +Import-Module -Name (Join-Path -Path (Split-Path -Path (Split-Path -Path $script:currentPath -Parent) -Parent) -ChildPath 'SqlServerDscHelper.psm1') <# .SYNOPSIS diff --git a/DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.schema.mof b/DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.schema.mof similarity index 91% rename from DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.schema.mof rename to DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.schema.mof index 8879b0459..3a189fb47 100644 --- a/DSCResources/MSFT_xSQLServerFirewall/MSFT_xSQLServerFirewall.schema.mof +++ b/DSCResources/MSFT_SqlWindowsFirewall/MSFT_SqlWindowsFirewall.schema.mof @@ -1,5 +1,5 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xSQLServerFirewall")] -class MSFT_xSQLServerFirewall : OMI_BaseResource +[ClassVersion("1.0.0.0"), FriendlyName("SqlWindowsFirewall")] +class MSFT_SqlWindowsFirewall : OMI_BaseResource { [Write, Description("An enumerated value that describes if the SQL firewall rules are is expected to be enabled on the machine.\nPresent {default} \nAbsent \n"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("UNC path to the root of the source files for installation.")] String SourcePath; diff --git a/Examples/DSCClusterSqlBuild.ps1 b/Examples/DSCClusterSqlBuild.ps1 index 68510a11e..2c854622b 100644 --- a/Examples/DSCClusterSqlBuild.ps1 +++ b/Examples/DSCClusterSqlBuild.ps1 @@ -1,4 +1,14 @@ -#requires -Version 5 +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> $StartTime = [System.Diagnostics.Stopwatch]::StartNew() Function check-even($num){[bool]!($num%2)} @@ -36,7 +46,7 @@ foreach ($computer in $computers) Configuration AlwaysOnCluster { Import-DscResource –Module PSDesiredStateConfiguration - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC Import-DscResource -Module xFailoverCluster Node $AllNodes.Where{$_.Role -eq "PrimaryClusterNode" }.NodeName @@ -88,7 +98,7 @@ Configuration AlwaysOnCluster DependsOn = '[WindowsFeature]NET' } - xSqlServerFirewall ($Node.NodeName) + SqlWindowsFirewall ($Node.NodeName) { SourcePath = $Node.SourcePath InstanceName = $Node.InstanceName @@ -97,7 +107,7 @@ Configuration AlwaysOnCluster DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMemory ($Node.Nodename) + SqlServerMemory ($Node.Nodename) { Ensure = "Present" DynamicAlloc = $True @@ -105,7 +115,7 @@ Configuration AlwaysOnCluster DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMaxDop($Node.Nodename) + SqlServerMaxDop($Node.Nodename) { Ensure = "Present" DynamicAlloc = $true @@ -154,14 +164,14 @@ Configuration AlwaysOnCluster DependsOn = “[WindowsFeature]RSATClusteringCmdInterface” } - xSQLServerAlwaysOnService($Node.Nodename) + SqlAlwaysOnService($Node.Nodename) { Ensure = "Present" DependsOn = ("[xCluster]ensureCreated"),("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerEndpoint($Node.Nodename) + SqlServerEndpoint($Node.Nodename) { Ensure = "Present" Port = 5022 @@ -179,7 +189,7 @@ Configuration AlwaysOnCluster AvailabilityGroupSubMask ="255.255.255.0" SetupCredential = $Node.InstallerServiceAccount PsDscRunAsCredential = $Node.InstallerServiceAccount - DependsOn = ("[xSQLServerEndpoint]" + $Node.NodeName),("[xSQLServerAlwaysOnService]" + $Node.NodeName),("[WindowsFeature]ADTools") + DependsOn = ("[SqlServerEndpoint]" + $Node.NodeName),("[SqlAlwaysOnService]" + $Node.NodeName),("[WindowsFeature]ADTools") } } Node $AllNodes.Where{$_.Role -eq "ReplicaServerNode" }.NodeName @@ -224,7 +234,7 @@ Configuration AlwaysOnCluster DependsOn = '[WindowsFeature]NET' } - xSqlServerFirewall ($Node.NodeName) + SqlWindowsFirewall ($Node.NodeName) { SourcePath = $Node.SourcePath InstanceName = $Node.InstanceName @@ -233,14 +243,14 @@ Configuration AlwaysOnCluster DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMemory ($Node.Nodename) + SqlServerMemory ($Node.Nodename) { Ensure = "Present" DynamicAlloc = $True DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMaxDop($Node.Nodename) + SqlServerMaxDop($Node.Nodename) { Ensure = "Present" DynamicAlloc = $true @@ -299,13 +309,13 @@ Configuration AlwaysOnCluster DependsOn = "[xWaitForCluster]waitForCluster" } - xSQLServerAlwaysOnService($Node.Nodename) + SqlAlwaysOnService($Node.Nodename) { Ensure = "Present" DependsOn = ("[xCluster]joinCluster"),("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerEndpoint($Node.Nodename) + SqlServerEndpoint($Node.Nodename) { Ensure = "Present" Port = 5022 @@ -314,13 +324,13 @@ Configuration AlwaysOnCluster DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xWaitForAvailabilityGroup waitforAG + SqlWaitForAG waitforAG { Name = "MyAG" RetryIntervalSec = 20 RetryCount = 6 - DependsOn = (“[xSQLServerEndpoint]" +$Node.Nodename),(“[xSQLServerAlwaysOnService]" +$Node.Nodename) + DependsOn = (“[SqlServerEndpoint]" +$Node.Nodename),(“[SqlServerAlwaysOnService]" +$Node.Nodename) } xSQLAOGroupJoin ($Node.Nodename) @@ -330,7 +340,7 @@ Configuration AlwaysOnCluster SetupCredential = $Node.InstallerServiceAccount PsDscRunAsCredential = $Node.InstallerServiceAccount - DependsOn = ("[xWaitForAvailabilityGroup]waitforAG") + DependsOn = ("[SqlWaitForAG]waitforAG") } } @@ -412,4 +422,3 @@ Workflow TestConfigs TestConfigs -computers $computers #> - diff --git a/Examples/DSCFCISqlBuild.ps1 b/Examples/DSCFCISqlBuild.ps1 index 928963efa..063859c04 100644 --- a/Examples/DSCFCISqlBuild.ps1 +++ b/Examples/DSCFCISqlBuild.ps1 @@ -1,11 +1,21 @@ -#requires -Version 5 +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> $computers = 'OHSQL9034N1','OHSQL9034N2','OHSQL9034N3' $OutputPath = 'F:\DSCConfig' Configuration FCISQL { Import-DscResource –Module PSDesiredStateConfiguration - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC Import-DscResource -Module xFailoverCluster Node $AllNodes.NodeName @@ -64,7 +74,7 @@ Configuration FCISQL SQLSvcAccount = $Node.InstallerServiceAccount } - xSqlServerFirewall "FirewallMSSQLSERVER" + SqlWindowsFirewall "FirewallMSSQLSERVER" { DependsOn = "[xSQLServerFailoverClusterSetup]PrepareMSSQLSERVER" SourcePath = $Node.SourcePath @@ -212,4 +222,3 @@ Workflow StartConfigs } StartConfigs -Computers $computers -Path $OutputPath - diff --git a/Examples/DSCSQLBuildEncrypted.ps1 b/Examples/DSCSQLBuildEncrypted.ps1 index 2038c6e92..cd5bf924d 100644 --- a/Examples/DSCSQLBuildEncrypted.ps1 +++ b/Examples/DSCSQLBuildEncrypted.ps1 @@ -1,4 +1,14 @@ -#requires -Version 5 +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> $StartTime = [System.Diagnostics.Stopwatch]::StartNew() $computers = 'OHSQL9012' @@ -70,7 +80,7 @@ foreach ($computer in $computers) Configuration SQLBuild { Import-DscResource –Module PSDesiredStateConfiguration - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC Node $AllNodes.NodeName { @@ -106,7 +116,7 @@ Configuration SQLBuild SQLTempDBLogDir = "L:\MSSQL\Data" SQLBackupDir = "G:\MSSQL\Backup" } - xSqlServerFirewall ($Node.NodeName) + SqlWindowsFirewall ($Node.NodeName) { SourcePath = $Node.SourcePath InstanceName = $Node.InstanceName @@ -115,14 +125,14 @@ Configuration SQLBuild DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMemory ($Node.Nodename) + SqlServerMemory ($Node.Nodename) { Ensure = "Present" DynamicAlloc = $True DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMaxDop($Node.Nodename) + SqlServerMaxDop($Node.Nodename) { Ensure = "Present" DynamicAlloc = $true diff --git a/Examples/DSCSqlBuild.ps1 b/Examples/DSCSqlBuild.ps1 index 360db5c55..0bca03f86 100644 --- a/Examples/DSCSqlBuild.ps1 +++ b/Examples/DSCSqlBuild.ps1 @@ -1,4 +1,14 @@ -#requires -Version 5 +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> $StartTime = [System.Diagnostics.Stopwatch]::StartNew() $computers = 'OHSQL9015' @@ -35,7 +45,7 @@ foreach ($computer in $computers) Configuration SQLBuild { Import-DscResource –ModuleName PSDesiredStateConfiguration - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDSC Node $AllNodes.NodeName @@ -88,7 +98,7 @@ Configuration SQLBuild DependsOn = '[WindowsFeature]NET' } - xSqlServerFirewall ($Node.NodeName) + SqlWindowsFirewall ($Node.NodeName) { SourcePath = $Node.SourcePath InstanceName = $Node.InstanceName @@ -97,14 +107,14 @@ Configuration SQLBuild DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMemory ($Node.Nodename) + SqlServerMemory ($Node.Nodename) { Ensure = "Present" DynamicAlloc = $True DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) } - xSQLServerMaxDop($Node.Nodename) + SqlServerMaxDop($Node.Nodename) { Ensure = "Present" DynamicAlloc = $true @@ -113,7 +123,7 @@ Configuration SQLBuild } } - xSQLServerEndpoint($Node.Nodename) + SqlServerEndpoint($Node.Nodename) { Ensure = "Present" Port = 5022 diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/1-CreateAvailabilityGroup.ps1 b/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 similarity index 63% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/1-CreateAvailabilityGroup.ps1 rename to Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 index 033e5f312..2fff9a6d0 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/1-CreateAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 @@ -6,8 +6,8 @@ $ConfigurationData = @{ AllNodes = @( @{ - NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + NodeName = '*' + InstanceName = 'MSSQLSERVER' }, @{ @@ -25,53 +25,53 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName - InstanceName = $Node.SqlInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' PsDscRunAsCredential = $SysAdminAccount } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/2-RemoveAvailabilityGroup.ps1 b/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 similarity index 72% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/2-RemoveAvailabilityGroup.ps1 rename to Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 index 719f450a9..d41c2352a 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/2-RemoveAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 @@ -6,8 +6,8 @@ This example shows how to ensure that the Availability Group 'TestAG' does not e $ConfigurationData = @{ AllNodes = @( @{ - NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + NodeName = '*' + InstanceName = 'MSSQLSERVER' }, @{ @@ -25,18 +25,18 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup RemoveTestAG + SqlAG RemoveTestAG { Ensure = 'Absent' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/3-CreateAvailabilityGroupDetailed.ps1 b/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 similarity index 75% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/3-CreateAvailabilityGroupDetailed.ps1 rename to Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 index 51ddbe8ee..b53a47d6c 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/3-CreateAvailabilityGroupDetailed.ps1 +++ b/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 @@ -12,7 +12,7 @@ $ConfigurationData = @{ AllNodes = @( @{ NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + InstanceName = 'MSSQLSERVER' ProcessOnlyOnActiveNode = $true AutomatedBackupPreference = 'Primary' @@ -29,8 +29,8 @@ $ConfigurationData = @{ }, @{ - NodeName = 'SP23-VM-SQL1' - Role = 'PrimaryReplica' + NodeName = 'SP23-VM-SQL1' + Role = 'PrimaryReplica' } ) } @@ -43,52 +43,52 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName - InstanceName = $Node.SqlInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' PsDscRunAsCredential = $SysAdminAccount } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode AutomatedBackupPreference = $Node.AutomatedBackupPreference @@ -104,7 +104,7 @@ Configuration Example DatabaseHealthTrigger = $Node.DatabaseHealthTrigger DtcSupportEnabled = $Node.DtcSupportEnabled - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/1-AddDatabasesToAvailabilityGroup.ps1 b/Examples/Resources/SqlAGDatabase/1-AddDatabaseToAvailabilityGroup.ps1 similarity index 63% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/1-AddDatabasesToAvailabilityGroup.ps1 rename to Examples/Resources/SqlAGDatabase/1-AddDatabaseToAvailabilityGroup.ps1 index b2869c583..a2bd11c35 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/1-AddDatabasesToAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAGDatabase/1-AddDatabaseToAvailabilityGroup.ps1 @@ -36,26 +36,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -63,26 +63,26 @@ Configuration Example } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = $Node.AvailabilityGroupName - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } @@ -90,27 +90,27 @@ Configuration Example if ( $Node.Role -eq 'SecondaryReplica' ) { # Add the availability group replica to the availability group - xSQLServerAlwaysOnAvailabilityGroupReplica AddReplica + SqlAGReplica AddReplica { - Ensure = 'Present' - Name = $Node.NodeName - AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName - PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName - PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName + Ensure = 'Present' + Name = $Node.NodeName + AvailabilityGroupName = $Node.AvailabilityGroupName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName + PrimaryReplicaServerName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName + PrimaryReplicaInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName } } if ( $Node.Role -eq 'PrimaryReplica' ) { - xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership 'TestAGDatabaseMemberships' + SqlAGDatabase 'TestAGDatabaseMemberships' { AvailabilityGroupName = $Node.AvailabilityGroupName BackupPath = '\\SQL1\AgInitialize' DatabaseName = 'DB*', 'AdventureWorks' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName Ensure = 'Present' ProcessOnlyOnActiveNode = $true PsDscRunAsCredential = $SysAdminAccount diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/2-RemoveDatabasesFromAvailabilityGroup.ps1 b/Examples/Resources/SqlAGDatabase/2-RemoveDatabaseFromAvailabilityGroup.ps1 similarity index 60% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/2-RemoveDatabasesFromAvailabilityGroup.ps1 rename to Examples/Resources/SqlAGDatabase/2-RemoveDatabaseFromAvailabilityGroup.ps1 index 1af3cd0b7..ee99f9e80 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/2-RemoveDatabasesFromAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAGDatabase/2-RemoveDatabaseFromAvailabilityGroup.ps1 @@ -31,26 +31,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -58,26 +58,26 @@ Configuration Example } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = $Node.AvailabilityGroupName - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } @@ -85,27 +85,27 @@ Configuration Example if ( $Node.Role -eq 'SecondaryReplica' ) { # Add the availability group replica to the availability group - xSQLServerAlwaysOnAvailabilityGroupReplica AddReplica + SqlAGReplica AddReplica { - Ensure = 'Present' - Name = $Node.NodeName - AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName - PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName - PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName + Ensure = 'Present' + Name = $Node.NodeName + AvailabilityGroupName = $Node.AvailabilityGroupName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName + PrimaryReplicaServerName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName + PrimaryReplicaInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName } } if ( $Node.Role -eq 'PrimaryReplica' ) { - xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership 'TestAGDatabaseMemberships' + SqlAGDatabase 'TestAGDatabaseMemberships' { AvailabilityGroupName = $Node.AvailabilityGroupName BackupPath = '\\SQL1\AgInitialize' DatabaseName = 'DB*', 'AdventureWorks' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName Ensure = 'Absent' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/3-MatchDefinedDatabasesInAvailabilityGroup.ps1 b/Examples/Resources/SqlAGDatabase/3-MatchDefinedDatabaseInAvailabilityGroup.ps1 similarity index 60% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/3-MatchDefinedDatabasesInAvailabilityGroup.ps1 rename to Examples/Resources/SqlAGDatabase/3-MatchDefinedDatabaseInAvailabilityGroup.ps1 index a2039e006..fe7e3aa1b 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership/3-MatchDefinedDatabasesInAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAGDatabase/3-MatchDefinedDatabaseInAvailabilityGroup.ps1 @@ -31,26 +31,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -58,26 +58,26 @@ Configuration Example } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = $Node.AvailabilityGroupName - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } @@ -85,27 +85,27 @@ Configuration Example if ( $Node.Role -eq 'SecondaryReplica' ) { # Add the availability group replica to the availability group - xSQLServerAlwaysOnAvailabilityGroupReplica AddReplica + SqlAGReplica AddReplica { - Ensure = 'Present' - Name = $Node.NodeName - AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName - PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName - PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName + Ensure = 'Present' + Name = $Node.NodeName + AvailabilityGroupName = $Node.AvailabilityGroupName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName + PrimaryReplicaServerName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName + PrimaryReplicaInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName } } if ( $Node.Role -eq 'PrimaryReplica' ) { - xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership 'TestAGDatabaseMemberships' + SqlAGDatabase 'TestAGDatabaseMemberships' { AvailabilityGroupName = $Node.AvailabilityGroupName BackupPath = '\\SQL1\AgInitialize' DatabaseName = 'DB*', 'AdventureWorks' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName Ensure = 'Present' Force = $true PsDscRunAsCredential = $SysAdminAccount diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 b/Examples/Resources/SqlAGListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 similarity index 78% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 rename to Examples/Resources/SqlAGListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 index d93ac05ee..40383be59 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 +++ b/Examples/Resources/SqlAGListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener AvailabilityGroupListenerWithSameNameAsVCO + SqlAGListener AvailabilityGroupListenerWithSameNameAsVCO { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AG-01' Name = 'AG-01' diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 b/Examples/Resources/SqlAGListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 similarity index 78% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 rename to Examples/Resources/SqlAGListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 index 1d052e55d..7e09db5e0 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 +++ b/Examples/Resources/SqlAGListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener AvailabilityGroupListenerWithDifferentNameAsVCO + SqlAGListener AvailabilityGroupListenerWithDifferentNameAsVCO { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AvailabilityGroup-01' Name = 'AG-01' diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 b/Examples/Resources/SqlAGListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 similarity index 75% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 rename to Examples/Resources/SqlAGListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 index 712418e7e..a1f54f65b 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 +++ b/Examples/Resources/SqlAGListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener RemoveAvailabilityGroupListenerWithDifferentNameAsVCO + SqlAGListener RemoveAvailabilityGroupListenerWithDifferentNameAsVCO { Ensure = 'Absent' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AvailabilityGroup-01' Name = 'AG-01' diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 b/Examples/Resources/SqlAGListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 similarity index 75% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 rename to Examples/Resources/SqlAGListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 index e20f3b591..aeba220af 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 +++ b/Examples/Resources/SqlAGListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener RemoveAvailabilityGroupListenerWithSameNameAsVCO + SqlAGListener RemoveAvailabilityGroupListenerWithSameNameAsVCO { Ensure = 'Absent' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AG-01' Name = "AG-01" diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 b/Examples/Resources/SqlAGListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 similarity index 80% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 rename to Examples/Resources/SqlAGListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 index 64fc72568..ea373748b 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 +++ b/Examples/Resources/SqlAGListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener AvailabilityGroupListenerWithSameNameAsVCO + SqlAGListener AvailabilityGroupListenerWithSameNameAsVCO { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AG-01' Name = 'AG-01' diff --git a/Examples/Resources/xSQLServerAvailabilityGroupListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 b/Examples/Resources/SqlAGListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 similarity index 79% rename from Examples/Resources/xSQLServerAvailabilityGroupListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 rename to Examples/Resources/SqlAGListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 index b547ff066..34102d7e3 100644 --- a/Examples/Resources/xSQLServerAvailabilityGroupListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 +++ b/Examples/Resources/SqlAGListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1 @@ -12,14 +12,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAvailabilityGroupListener AvailabilityGroupListenerWithSameNameAsVCO + SqlAGListener AvailabilityGroupListenerWithSameNameAsVCO { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' AvailabilityGroup = 'AG-01' Name = 'AG-01' diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/1-CreateAvailabilityGroupReplica.ps1 b/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 similarity index 61% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/1-CreateAvailabilityGroupReplica.ps1 rename to Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 index 05805026e..e0cd7dad3 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/1-CreateAvailabilityGroupReplica.ps1 +++ b/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 @@ -38,26 +38,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -65,26 +65,26 @@ Configuration Example } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = $Node.AvailabilityGroupName - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } @@ -92,16 +92,16 @@ Configuration Example if ( $Node.Role -eq 'SecondaryReplica' ) { # Add the availability group replica to the availability group - xSQLServerAlwaysOnAvailabilityGroupReplica AddReplica + SqlAGReplica AddReplica { - Ensure = 'Present' - Name = $Node.NodeName - AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName - PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName - PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName - ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode + Ensure = 'Present' + Name = $Node.NodeName + AvailabilityGroupName = $Node.AvailabilityGroupName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName + PrimaryReplicaServerName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName + PrimaryReplicaInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName + ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode } } } diff --git a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/2-RemoveAvailabilityGroupReplica.ps1 b/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 similarity index 59% rename from Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/2-RemoveAvailabilityGroupReplica.ps1 rename to Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 index 3634f7f50..99b701aa9 100644 --- a/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/2-RemoveAvailabilityGroupReplica.ps1 +++ b/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 @@ -31,26 +31,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node $AllNodes.NodeName { # Adding the required service account to allow the cluster to log into SQL - xSQLServerLogin AddNTServiceClusSvc + SqlServerLogin AddNTServiceClusSvc { Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } # Add the required permissions to the cluster service login - xSQLServerPermission AddNTServiceClusSvcPermissions + SqlServerPermission AddNTServiceClusSvcPermissions { - DependsOn = '[xSQLServerLogin]AddNTServiceClusSvc' + DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -58,26 +58,26 @@ Configuration Example } # Create a DatabaseMirroring endpoint - xSQLServerEndpoint HADREndpoint + SqlServerEndpoint HADREndpoint { EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PsDscRunAsCredential = $SysAdminAccount } if ( $Node.Role -eq 'PrimaryReplica' ) { # Create the availability group on the instance tagged as the primary replica - xSQLServerAlwaysOnAvailabilityGroup AddTestAG + SqlAG AddTestAG { Ensure = 'Present' Name = $Node.AvailabilityGroupName - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName - DependsOn = '[xSQLServerEndpoint]HADREndpoint', '[xSQLServerPermission]AddNTServiceClusSvcPermissions' + InstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } } @@ -85,15 +85,15 @@ Configuration Example if ( $Node.Role -eq 'SecondaryReplica' ) { # Add the availability group replica to the availability group - xSQLServerAlwaysOnAvailabilityGroupReplica AddReplica + SqlAGReplica AddReplica { - Ensure = 'Absent' - Name = $Node.NodeName - AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName - PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName - PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName + Ensure = 'Absent' + Name = $Node.NodeName + AvailabilityGroupName = $Node.AvailabilityGroupName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName + PrimaryReplicaServerName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName + PrimaryReplicaInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName } } } diff --git a/Examples/Resources/xSQLServerAlias/1-AddSQLServerAlias.ps1 b/Examples/Resources/SqlAlias/1-AddSqlAlias.ps1 similarity index 73% rename from Examples/Resources/xSQLServerAlias/1-AddSQLServerAlias.ps1 rename to Examples/Resources/SqlAlias/1-AddSqlAlias.ps1 index 9654e65ec..fc1b270bf 100644 --- a/Examples/Resources/xSQLServerAlias/1-AddSQLServerAlias.ps1 +++ b/Examples/Resources/SqlAlias/1-AddSqlAlias.ps1 @@ -12,34 +12,34 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAlias Add_SqlAlias_TCP + SqlAlias Add_SqlAlias_TCP { Ensure = 'Present' Name = 'SQLDSC-TCP' - ServerName = "SQLServer\DSC" + ServerName = 'sqltest.company.local\DSC' Protocol = 'TCP' TcpPort = 1777 PsDscRunAsCredential = $SysAdminAccount } - xSQLServerAlias Add_SqlAlias_TCPUseDynamicTcpPort + SqlAlias Add_SqlAlias_TCPUseDynamicTcpPort { Ensure = 'Present' Name = 'SQLDSC-DYN' - ServerName = "SQLServer\DSC" + ServerName = 'sqltest.company.local\DSC' Protocol = 'TCP' UseDynamicTcpPort = $true PsDscRunAsCredential = $SysAdminAccount } - xSQLServerAlias Add_SqlAlias_NP + SqlAlias Add_SqlAlias_NP { Ensure = 'Present' Name = 'SQLDSC-NP' - ServerName = "\\sqlnode\PIPE\sql\query" + ServerName = '\\sqlnode\PIPE\sql\query' Protocol = 'NP' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerAlias/2-RemoveSQLServerAlias.ps1 b/Examples/Resources/SqlAlias/2-RemoveSqlAlias.ps1 similarity index 74% rename from Examples/Resources/xSQLServerAlias/2-RemoveSQLServerAlias.ps1 rename to Examples/Resources/SqlAlias/2-RemoveSqlAlias.ps1 index 986105874..ed9de5eea 100644 --- a/Examples/Resources/xSQLServerAlias/2-RemoveSQLServerAlias.ps1 +++ b/Examples/Resources/SqlAlias/2-RemoveSqlAlias.ps1 @@ -12,24 +12,24 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAlias Remove_SqlAlias_TCP + SqlAlias Remove_SqlAlias_TCP { Ensure = 'Absent' Name = 'SQLDSC-TCP' - ServerName = "SQLServer\DSC" + ServerName = 'sqltest.company.local\DSC' Protocol = 'TCP' TcpPort = 1777 PsDscRunAsCredential = $SysAdminAccount } - xSQLServerAlias Remove_SqlAlias_NP + SqlAlias Remove_SqlAlias_NP { Ensure = 'Absent' Name = 'SQLDSC-NP' - ServerName = "\\sqlnode\PIPE\sql\query" + ServerName = '\\sqlnode\PIPE\sql\query' Protocol = 'NP' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerAlwaysOnService/1-EnableAlwaysOn.ps1 b/Examples/Resources/SqlAlwaysOnService/1-EnableAlwaysOn.ps1 similarity index 73% rename from Examples/Resources/xSQLServerAlwaysOnService/1-EnableAlwaysOn.ps1 rename to Examples/Resources/SqlAlwaysOnService/1-EnableAlwaysOn.ps1 index 9bc907218..2846902bf 100644 --- a/Examples/Resources/xSQLServerAlwaysOnService/1-EnableAlwaysOn.ps1 +++ b/Examples/Resources/SqlAlwaysOnService/1-EnableAlwaysOn.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAlwaysOnService 'EnableAlwaysOn' + SqlAlwaysOnService 'EnableAlwaysOn' { Ensure = 'Present' - SQLServer = 'SP23-VM-SQL1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'SP23-VM-SQL1' + InstanceName = 'MSSQLSERVER' RestartTimeout = 120 PsDscRunAsCredential = $SysAdminAccount diff --git a/Examples/Resources/xSQLServerAlwaysOnService/2-DisableAlwaysOn.ps1 b/Examples/Resources/SqlAlwaysOnService/2-DisableAlwaysOn.ps1 similarity index 72% rename from Examples/Resources/xSQLServerAlwaysOnService/2-DisableAlwaysOn.ps1 rename to Examples/Resources/SqlAlwaysOnService/2-DisableAlwaysOn.ps1 index 9d45fab51..311d116fb 100644 --- a/Examples/Resources/xSQLServerAlwaysOnService/2-DisableAlwaysOn.ps1 +++ b/Examples/Resources/SqlAlwaysOnService/2-DisableAlwaysOn.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerAlwaysOnService 'DisableAlwaysOn' + SqlAlwaysOnService 'DisableAlwaysOn' { Ensure = 'Absent' - SQLServer = 'SP23-VM-SQL1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'SP23-VM-SQL1' + InstanceName = 'MSSQLSERVER' RestartTimeout = 120 PsDscRunAsCredential = $SysAdminAccount diff --git a/Examples/Resources/SqlDatabase/1-CreateDatabase.ps1 b/Examples/Resources/SqlDatabase/1-CreateDatabase.ps1 new file mode 100644 index 000000000..97dd3f43d --- /dev/null +++ b/Examples/Resources/SqlDatabase/1-CreateDatabase.ps1 @@ -0,0 +1,40 @@ +<# +.EXAMPLE + This example shows how to create a database with + the database name equal to 'Contoso'. + + The second example shows how to create a database + with a different collation. +#> +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + [System.Management.Automation.Credential()] + $SysAdminAccount + ) + + Import-DscResource -ModuleName SqlServerDsc + + node localhost + { + SqlDatabase Create_Database + { + Ensure = 'Present' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + Name = 'Contoso' + } + + SqlDatabase Create_Database_with_different_collation + { + Ensure = 'Present' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + Name = 'AdventureWorks' + Collation = 'SQL_Latin1_General_Pref_CP850_CI_AS' + } + } +} diff --git a/Examples/Resources/xSQLServerDatabase/2-DeleteDatabase.ps1 b/Examples/Resources/SqlDatabase/2-DeleteDatabase.ps1 similarity index 60% rename from Examples/Resources/xSQLServerDatabase/2-DeleteDatabase.ps1 rename to Examples/Resources/SqlDatabase/2-DeleteDatabase.ps1 index 34bbca64e..d85ec08a1 100644 --- a/Examples/Resources/xSQLServerDatabase/2-DeleteDatabase.ps1 +++ b/Examples/Resources/SqlDatabase/2-DeleteDatabase.ps1 @@ -13,16 +13,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerDatabase Delete_Database + SqlDatabase Delete_Database { - Ensure = 'Absent' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - Name = 'AdventureWorks' + Ensure = 'Absent' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + Name = 'AdventureWorks' } } } diff --git a/Examples/Resources/SqlDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 b/Examples/Resources/SqlDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 new file mode 100644 index 000000000..3e558c06d --- /dev/null +++ b/Examples/Resources/SqlDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 @@ -0,0 +1,53 @@ +<# +.EXAMPLE + This example shows how to manage database default locations for Data, Logs, and Backups for SQL Server. + + In the event this is applied to a Failover Cluster Instance (FCI), the + ProcessOnlyOnActiveNode property will tell the Test-TargetResource function + to evaluate if any changes are needed if the node is actively hosting the + SQL Server Instance. +#> +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + $SysAdminAccount + ) + + Import-DscResource -ModuleName SqlServerDsc + + node localhost + { + SqlDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Data + { + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + ProcessOnlyOnActiveNode = $true + Type = 'Data' + Path = 'C:\Program Files\Microsoft SQL Server' + PsDscRunAsCredential = $SysAdminAccount + } + + SqlDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Log + { + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + ProcessOnlyOnActiveNode = $true + Type = 'Log' + Path = 'C:\Program Files\Microsoft SQL Server' + PsDscRunAsCredential = $SysAdminAccount + } + + SqlDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Backup + { + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' + ProcessOnlyOnActiveNode = $true + Type = 'Backup' + Path = 'C:\Program Files\Microsoft SQL Server' + PsDscRunAsCredential = $SysAdminAccount + } + } +} diff --git a/Examples/Resources/xSQLServerDatabaseOwner/1-SetDatabaseOwner.ps1 b/Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1 similarity index 69% rename from Examples/Resources/xSQLServerDatabaseOwner/1-SetDatabaseOwner.ps1 rename to Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1 index 6b6e00794..3c1386778 100644 --- a/Examples/Resources/xSQLServerDatabaseOwner/1-SetDatabaseOwner.ps1 +++ b/Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1 @@ -13,26 +13,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerLogin Add_SqlServerLogin_SQLAdmin + SqlServerLogin Add_SqlServerLogin_SQLAdmin { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabaseOwner Set_SqlDatabaseOwner_SQLAdmin + SqlDatabaseOwner Set_SqlDatabaseOwner_SQLAdmin { Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorks' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerDatabasePermission/1-GrantDatabasePermissions.ps1 b/Examples/Resources/SqlDatabasePermission/1-GrantDatabasePermissions.ps1 similarity index 66% rename from Examples/Resources/xSQLServerDatabasePermission/1-GrantDatabasePermissions.ps1 rename to Examples/Resources/SqlDatabasePermission/1-GrantDatabasePermissions.ps1 index 209b22059..f680ab17b 100644 --- a/Examples/Resources/xSQLServerDatabasePermission/1-GrantDatabasePermissions.ps1 +++ b/Examples/Resources/SqlDatabasePermission/1-GrantDatabasePermissions.ps1 @@ -12,62 +12,62 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerLogin Add_SqlServerLogin_SQLAdmin + SqlServerLogin Add_SqlServerLogin_SQLAdmin { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerLogin Add_SqlServerLogin_SQLUser + SqlServerLogin Add_SqlServerLogin_SQLUser { Ensure = 'Present' Name = 'CONTOSO\SQLUser' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Grant_SqlDatabasePermissions_SQLAdmin_Db01 + SqlDatabasePermission Grant_SqlDatabasePermissions_SQLAdmin_Db01 { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorks' PermissionState = 'Grant' Permissions = 'Connect', 'Update' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Grant_SqlDatabasePermissions_SQLUser_Db01 + SqlDatabasePermission Grant_SqlDatabasePermissions_SQLUser_Db01 { Ensure = 'Present' Name = 'CONTOSO\SQLUser' Database = 'AdventureWorks' PermissionState = 'Grant' Permissions = 'Connect', 'Update' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Grant_SqlDatabasePermissions_SQLAdmin_Db02 + SqlDatabasePermission Grant_SqlDatabasePermissions_SQLAdmin_Db02 { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorksLT' PermissionState = 'Grant' Permissions = 'Connect', 'Update' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerDatabasePermission/2-RevokeDatabasePermissions.ps1 b/Examples/Resources/SqlDatabasePermission/2-RevokeDatabasePermissions.ps1 similarity index 71% rename from Examples/Resources/xSQLServerDatabasePermission/2-RevokeDatabasePermissions.ps1 rename to Examples/Resources/SqlDatabasePermission/2-RevokeDatabasePermissions.ps1 index 701fed79e..b451a5f0a 100644 --- a/Examples/Resources/xSQLServerDatabasePermission/2-RevokeDatabasePermissions.ps1 +++ b/Examples/Resources/SqlDatabasePermission/2-RevokeDatabasePermissions.ps1 @@ -12,30 +12,30 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerDatabasePermission RevokeGrant_SqlDatabasePermissions_SQLAdmin + SqlDatabasePermission RevokeGrant_SqlDatabasePermissions_SQLAdmin { Ensure = 'Absent' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorks' PermissionState = 'Grant' Permissions = 'Connect', 'Update' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission RevokeDeny_SqlDatabasePermissions_SQLAdmin + SqlDatabasePermission RevokeDeny_SqlDatabasePermissions_SQLAdmin { Ensure = 'Absent' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorks' PermissionState = 'Deny' Permissions = 'Select', 'Create Table' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerDatabasePermission/3-DenyDatabasePermissions.ps1 b/Examples/Resources/SqlDatabasePermission/3-DenyDatabasePermissions.ps1 similarity index 66% rename from Examples/Resources/xSQLServerDatabasePermission/3-DenyDatabasePermissions.ps1 rename to Examples/Resources/SqlDatabasePermission/3-DenyDatabasePermissions.ps1 index 940826148..e1c71c6aa 100644 --- a/Examples/Resources/xSQLServerDatabasePermission/3-DenyDatabasePermissions.ps1 +++ b/Examples/Resources/SqlDatabasePermission/3-DenyDatabasePermissions.ps1 @@ -12,62 +12,62 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerLogin Add_SqlServerLogin_SQLAdmin + SqlServerLogin Add_SqlServerLogin_SQLAdmin { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerLogin Add_SqlServerLogin_SQLUser + SqlServerLogin Add_SqlServerLogin_SQLUser { Ensure = 'Present' Name = 'CONTOSO\SQLUser' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Deny_SqlDatabasePermissions_SQLAdmin_Db01 + SqlDatabasePermission Deny_SqlDatabasePermissions_SQLAdmin_Db01 { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorks' PermissionState = 'Deny' Permissions = 'Select', 'Create Table' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Deny_SqlDatabasePermissions_SQLUser_Db01 + SqlDatabasePermission Deny_SqlDatabasePermissions_SQLUser_Db01 { Ensure = 'Present' Name = 'CONTOSO\SQLUser' Database = 'AdventureWorks' PermissionState = 'Deny' Permissions = 'Select', 'Create Table' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabasePermission Deny_SqlDatabasePermissions_SQLAdmin_Db02 + SqlDatabasePermission Deny_SqlDatabasePermissions_SQLAdmin_Db02 { Ensure = 'Present' Name = 'CONTOSO\SQLAdmin' Database = 'AdventureWorksLT' PermissionState = 'Deny' Permissions = 'Select', 'Create Table' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 b/Examples/Resources/SqlDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 similarity index 59% rename from Examples/Resources/xSQLServerDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 rename to Examples/Resources/SqlDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 index d8682edfc..5775490d6 100644 --- a/Examples/Resources/xSQLServerDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 +++ b/Examples/Resources/SqlDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1 @@ -14,43 +14,43 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerDatabase Add_SqlDatabaseAdventureworks + SqlDatabase Add_SqlDatabaseAdventureworks { Ensure = 'Present' Name = 'Adventureworks' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabase Add_SqlDatabaseAdventureWorks2012 + SqlDatabase Add_SqlDatabaseAdventureWorks2012 { Ensure = 'Present' Name = 'AdventureWorks2012' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabaseRecoveryModel Set_SqlDatabaseRecoveryModel_Adventureworks + SqlDatabaseRecoveryModel Set_SqlDatabaseRecoveryModel_Adventureworks { Name = 'Adventureworks' RecoveryModel = 'Full' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerDatabaseRecoveryModel Set_SqlDatabaseRecoveryModel_AdventureWorks2012 + SqlDatabaseRecoveryModel Set_SqlDatabaseRecoveryModel_AdventureWorks2012 { Name = 'AdventureWorks2012' RecoveryModel = 'Simple' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerDatabaseRole/1-AddDatabaseRole.ps1 b/Examples/Resources/SqlDatabaseRole/1-AddDatabaseRole.ps1 similarity index 78% rename from Examples/Resources/xSQLServerDatabaseRole/1-AddDatabaseRole.ps1 rename to Examples/Resources/SqlDatabaseRole/1-AddDatabaseRole.ps1 index b461a5bf2..f4d1e6ba3 100644 --- a/Examples/Resources/xSQLServerDatabaseRole/1-AddDatabaseRole.ps1 +++ b/Examples/Resources/SqlDatabaseRole/1-AddDatabaseRole.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerDatabaseRole Add_Database_Role + SqlDatabaseRole Add_Database_Role { Ensure = 'Present' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' Name = 'CONTOSO\SQLAdmin' Role = 'MyRole', 'MySecondRole' Database = 'AdventureWorks' diff --git a/Examples/Resources/xSQLServerDatabaseRole/2-RemoveDatabaseRole.ps1 b/Examples/Resources/SqlDatabaseRole/2-RemoveDatabaseRole.ps1 similarity index 77% rename from Examples/Resources/xSQLServerDatabaseRole/2-RemoveDatabaseRole.ps1 rename to Examples/Resources/SqlDatabaseRole/2-RemoveDatabaseRole.ps1 index 97e6a769a..184b76e7d 100644 --- a/Examples/Resources/xSQLServerDatabaseRole/2-RemoveDatabaseRole.ps1 +++ b/Examples/Resources/SqlDatabaseRole/2-RemoveDatabaseRole.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerDatabaseRole Remove_Database_Role + SqlDatabaseRole Remove_Database_Role { Ensure = 'Absent' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' Name = 'CONTOSO\SQLAdmin' Role = 'DeleteRole' Database = 'AdventureWorks' diff --git a/Examples/Resources/xSQLServerRSConfig/1-DefaultConfiguration.ps1 b/Examples/Resources/SqlRS/1-DefaultConfiguration.ps1 similarity index 59% rename from Examples/Resources/xSQLServerRSConfig/1-DefaultConfiguration.ps1 rename to Examples/Resources/SqlRS/1-DefaultConfiguration.ps1 index b780ed6b8..aca3839d1 100644 --- a/Examples/Resources/xSQLServerRSConfig/1-DefaultConfiguration.ps1 +++ b/Examples/Resources/SqlRS/1-DefaultConfiguration.ps1 @@ -1,22 +1,22 @@ -<# -.EXAMPLE - This example performs a default SSRS configuration. It will initialize SSRS - and register default Report Server Web Service and Report Manager URLs: - - http://localhost:80/ReportServer (Report Server Web Service) - - http://localhost:80/Reports (Report Manager) -#> -Configuration Example -{ - Import-DscResource -ModuleName xSqlServer - - node localhost { - xSQLServerRSConfig DefaultConfiguration - { - InstanceName = 'MSSQLSERVER' - RSSQLServer = 'localhost' - RSSQLInstanceName = 'MSSQLSERVER' - } - } -} +<# +.EXAMPLE + This example performs a default SSRS configuration. It will initialize SSRS + and register default Report Server Web Service and Report Manager URLs: + + http://localhost:80/ReportServer (Report Server Web Service) + + http://localhost:80/Reports (Report Manager) +#> +Configuration Example +{ + Import-DscResource -ModuleName SqlServerDsc + + node localhost { + SqlRS DefaultConfiguration + { + InstanceName = 'MSSQLSERVER' + DatabaseServerName = 'localhost' + DatabaseInstanceName = 'MSSQLSERVER' + } + } +} diff --git a/Examples/Resources/xSQLServerRSConfig/2-CustomConfiguration.ps1 b/Examples/Resources/SqlRS/2-CustomConfiguration.ps1 similarity index 56% rename from Examples/Resources/xSQLServerRSConfig/2-CustomConfiguration.ps1 rename to Examples/Resources/SqlRS/2-CustomConfiguration.ps1 index 2c616b763..094f1f78f 100644 --- a/Examples/Resources/xSQLServerRSConfig/2-CustomConfiguration.ps1 +++ b/Examples/Resources/SqlRS/2-CustomConfiguration.ps1 @@ -1,31 +1,31 @@ -<# -.EXAMPLE - This example performs a custom SSRS configuration. It will initialize SSRS - and register custom Report Server Web Service and Report Manager URLs: - - http://localhost:80/MyReportServer - https://localhost:443/MyReportServer (Report Server Web Service) - - http://localhost:80/MyReports - https://localhost:443/MyReports (Report Manager) - - Please note: this resource does not currently handle SSL bindings for HTTPS - endpoints. -#> -Configuration Example -{ - Import-DscResource -ModuleName xSqlServer - - node localhost { - xSQLServerRSConfig DefaultConfiguration - { - InstanceName = 'MSSQLSERVER' - RSSQLServer = 'localhost' - RSSQLInstanceName = 'MSSQLSERVER' - ReportServerVirtualDirectory = 'MyReportServer' - ReportsVirtualDirectory = 'MyReports' - ReportServerReservedUrl = @('http://+:80', 'https://+:443') - ReportsReservedUrl = @('http://+:80', 'https://+:443') - } - } -} +<# +.EXAMPLE + This example performs a custom SSRS configuration. It will initialize SSRS + and register custom Report Server Web Service and Report Manager URLs: + + http://localhost:80/MyReportServer + https://localhost:443/MyReportServer (Report Server Web Service) + + http://localhost:80/MyReports + https://localhost:443/MyReports (Report Manager) + + Please note: this resource does not currently handle SSL bindings for HTTPS + endpoints. +#> +Configuration Example +{ + Import-DscResource -ModuleName SqlServerDsc + + node localhost { + SqlRS DefaultConfiguration + { + InstanceName = 'MSSQLSERVER' + DatabaseServerName = 'localhost' + DatabaseInstanceName = 'MSSQLSERVER' + ReportServerVirtualDirectory = 'MyReportServer' + ReportsVirtualDirectory = 'MyReports' + ReportServerReservedUrl = @('http://+:80', 'https://+:443') + ReportsReservedUrl = @('http://+:80', 'https://+:443') + } + } +} diff --git a/Examples/Resources/xSQLServerScript/1-RunScriptUsingSQLAuthentication.ps1 b/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 similarity index 88% rename from Examples/Resources/xSQLServerScript/1-RunScriptUsingSQLAuthentication.ps1 rename to Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 index 659c076f4..ff0458a1a 100644 --- a/Examples/Resources/xSQLServerScript/1-RunScriptUsingSQLAuthentication.ps1 +++ b/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1 @@ -11,11 +11,11 @@ Configuration Example $SqlCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc Node localhost { - xSQLServerScript 'RunSQLScript' + SqlScript 'RunSQLScript' { ServerInstance = 'localhost\SQL2016' Credential = $SqlCredential diff --git a/Examples/Resources/xSQLServerScript/2-RunScriptUsingWindowsAuthentication.ps1 b/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 similarity index 89% rename from Examples/Resources/xSQLServerScript/2-RunScriptUsingWindowsAuthentication.ps1 rename to Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 index 3e5664c7b..dcb5f6cfb 100644 --- a/Examples/Resources/xSQLServerScript/2-RunScriptUsingWindowsAuthentication.ps1 +++ b/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1 @@ -12,11 +12,11 @@ Configuration Example $WindowsCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc Node localhost { - xSQLServerScript 'RunSQLScript-AsSYSTEM' + SqlScript 'RunSQLScript-AsSYSTEM' { ServerInstance = 'localhost\SQL2016' @@ -26,7 +26,7 @@ Configuration Example Variable = @("FilePath=C:\temp\log\AuditFiles") } - xSQLServerScript 'RunSQLScript-AsUSER' + SqlScript 'RunSQLScript-AsUSER' { ServerInstance = 'localhost\SQL2016' @@ -38,7 +38,7 @@ Configuration Example PsDscRunAsCredential = $WindowsCredential } - xSQLServerScript 'RunSQLScript-With30SecondTimeout' + SqlScript 'RunSQLScript-With30SecondTimeout' { ServerInstance = 'localhost\SQL2016' diff --git a/Examples/Resources/xSQLServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 b/Examples/Resources/SqlServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 similarity index 67% rename from Examples/Resources/xSQLServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 rename to Examples/Resources/SqlServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 index 25d1152e6..c6bd8677b 100644 --- a/Examples/Resources/xSQLServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 +++ b/Examples/Resources/SqlServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1 @@ -17,18 +17,18 @@ $configurationData = @{ Configuration Example { - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { foreach ($SQLInstance in $node.SQLInstances) { - xSQLServerConfiguration ('SQLConfigCLR_{0}' -f $SQLInstance) + SqlServerConfiguration ('SQLConfigCLR_{0}' -f $SQLInstance) { - SQLServer = $node.NodeName - SQLInstanceName = $SQLInstance - OptionName = $node.OptionName - OptionValue = 1 + Servername = $node.NodeName + InstanceName = $SQLInstance + OptionName = $node.OptionName + OptionValue = 1 } } } diff --git a/Examples/Resources/xSQLServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 b/Examples/Resources/SqlServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 similarity index 55% rename from Examples/Resources/xSQLServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 rename to Examples/Resources/SqlServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 index 93c1b222c..d3adc05f3 100644 --- a/Examples/Resources/xSQLServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 +++ b/Examples/Resources/SqlServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1 @@ -7,18 +7,18 @@ Configuration Example { - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerConfiguration 'SQLConfigPriorityBoost' + SqlServerConfiguration 'SQLConfigPriorityBoost' { - SQLServer = 'localhost' - SQLInstanceName = 'MSSQLSERVER' - OptionName = 'priority boost' - OptionValue = 1 - RestartService = $false + ServerName = 'localhost' + InstanceName = 'MSSQLSERVER' + OptionName = 'priority boost' + OptionValue = 1 + RestartService = $false } } } diff --git a/Examples/Resources/xSQLServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 b/Examples/Resources/SqlServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 similarity index 70% rename from Examples/Resources/xSQLServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 rename to Examples/Resources/SqlServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 index 3bbb8bf7d..45fafb065 100644 --- a/Examples/Resources/xSQLServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 +++ b/Examples/Resources/SqlServerEndpoint/1-CreateEndpointWithDefaultValues.ps1 @@ -13,22 +13,22 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpoint SQLConfigureEndpoint-Instance1 + SqlServerEndpoint SQLConfigureEndpoint-Instance1 { EndpointName = 'HADR' - SQLInstanceName = 'INST1' + InstanceName = 'INST1' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerEndpoint SQLConfigureEndpoint-Instances2 + SqlServerEndpoint SQLConfigureEndpoint-Instances2 { EndpointName = 'HADR' - SQLInstanceName = 'INST2' + InstanceName = 'INST2' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 b/Examples/Resources/SqlServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 similarity index 76% rename from Examples/Resources/xSQLServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 rename to Examples/Resources/SqlServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 index f807d42be..e88baa91c 100644 --- a/Examples/Resources/xSQLServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 +++ b/Examples/Resources/SqlServerEndpoint/2-CreateEndpointWithSpecificPortAndIPAddress.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpoint SQLConfigureEndpoint + SqlServerEndpoint SQLConfigureEndpoint { Ensure = 'Present' @@ -24,8 +24,8 @@ Configuration Example Port = 9001 IpAddress = '192.168.0.20' - SQLServer = 'server1.company.local' - SQLInstanceName = 'INST1' + ServerName = 'server1.company.local' + InstanceName = 'INST1' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerEndpoint/3-RemoveEndpoint.ps1 b/Examples/Resources/SqlServerEndpoint/3-RemoveEndpoint.ps1 similarity index 73% rename from Examples/Resources/xSQLServerEndpoint/3-RemoveEndpoint.ps1 rename to Examples/Resources/SqlServerEndpoint/3-RemoveEndpoint.ps1 index deecb023c..1f2ca5254 100644 --- a/Examples/Resources/xSQLServerEndpoint/3-RemoveEndpoint.ps1 +++ b/Examples/Resources/SqlServerEndpoint/3-RemoveEndpoint.ps1 @@ -13,26 +13,26 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpoint SQLConfigureEndpoint-Instance1 + SqlServerEndpoint SQLConfigureEndpoint-Instance1 { Ensure = 'Absent' EndpointName = 'HADR' - SQLInstanceName = 'INST1' + InstanceName = 'INST1' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerEndpoint SQLConfigureEndpoint-Instance2 + SqlServerEndpoint SQLConfigureEndpoint-Instance2 { Ensure = 'Absent' EndpointName = 'HADR' - SQLInstanceName = 'INST2' + InstanceName = 'INST2' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerEndpointPermission/1-AddConnectPermission.ps1 b/Examples/Resources/SqlServerEndpointPermission/1-AddConnectPermission.ps1 similarity index 85% rename from Examples/Resources/xSQLServerEndpointPermission/1-AddConnectPermission.ps1 rename to Examples/Resources/SqlServerEndpointPermission/1-AddConnectPermission.ps1 index fea85e1fb..3adc4875c 100644 --- a/Examples/Resources/xSQLServerEndpointPermission/1-AddConnectPermission.ps1 +++ b/Examples/Resources/SqlServerEndpointPermission/1-AddConnectPermission.ps1 @@ -18,14 +18,14 @@ Configuration Example $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpointPermission SQLConfigureEndpointPermission + SqlServerEndpointPermission SQLConfigureEndpointPermission { Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredential.UserName diff --git a/Examples/Resources/xSQLServerEndpointPermission/2-RemoveConnectPermission.ps1 b/Examples/Resources/SqlServerEndpointPermission/2-RemoveConnectPermission.ps1 similarity index 85% rename from Examples/Resources/xSQLServerEndpointPermission/2-RemoveConnectPermission.ps1 rename to Examples/Resources/SqlServerEndpointPermission/2-RemoveConnectPermission.ps1 index 47a1192c6..d48bc5381 100644 --- a/Examples/Resources/xSQLServerEndpointPermission/2-RemoveConnectPermission.ps1 +++ b/Examples/Resources/SqlServerEndpointPermission/2-RemoveConnectPermission.ps1 @@ -18,14 +18,14 @@ Configuration Example $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpointPermission SQLConfigureEndpointPermission + SqlServerEndpointPermission SQLConfigureEndpointPermission { Ensure = 'Absent' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredential.UserName diff --git a/Examples/Resources/xSQLServerEndpointPermission/3-AddConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 b/Examples/Resources/SqlServerEndpointPermission/3-AddConnectPermissionToTwoReplicasEachWithDifferentServiceAccount.ps1 similarity index 83% rename from Examples/Resources/xSQLServerEndpointPermission/3-AddConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 rename to Examples/Resources/SqlServerEndpointPermission/3-AddConnectPermissionToTwoReplicasEachWithDifferentServiceAccount.ps1 index 1c750eb61..a38b001ee 100644 --- a/Examples/Resources/xSQLServerEndpointPermission/3-AddConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 +++ b/Examples/Resources/SqlServerEndpointPermission/3-AddConnectPermissionToTwoReplicasEachWithDifferentServiceAccount.ps1 @@ -43,14 +43,14 @@ Configuration Example $SqlServiceNode2Credential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node $AllNodes.Where{$_.Role -eq 'PrimaryReplica' }.NodeName { - xSQLServerEndpointPermission SQLConfigureEndpointPermissionPrimary + SqlServerEndpointPermission SQLConfigureEndpointPermissionPrimary { Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceNode1Credential.UserName @@ -59,10 +59,10 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xSQLServerEndpointPermission SQLConfigureEndpointPermissionSecondary + SqlServerEndpointPermission SQLConfigureEndpointPermissionSecondary { Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceNode2Credential.UserName @@ -74,10 +74,10 @@ Configuration Example Node $AllNodes.Where{ $_.Role -eq 'SecondaryReplica' }.NodeName { - xSQLServerEndpointPermission SQLConfigureEndpointPermissionPrimary + SqlServerEndpointPermission SQLConfigureEndpointPermissionPrimary { Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceNode1Credential.UserName @@ -86,10 +86,10 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xSQLServerEndpointPermission SQLConfigureEndpointPermissionSecondary + SqlServerEndpointPermission SQLConfigureEndpointPermissionSecondary { Ensure = 'Present' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceNode2Credential.UserName diff --git a/Examples/Resources/xSQLServerEndpointPermission/4-RemoveConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 b/Examples/Resources/SqlServerEndpointPermission/4-RemoveConnectPermissionForTwoReplicasEachWithDifferentServiceAccount.ps1 similarity index 73% rename from Examples/Resources/xSQLServerEndpointPermission/4-RemoveConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 rename to Examples/Resources/SqlServerEndpointPermission/4-RemoveConnectPermissionForTwoReplicasEachWithDifferentServiceAccount.ps1 index 2af15d227..ca9391ddd 100644 --- a/Examples/Resources/xSQLServerEndpointPermission/4-RemoveConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1 +++ b/Examples/Resources/SqlServerEndpointPermission/4-RemoveConnectPermissionForTwoReplicasEachWithDifferentServiceAccount.ps1 @@ -43,14 +43,14 @@ Configuration Example $SqlServiceNode2Credential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node $AllNodes.Where{$_.Role -eq 'PrimaryReplica' }.NodeName { - xSQLServerEndpointPermission RemoveSQLConfigureEndpointPermissionPrimary + SqlServerEndpointPermission RemoveSQLConfigureEndpointPermissionPrimary { Ensure = 'Absent' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredentialNode2.UserName @@ -58,13 +58,13 @@ Configuration Example PsDscRunAsCredential = $SqlAdministratorCredential - DependsOn = '[xSQLServerEndpointPermission]SQLConfigureEndpointPermissionPrimary' + DependsOn = '[SqlServerEndpointPermission]SQLConfigureEndpointPermissionPrimary' } - xSQLServerEndpointPermission RemoveSQLConfigureEndpointPermissionSecondary + SqlServerEndpointPermission RemoveSQLConfigureEndpointPermissionSecondary { Ensure = 'Absent' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredentialNode2.UserName @@ -72,16 +72,16 @@ Configuration Example PsDscRunAsCredential = $SqlAdministratorCredential - DependsOn = '[xSQLServerEndpointPermission]SQLConfigureEndpointPermissionSecondary' + DependsOn = '[SqlServerEndpointPermission]SQLConfigureEndpointPermissionSecondary' } } Node $AllNodes.Where{ $_.Role -eq 'SecondaryReplica' }.NodeName { - xSQLServerEndpointPermission RemoveSQLConfigureEndpointPermissionPrimary + SqlServerEndpointPermission RemoveSQLConfigureEndpointPermissionPrimary { Ensure = 'Absent' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredentialNode2.UserName @@ -89,13 +89,13 @@ Configuration Example PsDscRunAsCredential = $SqlAdministratorCredential - DependsOn = '[xSQLServerEndpointPermission]SQLConfigureEndpointPermissionPrimary' + DependsOn = '[SqlServerEndpointPermission]SQLConfigureEndpointPermissionPrimary' } - xSQLServerEndpointPermission RemoveSQLConfigureEndpointPermissionSecondary + SqlServerEndpointPermission RemoveSQLConfigureEndpointPermissionSecondary { Ensure = 'Absent' - NodeName = $Node.NodeName + ServerName = $Node.NodeName InstanceName = $Node.SqlInstanceName Name = 'DefaultMirrorEndpoint' Principal = $SqlServiceCredentialNode2.UserName @@ -103,7 +103,7 @@ Configuration Example PsDscRunAsCredential = $SqlAdministratorCredential - DependsOn = '[xSQLServerEndpointPermission]SQLConfigureEndpointPermissionSecondary' + DependsOn = '[SqlServerEndpointPermission]SQLConfigureEndpointPermissionSecondary' } } } diff --git a/Examples/Resources/xSQLServerEndpointState/1-MakeSureEndpointIsStarted.ps1 b/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 similarity index 82% rename from Examples/Resources/xSQLServerEndpointState/1-MakeSureEndpointIsStarted.ps1 rename to Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 index 11baa12e2..21f34abc6 100644 --- a/Examples/Resources/xSQLServerEndpointState/1-MakeSureEndpointIsStarted.ps1 +++ b/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1 @@ -21,14 +21,14 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { # Start the DefaultMirrorEndpoint in the default instance - xSQLServerEndpointState StartEndpoint1 + SqlServerEndpointState StartEndpoint1 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'DefaultMirrorEndpoint' State = 'Started' @@ -37,9 +37,9 @@ Configuration Example } # Start the HADR in the default instance - xSQLServerEndpointState StartEndpoint2 + SqlServerEndpointState StartEndpoint2 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'HADR' State = 'Started' @@ -48,9 +48,9 @@ Configuration Example } # Start the DefaultMirrorEndpoint in the named instance INSTANCE1 - xSQLServerEndpointState StartEndpoint3 + SqlServerEndpointState StartEndpoint3 { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'INSTANCE1' Name = 'DefaultMirrorEndpoint' State = 'Started' diff --git a/Examples/Resources/xSQLServerEndpointState/2-MakeSureEndpointIsStopped.ps1 b/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 similarity index 80% rename from Examples/Resources/xSQLServerEndpointState/2-MakeSureEndpointIsStopped.ps1 rename to Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 index 69422e93b..882fd32c8 100644 --- a/Examples/Resources/xSQLServerEndpointState/2-MakeSureEndpointIsStopped.ps1 +++ b/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1 @@ -12,13 +12,13 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerEndpointState StopEndpoint + SqlServerEndpointState StopEndpoint { - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Name = 'DefaultMirrorEndpoint' State = 'Stopped' diff --git a/Examples/Resources/xSQLServerLogin/1-AddLogin.ps1 b/Examples/Resources/SqlServerLogin/1-AddLogin.ps1 similarity index 72% rename from Examples/Resources/xSQLServerLogin/1-AddLogin.ps1 rename to Examples/Resources/SqlServerLogin/1-AddLogin.ps1 index 063a495a1..35a714917 100644 --- a/Examples/Resources/xSQLServerLogin/1-AddLogin.ps1 +++ b/Examples/Resources/SqlServerLogin/1-AddLogin.ps1 @@ -21,47 +21,47 @@ Configuration Example $LoginCredential ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerLogin Add_WindowsUser + SqlServerLogin Add_WindowsUser { Ensure = 'Present' Name = 'CONTOSO\WindowsUser' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerLogin Add_DisabledWindowsUser + SqlServerLogin Add_DisabledWindowsUser { Ensure = 'Present' Name = 'CONTOSO\WindowsUser2' LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount Disabled = $true } - xSQLServerLogin Add_WindowsGroup + SqlServerLogin Add_WindowsGroup { Ensure = 'Present' Name = 'CONTOSO\WindowsGroup' LoginType = 'WindowsGroup' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } - xSQLServerLogin Add_SqlLogin + SqlServerLogin Add_SqlLogin { Ensure = 'Present' Name = 'SqlLogin' LoginType = 'SqlLogin' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' LoginCredential = $LoginCredential LoginMustChangePassword = $false LoginPasswordExpirationEnabled = $true diff --git a/Examples/Resources/SqlServerLogin/2-RemoveLogin.ps1 b/Examples/Resources/SqlServerLogin/2-RemoveLogin.ps1 new file mode 100644 index 000000000..489c1bb69 --- /dev/null +++ b/Examples/Resources/SqlServerLogin/2-RemoveLogin.ps1 @@ -0,0 +1,44 @@ +<# +.EXAMPLE +This example shows how to remove the Windows user 'CONTOSO\WindowsUser'. + +.EXAMPLE +This example shows how to remove Windows group 'CONTOSO\WindowsGroup'. + +.EXAMPLE +This example shows how to remove the SQL Login 'SqlLogin'. +#> + +Configuration Example +{ + Import-DscResource -ModuleName SqlServerDsc + + node localhost { + SqlServerLogin Remove_WindowsUser + { + Ensure = 'Absent' + Name = 'CONTOSO\WindowsUser' + LoginType = 'WindowsUser' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' + } + + SqlServerLogin Remove_WindowsGroup + { + Ensure = 'Absent' + Name = 'CONTOSO\WindowsGroup' + LoginType = 'WindowsGroup' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' + } + + SqlServerLogin Remove_SqlLogin + { + Ensure = 'Absent' + Name = 'SqlLogin' + LoginType = 'SqlLogin' + ServerName = 'TestServer.company.local' + InstanceName = 'DSC' + } + } +} diff --git a/Examples/Resources/xSQLServerMaxDop/1-SetMaxDopToOne.ps1 b/Examples/Resources/SqlServerMaxDop/1-SetMaxDopToOne.ps1 similarity index 74% rename from Examples/Resources/xSQLServerMaxDop/1-SetMaxDopToOne.ps1 rename to Examples/Resources/SqlServerMaxDop/1-SetMaxDopToOne.ps1 index 53638884e..695643cc2 100644 --- a/Examples/Resources/xSQLServerMaxDop/1-SetMaxDopToOne.ps1 +++ b/Examples/Resources/SqlServerMaxDop/1-SetMaxDopToOne.ps1 @@ -13,17 +13,17 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMaxDop Set_SQLServerMaxDop_ToOne + SqlServerMaxDop Set_SQLServerMaxDop_ToOne { Ensure = 'Present' DynamicAlloc = $false MaxDop = 1 - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerMaxDop/2-SetMaxDopToAuto.ps1 b/Examples/Resources/SqlServerMaxDop/2-SetMaxDopToAuto.ps1 similarity index 80% rename from Examples/Resources/xSQLServerMaxDop/2-SetMaxDopToAuto.ps1 rename to Examples/Resources/SqlServerMaxDop/2-SetMaxDopToAuto.ps1 index 4cfd75451..ad0ccacef 100644 --- a/Examples/Resources/xSQLServerMaxDop/2-SetMaxDopToAuto.ps1 +++ b/Examples/Resources/SqlServerMaxDop/2-SetMaxDopToAuto.ps1 @@ -18,16 +18,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMaxDop Set_SQLServerMaxDop_ToAuto + SqlServerMaxDop Set_SQLServerMaxDop_ToAuto { Ensure = 'Present' DynamicAlloc = $true - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount ProcessOnlyOnActiveNode = $true } diff --git a/Examples/Resources/xSQLServerMaxDop/3-SetMaxDopToDefault.ps1 b/Examples/Resources/SqlServerMaxDop/3-SetMaxDopToDefault.ps1 similarity index 71% rename from Examples/Resources/xSQLServerMaxDop/3-SetMaxDopToDefault.ps1 rename to Examples/Resources/SqlServerMaxDop/3-SetMaxDopToDefault.ps1 index 917ada584..1b81a8b38 100644 --- a/Examples/Resources/xSQLServerMaxDop/3-SetMaxDopToDefault.ps1 +++ b/Examples/Resources/SqlServerMaxDop/3-SetMaxDopToDefault.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMaxDop Set_SQLServerMaxDop_ToDefault + SqlServerMaxDop Set_SQLServerMaxDop_ToDefault { Ensure = 'Absent' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerMemory/1-SetMaxMemoryTo12GB.ps1 b/Examples/Resources/SqlServerMemory/1-SetMaxMemoryTo12GB.ps1 similarity index 75% rename from Examples/Resources/xSQLServerMemory/1-SetMaxMemoryTo12GB.ps1 rename to Examples/Resources/SqlServerMemory/1-SetMaxMemoryTo12GB.ps1 index fc8a2a789..525e20233 100644 --- a/Examples/Resources/xSQLServerMemory/1-SetMaxMemoryTo12GB.ps1 +++ b/Examples/Resources/SqlServerMemory/1-SetMaxMemoryTo12GB.ps1 @@ -13,18 +13,18 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMemory Set_SQLServerMaxMemory_To12GB + SqlServerMemory Set_SQLServerMaxMemory_To12GB { Ensure = 'Present' DynamicAlloc = $false MinMemory = 1024 MaxMemory = 12288 - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerMemory/2-SetMaxMemoryToAuto.ps1 b/Examples/Resources/SqlServerMemory/2-SetMaxMemoryToAuto.ps1 similarity index 80% rename from Examples/Resources/xSQLServerMemory/2-SetMaxMemoryToAuto.ps1 rename to Examples/Resources/SqlServerMemory/2-SetMaxMemoryToAuto.ps1 index a13999410..9c2bdb99b 100644 --- a/Examples/Resources/xSQLServerMemory/2-SetMaxMemoryToAuto.ps1 +++ b/Examples/Resources/SqlServerMemory/2-SetMaxMemoryToAuto.ps1 @@ -18,16 +18,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMemory Set_SQLServerMaxMemory_ToAuto + SqlServerMemory Set_SQLServerMaxMemory_ToAuto { Ensure = 'Present' DynamicAlloc = $true - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount ProcessOnlyOnActiveNode = $true } diff --git a/Examples/Resources/xSQLServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 b/Examples/Resources/SqlServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 similarity index 74% rename from Examples/Resources/xSQLServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 rename to Examples/Resources/SqlServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 index 7c245ec29..449aef519 100644 --- a/Examples/Resources/xSQLServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 +++ b/Examples/Resources/SqlServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1 @@ -13,16 +13,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMemory Set_SQLServerMinAndMaxMemory_ToAuto + SqlServerMemory Set_SQLServerMinAndMaxMemory_ToAuto { Ensure = 'Present' DynamicAlloc = $true - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' MinMemory = 2048 PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/xSQLServerMemory/4-SetMaxMemoryToDefault.ps1 b/Examples/Resources/SqlServerMemory/4-SetMaxMemoryToDefault.ps1 similarity index 71% rename from Examples/Resources/xSQLServerMemory/4-SetMaxMemoryToDefault.ps1 rename to Examples/Resources/SqlServerMemory/4-SetMaxMemoryToDefault.ps1 index 975249117..c7718a071 100644 --- a/Examples/Resources/xSQLServerMemory/4-SetMaxMemoryToDefault.ps1 +++ b/Examples/Resources/SqlServerMemory/4-SetMaxMemoryToDefault.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerMemory Set_SQLServerMaxMemory_ToDefault + SqlServerMemory Set_SQLServerMaxMemory_ToDefault { Ensure = 'Absent' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerNetwork/1-EnableTcpIpWithStaticPort.ps1 b/Examples/Resources/SqlServerNetwork/1-EnableTcpIpWithStaticPort.ps1 similarity index 86% rename from Examples/Resources/xSQLServerNetwork/1-EnableTcpIpWithStaticPort.ps1 rename to Examples/Resources/SqlServerNetwork/1-EnableTcpIpWithStaticPort.ps1 index 20062dd69..ee91453e0 100644 --- a/Examples/Resources/xSQLServerNetwork/1-EnableTcpIpWithStaticPort.ps1 +++ b/Examples/Resources/SqlServerNetwork/1-EnableTcpIpWithStaticPort.ps1 @@ -13,11 +13,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerNetwork 'ChangeTcpIpOnDefaultInstance' + SqlServerNetwork 'ChangeTcpIpOnDefaultInstance' { InstanceName = 'MSSQLSERVER' ProtocolName = 'Tcp' diff --git a/Examples/Resources/xSQLServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 b/Examples/Resources/SqlServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 similarity index 86% rename from Examples/Resources/xSQLServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 rename to Examples/Resources/SqlServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 index 1ba825cf5..ac0f5ddee 100644 --- a/Examples/Resources/xSQLServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 +++ b/Examples/Resources/SqlServerNetwork/2-EnableTcpIpWithDynamicPort.ps1 @@ -13,11 +13,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerNetwork 'ChangeTcpIpOnDefaultInstance' + SqlServerNetwork 'ChangeTcpIpOnDefaultInstance' { InstanceName = 'MSSQLSERVER' ProtocolName = 'Tcp' diff --git a/Examples/Resources/xSQLServerPermission/1-AddServerPermissionForLogin.ps1 b/Examples/Resources/SqlServerPermission/1-AddServerPermissionForLogin.ps1 similarity index 78% rename from Examples/Resources/xSQLServerPermission/1-AddServerPermissionForLogin.ps1 rename to Examples/Resources/SqlServerPermission/1-AddServerPermissionForLogin.ps1 index 92ceac630..15603c426 100644 --- a/Examples/Resources/xSQLServerPermission/1-AddServerPermissionForLogin.ps1 +++ b/Examples/Resources/SqlServerPermission/1-AddServerPermissionForLogin.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDSC node localhost { # Add permission - xSQLServerPermission 'SQLConfigureServerPermission-SYSTEM' + SqlServerPermission 'SQLConfigureServerPermission-SYSTEM' { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Principal = 'NT AUTHORITY\SYSTEM' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' @@ -29,10 +29,10 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xSQLServerPermission 'SQLConfigureServerPermission-ClusSvc' + SqlServerPermission 'SQLConfigureServerPermission-ClusSvc' { Ensure = 'Present' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' diff --git a/Examples/Resources/xSQLServerPermission/2-RemoveServerPermissionForLogin.ps1 b/Examples/Resources/SqlServerPermission/2-RemoveServerPermissionForLogin.ps1 similarity index 81% rename from Examples/Resources/xSQLServerPermission/2-RemoveServerPermissionForLogin.ps1 rename to Examples/Resources/SqlServerPermission/2-RemoveServerPermissionForLogin.ps1 index 8355c62b6..b433ba877 100644 --- a/Examples/Resources/xSQLServerPermission/2-RemoveServerPermissionForLogin.ps1 +++ b/Examples/Resources/SqlServerPermission/2-RemoveServerPermissionForLogin.ps1 @@ -13,15 +13,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDSC node localhost { # Add permission - xSQLServerPermission SQLConfigureServerPermission + SqlServerPermission SQLConfigureServerPermission { Ensure = 'Absent' - NodeName = 'SQLNODE01.company.local' + ServerName = 'SQLNODE01.company.local' InstanceName = 'MSSQLSERVER' Principal = 'NT AUTHORITY\SYSTEM' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' diff --git a/Examples/Resources/xSQLServerReplication/1-ConfigureInstanceAsDistributor.ps1 b/Examples/Resources/SqlServerReplication/1-ConfigureInstanceAsDistributor.ps1 similarity index 88% rename from Examples/Resources/xSQLServerReplication/1-ConfigureInstanceAsDistributor.ps1 rename to Examples/Resources/SqlServerReplication/1-ConfigureInstanceAsDistributor.ps1 index c1d5bf716..25d71253b 100644 --- a/Examples/Resources/xSQLServerReplication/1-ConfigureInstanceAsDistributor.ps1 +++ b/Examples/Resources/SqlServerReplication/1-ConfigureInstanceAsDistributor.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerReplication distributor + SqlServerReplication distributor { Ensure = 'Present' InstanceName = 'MSSQLSERVER' diff --git a/Examples/Resources/xSQLServerReplication/2-ConfigureInstanceAsPublisher.ps1 b/Examples/Resources/SqlServerReplication/2-ConfigureInstanceAsPublisher.ps1 similarity index 89% rename from Examples/Resources/xSQLServerReplication/2-ConfigureInstanceAsPublisher.ps1 rename to Examples/Resources/SqlServerReplication/2-ConfigureInstanceAsPublisher.ps1 index 3d29ae26b..30737e9a8 100644 --- a/Examples/Resources/xSQLServerReplication/2-ConfigureInstanceAsPublisher.ps1 +++ b/Examples/Resources/SqlServerReplication/2-ConfigureInstanceAsPublisher.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerReplication publisher + SqlServerReplication publisher { Ensure = 'Present' InstanceName = 'PUBLISHER' diff --git a/Examples/Resources/xSQLServerRole/1-AddServerRole.ps1 b/Examples/Resources/SqlServerRole/1-AddServerRole.ps1 similarity index 52% rename from Examples/Resources/xSQLServerRole/1-AddServerRole.ps1 rename to Examples/Resources/SqlServerRole/1-AddServerRole.ps1 index c14a0cb10..0546bfdfb 100644 --- a/Examples/Resources/xSQLServerRole/1-AddServerRole.ps1 +++ b/Examples/Resources/SqlServerRole/1-AddServerRole.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to ensure that the server role named - AdminSqlforBI is present on instance SQLServer\DSC. + AdminSqlforBI is present on instance sqltest.company.local\DSC. #> Configuration Example @@ -12,15 +12,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerRole Add_ServerRole_AdminSqlforBI + SqlServerRole Add_ServerRole_AdminSqlforBI { Ensure = 'Present' - ServerRoleName = "AdminSqlforBI" - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerRoleName = 'AdminSqlforBI' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerRole/2-RemoveServerRole.ps1 b/Examples/Resources/SqlServerRole/2-RemoveServerRole.ps1 similarity index 52% rename from Examples/Resources/xSQLServerRole/2-RemoveServerRole.ps1 rename to Examples/Resources/SqlServerRole/2-RemoveServerRole.ps1 index 3abaf2e12..407055246 100644 --- a/Examples/Resources/xSQLServerRole/2-RemoveServerRole.ps1 +++ b/Examples/Resources/SqlServerRole/2-RemoveServerRole.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to ensure that the server role named - serverRoleToDelete is not present on instance SQLServer\DSC. + serverRoleToDelete is not present on instance sqltest.company.local\DSC. #> Configuration Example @@ -12,15 +12,15 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerRole Remove_ServerRole + SqlServerRole Remove_ServerRole { Ensure = 'Absent' - ServerRoleName = "serverRoleToDelete" - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + ServerRoleName = 'serverRoleToDelete' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerRole/3-AddMembersToServerRole.ps1 b/Examples/Resources/SqlServerRole/3-AddMembersToServerRole.ps1 similarity index 57% rename from Examples/Resources/xSQLServerRole/3-AddMembersToServerRole.ps1 rename to Examples/Resources/SqlServerRole/3-AddMembersToServerRole.ps1 index 4fd419159..5e7c0c35a 100644 --- a/Examples/Resources/xSQLServerRole/3-AddMembersToServerRole.ps1 +++ b/Examples/Resources/SqlServerRole/3-AddMembersToServerRole.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to ensure that the server role named - AdminSqlforBI is present on instance SQLServer\DSC and only logins + AdminSqlforBI is present on instance sqltest.company.local\DSC and only logins CONTOSO\SQLAdmin and CONTOSO\SQLAdminBI are members of this role. #> @@ -13,16 +13,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerRole Add_ServerRole_AdminSqlforBI + SqlServerRole Add_ServerRole_AdminSqlforBI { Ensure = 'Present' ServerRoleName = 'AdminSqlforBI' - Members = "CONTOSO\SQLAdmin", "CONTOSO\SQLAdminBI" - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + Members = 'CONTOSO\SQLAdmin', 'CONTOSO\SQLAdminBI' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerRole/4-MembersToIncludeInServerRole.ps1 b/Examples/Resources/SqlServerRole/4-MembersToIncludeInServerRole.ps1 similarity index 58% rename from Examples/Resources/xSQLServerRole/4-MembersToIncludeInServerRole.ps1 rename to Examples/Resources/SqlServerRole/4-MembersToIncludeInServerRole.ps1 index 444a60071..86400f4ca 100644 --- a/Examples/Resources/xSQLServerRole/4-MembersToIncludeInServerRole.ps1 +++ b/Examples/Resources/SqlServerRole/4-MembersToIncludeInServerRole.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to ensure that the server role named - AdminSqlforBI is present on instance SQLServer\DSC and logins + AdminSqlforBI is present on instance sqltest.company.local\DSC and logins CONTOSO\John and CONTOSO\Kelly are added as members of this role. #> @@ -13,16 +13,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerRole Add_ServerRole_AdminSqlforBI + SqlServerRole Add_ServerRole_AdminSqlforBI { Ensure = 'Present' ServerRoleName = 'AdminSqlforBI' - MembersToInclude = "CONTOSO\John", "CONTOSO\Kelly" - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + MembersToInclude = 'CONTOSO\John', 'CONTOSO\Kelly' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerRole/5-MembersToExcludeInServerRole.ps1 b/Examples/Resources/SqlServerRole/5-MembersToExcludeInServerRole.ps1 similarity index 57% rename from Examples/Resources/xSQLServerRole/5-MembersToExcludeInServerRole.ps1 rename to Examples/Resources/SqlServerRole/5-MembersToExcludeInServerRole.ps1 index 5a2f520d0..0594a2f34 100644 --- a/Examples/Resources/xSQLServerRole/5-MembersToExcludeInServerRole.ps1 +++ b/Examples/Resources/SqlServerRole/5-MembersToExcludeInServerRole.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to ensure that the server role named - AdminSqlforBI is present on instance SQLServer\DSC and logins + AdminSqlforBI is present on instance sqltest.company.local\DSC and logins CONTOSO\Mark and CONTOSO\Lucy are not members of this role. #> @@ -13,16 +13,16 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerRole Drop_ServerRole_AdminSqlforBI + SqlServerRole Drop_ServerRole_AdminSqlforBI { Ensure = 'Present' ServerRoleName = 'AdminSqlforBI' - MembersToExclude = "CONTOSO\Mark", "CONTOSO\Lucy" - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' + MembersToExclude = 'CONTOSO\Mark', 'CONTOSO\Lucy' + ServerName = 'sqltest.company.local' + InstanceName = 'DSC' PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/xSQLServerServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 b/Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 similarity index 63% rename from Examples/Resources/xSQLServerServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 rename to Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 index 42b91b13c..e1459f217 100644 --- a/Examples/Resources/xSQLServerServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 +++ b/Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1 @@ -12,14 +12,14 @@ Configuration Example $ServiceAccountCredential ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node localhost { - xSQLServerServiceAccount SetServiceAcccount_User + SqlServiceAccount SetServiceAcccount_User { - SQLServer = 'TestServer' - SQLInstanceName = 'MSSQLSERVER' - ServiceType = 'DatabaseEngine' + ServerName = 'TestServer' + InstanceName = 'MSSQLSERVER' + ServiceType = 'DatabaseEngine' ServiceAccount = $ServiceAccountCredential RestartService = $true } diff --git a/Examples/Resources/xSQLServerServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 b/Examples/Resources/SqlServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 similarity index 69% rename from Examples/Resources/xSQLServerServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 rename to Examples/Resources/SqlServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 index d0ff7a4c3..d74b11b8b 100644 --- a/Examples/Resources/xSQLServerServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 +++ b/Examples/Resources/SqlServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1 @@ -15,17 +15,17 @@ Configuration Example $ServiceAcccountCredential ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc Node localhost { - xSQLServerServiceAccount SetServiceAcccount_User + SqlServiceAccount SetServiceAcccount_User { - SQLServer = 'TestServer' - SQLInstanceName = 'DSC' - ServiceType = 'DatabaseEngine' + ServerName = 'TestServer' + InstanceName = 'DSC' + ServiceType = 'DatabaseEngine' ServiceAccount = $ServiceAcccountCredential RestartService = $true - Force = $true + Force = $true } } } diff --git a/Examples/Resources/xSQLServerSetup/1-InstallDefaultInstanceSingleServer.ps1 b/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 similarity index 97% rename from Examples/Resources/xSQLServerSetup/1-InstallDefaultInstanceSingleServer.ps1 rename to Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 index 8988308c3..9eafc2c7c 100644 --- a/Examples/Resources/xSQLServerSetup/1-InstallDefaultInstanceSingleServer.ps1 +++ b/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 @@ -35,7 +35,7 @@ Configuration Example $SqlAgentServiceCredential = $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { @@ -55,7 +55,7 @@ Configuration Example #endregion Install prerequisites for SQL Server #region Install SQL Server - xSQLServerSetup 'InstallDefaultInstance' + SqlSetup 'InstallDefaultInstance' { InstanceName = 'MSSQLSERVER' Features = 'SQLENGINE,AS' diff --git a/Examples/Resources/xSQLServerSetup/2-InstallNamedInstanceSingleServer.ps1 b/Examples/Resources/SqlSetup/2-InstallNamedInstanceSingleServer.ps1 similarity index 97% rename from Examples/Resources/xSQLServerSetup/2-InstallNamedInstanceSingleServer.ps1 rename to Examples/Resources/SqlSetup/2-InstallNamedInstanceSingleServer.ps1 index 254763e86..a754fffe6 100644 --- a/Examples/Resources/xSQLServerSetup/2-InstallNamedInstanceSingleServer.ps1 +++ b/Examples/Resources/SqlSetup/2-InstallNamedInstanceSingleServer.ps1 @@ -35,7 +35,7 @@ Configuration Example $SqlAgentServiceCredential = $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDSC node localhost { @@ -55,7 +55,7 @@ Configuration Example #endregion Install prerequisites for SQL Server #region Install SQL Server - xSQLServerSetup 'InstallNamedInstance-INST2016' + SqlSetup 'InstallNamedInstance-INST2016' { InstanceName = 'INST2016' Features = 'SQLENGINE,AS' diff --git a/Examples/Resources/xSQLServerSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 b/Examples/Resources/SqlSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 similarity index 97% rename from Examples/Resources/xSQLServerSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 rename to Examples/Resources/SqlSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 index 3b01a2588..bdd01187b 100644 --- a/Examples/Resources/xSQLServerSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 +++ b/Examples/Resources/SqlSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1 @@ -39,7 +39,7 @@ Configuration Example $SqlAgentServiceCredential = $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { @@ -59,7 +59,7 @@ Configuration Example #endregion Install prerequisites for SQL Server #region Install SQL Server - xSQLServerSetup 'InstallNamedInstance-INST2016' + SqlSetup 'InstallNamedInstance-INST2016' { InstanceName = 'INST2016' Features = 'SQLENGINE,AS' diff --git a/Examples/Resources/xSQLServerSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 b/Examples/Resources/SqlSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 similarity index 98% rename from Examples/Resources/xSQLServerSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 rename to Examples/Resources/SqlSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 index 786bb5d53..8ddd54537 100644 --- a/Examples/Resources/xSQLServerSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 +++ b/Examples/Resources/SqlSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1 @@ -59,7 +59,7 @@ Configuration Example $SqlAgentServiceCredential = $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { @@ -79,7 +79,7 @@ Configuration Example #endregion Install prerequisites for SQL Server #region Install SQL Server Failover Cluster - xSQLServerSetup 'InstallNamedInstanceNode1-INST2016' + SqlSetup 'InstallNamedInstanceNode1-INST2016' { Action = 'InstallFailoverCluster' ForceReboot = $false diff --git a/Examples/Resources/xSQLServerSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 b/Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 similarity index 97% rename from Examples/Resources/xSQLServerSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 rename to Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 index 17f9b250e..3bf76ce91 100644 --- a/Examples/Resources/xSQLServerSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 +++ b/Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1 @@ -55,7 +55,7 @@ Configuration Example $SqlAgentServiceCredential = $SqlServiceCredential ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { @@ -75,7 +75,7 @@ Configuration Example #endregion Install prerequisites for SQL Server #region Install SQL Server Failover Cluster - xSQLServerSetup 'InstallNamedInstanceNode2-INST2016' + SqlSetup 'InstallNamedInstanceNode2-INST2016' { Action = 'AddNode' ForceReboot = $false diff --git a/Examples/Resources/xWaitForAvailabilityGroup/1-WaitForASingleClusterGroup.ps1 b/Examples/Resources/SqlWaitForAG/1-WaitForASingleClusterGroup.ps1 similarity index 83% rename from Examples/Resources/xWaitForAvailabilityGroup/1-WaitForASingleClusterGroup.ps1 rename to Examples/Resources/SqlWaitForAG/1-WaitForASingleClusterGroup.ps1 index 96c191d9c..d1566a51e 100644 --- a/Examples/Resources/xWaitForAvailabilityGroup/1-WaitForASingleClusterGroup.ps1 +++ b/Examples/Resources/SqlWaitForAG/1-WaitForASingleClusterGroup.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xWaitForAvailabilityGroup SQLConfigureAG-WaitAGTest1 + SqlWaitForAG SQLConfigureAG-WaitAGTest1 { Name = 'AGTest1' RetryIntervalSec = 20 diff --git a/Examples/Resources/xWaitForAvailabilityGroup/2-WaitForMultipleClusterGroups.ps1 b/Examples/Resources/SqlWaitForAG/2-WaitForMultipleClusterGroups.ps1 similarity index 81% rename from Examples/Resources/xWaitForAvailabilityGroup/2-WaitForMultipleClusterGroups.ps1 rename to Examples/Resources/SqlWaitForAG/2-WaitForMultipleClusterGroups.ps1 index 93773477f..ef25ba152 100644 --- a/Examples/Resources/xWaitForAvailabilityGroup/2-WaitForMultipleClusterGroups.ps1 +++ b/Examples/Resources/SqlWaitForAG/2-WaitForMultipleClusterGroups.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSQLServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xWaitForAvailabilityGroup SQLConfigureAG-WaitAGTest1 + SqlWaitForAG SQLConfigureAG-WaitAGTest1 { Name = 'AGTest1' RetryIntervalSec = 20 @@ -25,7 +25,7 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xWaitForAvailabilityGroup SQLConfigureAG-WaitAGTest2 + SqlWaitForAG SQLConfigureAG-WaitAGTest2 { Name = 'AGTest2' RetryIntervalSec = 20 diff --git a/Examples/Resources/xSQLServerFirewall/1-CreateInboundFirewallRules.ps1 b/Examples/Resources/SqlWindowsFirewall/1-CreateInboundFirewallRules.ps1 similarity index 84% rename from Examples/Resources/xSQLServerFirewall/1-CreateInboundFirewallRules.ps1 rename to Examples/Resources/SqlWindowsFirewall/1-CreateInboundFirewallRules.ps1 index 8ce7ccfa5..3333b28c2 100644 --- a/Examples/Resources/xSQLServerFirewall/1-CreateInboundFirewallRules.ps1 +++ b/Examples/Resources/SqlWindowsFirewall/1-CreateInboundFirewallRules.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerFirewall Create_FirewallRules_For_SQL2012 + SqlWindowsFirewall Create_FirewallRules_For_SQL2012 { Ensure = 'Present' Features = 'SQLENGINE,AS,RS,IS' @@ -26,7 +26,7 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xSQLServerFirewall Create_FirewallRules_For_SQL2016 + SqlWindowsFirewall Create_FirewallRules_For_SQL2016 { Ensure = 'Present' Features = 'SQLENGINE' diff --git a/Examples/Resources/xSQLServerFirewall/2-RemoveInboundFirewallRules.ps1 b/Examples/Resources/SqlWindowsFirewall/2-RemoveInboundFirewallRules.ps1 similarity index 84% rename from Examples/Resources/xSQLServerFirewall/2-RemoveInboundFirewallRules.ps1 rename to Examples/Resources/SqlWindowsFirewall/2-RemoveInboundFirewallRules.ps1 index 583befca6..3ba7fac4c 100644 --- a/Examples/Resources/xSQLServerFirewall/2-RemoveInboundFirewallRules.ps1 +++ b/Examples/Resources/SqlWindowsFirewall/2-RemoveInboundFirewallRules.ps1 @@ -12,11 +12,11 @@ Configuration Example $SysAdminAccount ) - Import-DscResource -ModuleName xSqlServer + Import-DscResource -ModuleName SqlServerDsc node localhost { - xSQLServerFirewall Remove_FirewallRules_For_SQL2012 + SqlWindowsFirewall Remove_FirewallRules_For_SQL2012 { Ensure = 'Absent' Features = 'SQLENGINE,AS,RS,IS' @@ -26,7 +26,7 @@ Configuration Example PsDscRunAsCredential = $SysAdminAccount } - xSQLServerFirewall Remove_FirewallRules_For_SQL2016 + SqlWindowsFirewall Remove_FirewallRules_For_SQL2016 { Ensure = 'Absent' Features = 'SQLENGINE' diff --git a/Examples/Resources/xSQLServerDatabase/1-CreateDatabase.ps1 b/Examples/Resources/xSQLServerDatabase/1-CreateDatabase.ps1 deleted file mode 100644 index 0bd9e3c29..000000000 --- a/Examples/Resources/xSQLServerDatabase/1-CreateDatabase.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -<# -.EXAMPLE - This example shows how to create a database with - the database name equal to 'Contoso'. - - The second example shows how to create a database - with a different collation. -#> -Configuration Example -{ - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - [System.Management.Automation.Credential()] - $SysAdminAccount - ) - - Import-DscResource -ModuleName xSqlServer - - node localhost - { - xSQLServerDatabase Create_Database - { - Ensure = 'Present' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - Name = 'Contoso' - } - - xSQLServerDatabase Create_Database_with_different_collation - { - Ensure = 'Present' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - Name = 'AdventureWorks' - Collation = 'SQL_Latin1_General_Pref_CP850_CI_AS' - } - } -} diff --git a/Examples/Resources/xSQLServerDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 b/Examples/Resources/xSQLServerDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 deleted file mode 100644 index 86e289a07..000000000 --- a/Examples/Resources/xSQLServerDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -<# -.EXAMPLE - This example shows how to manage database default locations for Data, Logs, and Backups for SQL Server. - - In the event this is applied to a Failover Cluster Instance (FCI), the - ProcessOnlyOnActiveNode property will tell the Test-TargetResource function - to evaluate if any changes are needed if the node is actively hosting the - SQL Server Instance. -#> -Configuration Example -{ - param - ( - [Parameter(Mandatory = $true)] - [System.Management.Automation.PSCredential] - $SysAdminAccount - ) - - Import-DscResource -ModuleName xSqlServer - - node localhost - { - xSQLServerDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Data - { - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - ProcessOnlyOnActiveNode = $true - Type = 'Data' - Path = 'C:\Program Files\Microsoft SQL Server' - PsDscRunAsCredential = $SysAdminAccount - } - - xSQLServerDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Log - { - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - ProcessOnlyOnActiveNode = $true - Type = 'Log' - Path = 'C:\Program Files\Microsoft SQL Server' - PsDscRunAsCredential = $SysAdminAccount - } - - xSQLServerDatabaseDefaultLocation Set_SqlDatabaseDefaultDirectory_Backup - { - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - ProcessOnlyOnActiveNode = $true - Type = 'Backup' - Path = 'C:\Program Files\Microsoft SQL Server' - PsDscRunAsCredential = $SysAdminAccount - } - } -} diff --git a/Examples/Resources/xSQLServerLogin/2-RemoveLogin.ps1 b/Examples/Resources/xSQLServerLogin/2-RemoveLogin.ps1 deleted file mode 100644 index 98a50222d..000000000 --- a/Examples/Resources/xSQLServerLogin/2-RemoveLogin.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -<# -.EXAMPLE -This example shows how to remove the Windows user 'CONTOSO\WindowsUser'. - -.EXAMPLE -This example shows how to remove Windows group 'CONTOSO\WindowsGroup'. - -.EXAMPLE -This example shows how to remove the SQL Login 'SqlLogin'. -#> - -Configuration Example -{ - Import-DscResource -ModuleName xSqlServer - - node localhost { - xSQLServerLogin Remove_WindowsUser - { - Ensure = 'Absent' - Name = 'CONTOSO\WindowsUser' - LoginType = 'WindowsUser' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - } - - xSQLServerLogin Remove_WindowsGroup - { - Ensure = 'Absent' - Name = 'CONTOSO\WindowsGroup' - LoginType = 'WindowsGroup' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - } - - xSQLServerLogin Remove_SqlLogin - { - Ensure = 'Absent' - Name = 'SqlLogin' - LoginType = 'SqlLogin' - SQLServer = 'SQLServer' - SQLInstanceName = 'DSC' - } - } -} diff --git a/Examples/SQL-ClusterDB.ps1 b/Examples/SQL-ClusterDB.ps1 index 8b31fc540..f1828006b 100644 --- a/Examples/SQL-ClusterDB.ps1 +++ b/Examples/SQL-ClusterDB.ps1 @@ -1,11 +1,20 @@ -#requires -Version 5 - +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () Configuration SQL { - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC Import-DscResource -Module xFailoverCluster Node $AllNodes.NodeName @@ -104,7 +113,7 @@ Configuration SQL SQLSvcAccount = $Node.SQLServiceAccount } - xSqlServerFirewall "FirewallMSSQLSERVER" + SqlWindowsFirewall "FirewallMSSQLSERVER" { DependsOn = "[xSQLServerFailoverClusterSetup]PrepareMSSQLSERVER" SourcePath = $Node.SourcePath @@ -126,8 +135,8 @@ Configuration SQL RetryIntervalSec = 5 RetryCount = 720 } - - xSQLServerFailoverClusterSetup "CompleteMSSQLSERVER" + + SqlServerDSCFailoverClusterSetup "CompleteMSSQLSERVER" { DependsOn = @( "[WaitForAll]Cluster", @@ -200,4 +209,3 @@ foreach($Node in $ConfigurationData.AllNodes) SQL -ConfigurationData $ConfigurationData Set-DscLocalConfigurationManager -Path .\SQL -Verbose Start-DscConfiguration -Path .\SQL -Verbose -Wait -Force - diff --git a/Examples/SQL-Standalone.ps1 b/Examples/SQL-Standalone.ps1 index 9f52781f8..a56f9d43f 100644 --- a/Examples/SQL-Standalone.ps1 +++ b/Examples/SQL-Standalone.ps1 @@ -1,11 +1,20 @@ -#requires -Version 5 - +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () Configuration SQLSA { - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC # Set role and instance variables $Roles = $AllNodes.Roles | Sort-Object -Unique @@ -20,7 +29,7 @@ Configuration SQLSA $Role.Contains("Database") -or $Role.Contains("Datawarehouse") -or $Role.Contains("Reporting") -or - $Role.Contains("Analysis") -or + $Role.Contains("Analysis") -or $Role.Contains("Integration") ) { @@ -28,7 +37,7 @@ Configuration SQLSA Set-Variable -Name ($Role.Replace(" ","").Replace(".","").Replace("Server","Instance")) -Value $Instance } } - } + } Node $AllNodes.NodeName { @@ -79,7 +88,7 @@ Configuration SQLSA ASConfigDir = "O:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Config" } - xSqlServerFirewall ($Node.NodeName + $SQLInstanceName) + SqlWindowsFirewall ($Node.NodeName + $SQLInstanceName) { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName + $SQLInstanceName) SourcePath = $Node.SourcePath @@ -146,4 +155,3 @@ foreach($Node in $ConfigurationData.AllNodes) SQLSA -ConfigurationData $ConfigurationData Set-DscLocalConfigurationManager -Path .\SQLSA -Verbose Start-DscConfiguration -Path .\SQLSA -Verbose -Wait -Force - diff --git a/Examples/SQLPush_SingleServer.ps1 b/Examples/SQLPush_SingleServer.ps1 index 209598d4f..05ef4a8d6 100644 --- a/Examples/SQLPush_SingleServer.ps1 +++ b/Examples/SQLPush_SingleServer.ps1 @@ -1,4 +1,14 @@ -#requires -Version 5 +<# + .NOTES + THIS EXAMPLE IS OBSOLETE. Due to major changes in the resource modules + over the last several versions, this example has not been updated to reflect + those changes. + Please refer to the resource example folder for updated examples. + https://github.com/PowerShell/SqlServerDsc/tree/master/Examples/Resources + + There is an issue open to replace this example, please see issue + https://github.com/PowerShell/SqlServerDsc/issues/462 +#> $computers = 'OHSQL1016' $OutputPath = 'D:\DSCLocal' $cim = New-CimSession -ComputerName $computers @@ -33,7 +43,7 @@ foreach ($computer in $computers) Configuration SQLSA { Import-DscResource –Module PSDesiredStateConfiguration - Import-DscResource -Module xSQLServer + Import-DscResource -Module SqlServerDSC Node $AllNodes.NodeName { @@ -71,7 +81,7 @@ Configuration SQLSA SQLBackupDir = "G:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data" } - xSqlServerFirewall ($Node.NodeName) + SqlWindowsFirewall ($Node.NodeName) { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) SourcePath = $Node.SourcePath @@ -79,7 +89,7 @@ Configuration SQLSA Features = $Node.Features } - xSQLServerMemory ($Node.Nodename) + SqlServerMemory ($Node.Nodename) { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) Ensure = "Present" @@ -87,13 +97,13 @@ Configuration SQLSA MinMemory = "256" MaxMemory ="1024" } - xSQLServerMaxDop($Node.Nodename) + SqlServerMaxDop($Node.Nodename) { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) Ensure = "Present" DynamicAlloc = $true } - xSQLServerLogin($Node.Nodename+"TestUser2") + SqlServerLogin($Node.Nodename+"TestUser2") { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) Ensure = "Present" @@ -101,7 +111,7 @@ Configuration SQLSA LoginCredential = $Node.InstallerServiceAccount LoginType = "SQLLogin" } - xSQLServerLogin($Node.Nodename+"TestUser1") + SqlServerLogin($Node.Nodename+"TestUser1") { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) Ensure = "Present" @@ -109,7 +119,7 @@ Configuration SQLSA LoginCredential = $Node.InstallerServiceAccount LoginType = "SQLLogin" } - xSQLServerDatabaseRole($Node.Nodename) + SqlDatabaseRole($Node.Nodename) { DependsOn = ("[xSqlServerSetup]" + $Node.NodeName) Ensure = "Present" @@ -123,18 +133,18 @@ Configuration SQLSA RecoveryModel = "Full" SqlServerInstance ="$($Node.NodeName)\$($Node.SQLInstanceName)" } - xSQLServerDatabaseOwner($Node.Nodename) + SqlDatabaseOwner($Node.Nodename) { Database = "TestDB" Name = "TestUser2" } - xSQLServerDatabasePermission($Node.Nodename) + SqlDatabasePermission($Node.Nodename) { Database = "Model" Name = "TestUser1" Permissions ="SELECT","DELETE" } - xSQLServerDatabase($Node.Nodename) + SqlDatabase($Node.Nodename) { Database = "Test3" Ensure = "Present" @@ -165,7 +175,7 @@ ForEach ($computer in $computers) { } $Destination = "\\"+$computer+"\\c$\Program Files\WindowsPowerShell\Modules" - Copy-Item 'C:\Program Files\WindowsPowerShell\Modules\xSQLServer' -Destination $Destination -Recurse -Force + Copy-Item 'C:\Program Files\WindowsPowerShell\Modules\SqlServerDSC' -Destination $Destination -Recurse -Force } SQLSA -ConfigurationData $ConfigurationData -OutputPath $OutputPath @@ -182,4 +192,3 @@ foreach($Computer in $Computers) { test-dscconfiguration -ComputerName $Computer } - diff --git a/README.md b/README.md index 499516b9c..21c9ed5b6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# xSQLServer +# SqlServerDsc -The **xSQLServer** module contains DSC resources for deployment and configuration -of SQL Server. +The **SqlServerDsc** module contains DSC resources +for deployment and configuration of SQL Server. This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) @@ -12,89 +12,96 @@ questions or comments. ### master -[![Build status](https://ci.appveyor.com/api/projects/status/mxn453y284eab8li/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xsqlserver/branch/master) -[![codecov](https://codecov.io/gh/PowerShell/xSQLServer/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xSQLServer/branch/master) +[![Build status](https://ci.appveyor.com/api/projects/status/mxn453y284eab8li/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/SqlServerDsc/branch/master) +[![codecov](https://codecov.io/gh/PowerShell/SqlServerDsc/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/SqlServerDsc/branch/master) -This is the branch containing the latest release - no contributions should be made -directly to this branch. +This is the branch containing the latest release - +no contributions should be made directly to this branch. ### dev -[![Build status](https://ci.appveyor.com/api/projects/status/mxn453y284eab8li/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xsqlserver/branch/dev) -[![codecov](https://codecov.io/gh/PowerShell/xSQLServer/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xSQLServer/branch/dev) +[![Build status](https://ci.appveyor.com/api/projects/status/mxn453y284eab8li/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/SqlServerDsc/branch/dev) +[![codecov](https://codecov.io/gh/PowerShell/SqlServerDsc/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/SqlServerDsc/branch/dev) -This is the development branch to which contributions should be proposed by contributors -as pull requests. This development branch will periodically be merged to the master -branch, and be released to [PowerShell Gallery](https://www.powershellgallery.com/). +This is the development branch +to which contributions should be proposed by contributors as pull requests. +This development branch will periodically be merged to the master branch, +and be released to [PowerShell Gallery](https://www.powershellgallery.com/). ## Contributing -Regardless of the way you want to contribute we are tremendously happy to have you -here. - -There are several ways you can contribute. You can submit an issue to report a bug. -You can submit an issue to request an improvement. You can take part in discussions -for issues. You can review pull requests and comment on other contributors changes. -You can also improve the resources and tests, or even create new resources, by -sending in pull requests yourself. - -* If you want to submit an issue or take part in discussions, please browse the - list of [issues](https://github.com/PowerShell/xSQLServer/issues). Please check - out [Contributing to the DSC Resource Kit](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md) +Regardless of the way you want to contribute +we are tremendously happy to have you here. + +There are several ways you can contribute. +You can submit an issue to report a bug. +You can submit an issue to request an improvement. +You can take part in discussions for issues. +You can review pull requests and comment on other contributors changes. +You can also improve the resources and tests, +or even create new resources, +by sending in pull requests yourself. + +* If you want to submit an issue or take part in discussions, + please browse the list of [issues](https://github.com/PowerShell/SqlServerDsc/issues). + Please check out [Contributing to the DSC Resource Kit](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md) on how to work with issues. -* If you want to review pull requests, please first check out the - [Review Pull Request guidelines](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md#reviewing-pull-requests), - and the browse the list of [pull requests](https://github.com/PowerShell/xSQLServer/pulls) +* If you want to review pull requests, + please first check out the [Review Pull Request guidelines](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md#reviewing-pull-requests), + and the browse the list of [pull requests](https://github.com/PowerShell/SqlServerDsc/pulls) and look for those pull requests with label 'needs review'. -* If you want to improve the resources or tests, or create a new resource, then - please check out the following guidelines. +* If you want to improve the resources or tests, + or create a new resource, + then please check out the following guidelines. * The [Contributing to the DSC Resource Kit](https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md) guidelines. - * The specific [Contributing to xSQLServer](https://github.com/PowerShell/xSQLServer/blob/dev/CONTRIBUTING.md) + * The specific [Contributing to SqlServerDsc](https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md) guidelines. * The common [Style Guidelines](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md). * The common [Best Practices](https://github.com/PowerShell/DscResources/blob/master/BestPractices.md) guidelines. * The common [Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md). - * If you are new to GitHub (and git), then please check out - [Getting Started with GitHub](https://github.com/PowerShell/DscResources/blob/master/GettingStartedWithGitHub.md). + * If you are new to GitHub (and git), + then please check out [Getting Started with GitHub](https://github.com/PowerShell/DscResources/blob/master/GettingStartedWithGitHub.md). * If you are new to Pester and writing test, then please check out [Getting started with Pester](https://github.com/PowerShell/DscResources/blob/master/GettingStartedWithPester.md). -If you need any help along the way, don't be afraid to ask. We are here for each -other. +If you need any help along the way, +don't be afraid to ask. +We are here for each other. ## Installation -To manually install the module, download the source code and unzip the contents -of the '\Modules\xSQLServer' directory to the +To manually install the module, +download the source code and unzip the contents +of the '\Modules\SqlServerDsc' directory to the '$env:ProgramFiles\WindowsPowerShell\Modules' folder. -To install from the PowerShell gallery using PowerShellGet (in PowerShell 5.0) run -the following command: +To install from the PowerShell gallery using PowerShellGet (in PowerShell 5.0) +run the following command: ```powershell -Find-Module -Name xSQLServer -Repository PSGallery | Install-Module +Find-Module -Name SqlServerDsc -Repository PSGallery | Install-Module ``` To confirm installation, run the below command and ensure you see the SQL Server DSC resources available: ```powershell -Get-DscResource -Module xSQLServer +Get-DscResource -Module SqlServerDsc ``` ## Requirements -The minimum Windows Management Framework (PowerShell) version required is 5.0 or -higher, which ships with Windows 10 or Windows Server 2016, but can also be -installed on Windows 7 SP1, Windows 8.1, Windows Server 2008 R2 SP1, -Windows Server 2012 and Windows Server 2012 R2. +The minimum Windows Management Framework (PowerShell) version required is 5.0 +or higher, which ships with Windows 10 or Windows Server 2016, +but can also be installed on Windows 7 SP1, Windows 8.1, +Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2. ## Examples -You can review the [Examples](/Examples) directory in the xSQLServer module for -some general use scenarios for all of the resources that are in the module. +You can review the [Examples](/Examples) directory in the SqlServerDsc module +for some general use scenarios for all of the resources that are in the module. ## Change log @@ -102,95 +109,62 @@ A full list of changes in each version can be found in the [change log](CHANGELO ## Resources -* [**xSQLServerAlias**](#xsqlserveralias) resource to manage SQL Server client Aliases. -* [**xSQLServerAlwaysOnAvailabilityGroup**](#xsqlserveralwaysonavailabilitygroup) +* [**SqlAG**](#sqlag) resource to ensure an availability group is present or absent. -* [**xSQLServerAlwayOnAvailabilityGroupDatabaseMembership**](#xsqlserveralwaysonavailabilitygroupdatabasemembership) +* [**SqlAGDatabase**](#sqlagdatabase) to manage the database membership in Availability Groups. -* [**xSQLServerAlwaysOnAvailabilityGroupReplica**](#xsqlserveralwaysonavailabilitygroupreplica) +* [**SqlAGListener**](#sqlaglistener) + Create or remove an availability group listener. +* [**SqlAGReplica**](#sqlagreplica) resource to ensure an availability group replica is present or absent. -* [**xSQLServerAlwaysOnService**](#xsqlserveralwaysonservice) resource to enable +* [**SqlAlias**](#sqlalias) resource to manage SQL Server client Aliases. +* [**SqlAlwaysOnService**](#sqlalwaysonservice) resource to enable always on on a SQL Server. -* [**xSQLServerAvailabilityGroupListener**](#xsqlserveravailabilitygrouplistener) - Create or remove an availability group listener. -* [**xSQLServerConfiguration**](#xsqlserverconfiguration) resource to manage - [SQL Server Configuration Options](https://msdn.microsoft.com/en-us/library/ms189631.aspx). -* [**xSQLServerDatabase**](#xsqlserverdatabase) resource to manage ensure database +* [**SqlDatabase**](#sqldatabase) resource to manage ensure database is present or absent. -* [**xSQLServerDatabaseDefaultLocation**](#xsqlserverdatabasedefaultlocation) resource +* [**SqlDatabaseDefaultLocation**](#sqldatabasedefaultlocation) resource to manage default locations for Data, Logs, and Backups for SQL Server -* [**xSQLServerDatabaseOwner**](#xsqlserverdatabaseowner) resource to manage SQL +* [**SqlDatabaseOwner**](#sqldatabaseowner) resource to manage SQL database owners. -* [**xSQLServerDatabasePermission**](#xsqlserverdatabasepermission) resource to +* [**SqlDatabasePermission**](#sqldatabasepermission) resource to manage SQL database permissions. -* [**xSQLServerDatabaseRecoveryModel**](#xsqlserverdatabaserecoverymodel) resource +* [**SqlDatabaseRecoveryModel**](#sqldatabaserecoverymodel) resource to manage database recovery model. -* [**xSQLServerDatabaseRole**](#xsqlserverdatabaserole) resource to manage SQL +* [**SqlDatabaseRole**](#sqldatabaserole) resource to manage SQL database roles. -* [**xSQLServerEndpoint**](#xsqlserverendpoint) resource to ensure database endpoint +* [**SqlRS**](#sqlrs) configures SQL Server Reporting + Services to use a database engine in another instance. +* [**SqlRSSecureConnectionLevel**](#sqlrssecureconnectionlevel) sets + the secure connection level for SQL Server Reporting Services. +* [**SqlScript**](#sqlscript) resource to extend DSC Get/Set/Test + functionality to T-SQL. +* [**SqlServerConfiguration**](#sqlserverconfiguration) resource to manage + [SQL Server Configuration Options](https://msdn.microsoft.com/en-us/library/ms189631.aspx). +* [**SqlServerEndpoint**](#sqlserverendpoint) resource to ensure database endpoint is present or absent. -* [**xSQLServerEndpointPermission**](#xsqlserverendpointpermission) Grant or revoke +* [**SqlServerEndpointPermission**](#sqlserverendpointpermission) Grant or revoke permission on the endpoint. -* [**xSQLServerEndpointState**](#xsqlserverendpointstate) Change state of the endpoint. -* [**xSQLServerFirewall**](#xsqlserverfirewall) configures firewall settings to - allow remote access to a SQL Server instance. -* [**xSQLServerLogin**](#xsqlserverlogin) resource to manage SQL logins. -* [**xSQLServerMaxDop**](#xsqlservermaxdop) resource to manage MaxDegree of Parallelism +* [**SqlServerEndpointState**](#sqlserverendpointstate) Change state of the endpoint. +* [**SqlServerLogin**](#sqlserverlogin) resource to manage SQL logins. +* [**SqlServerMaxDop**](#sqlservermaxdop) resource to manage MaxDegree of Parallelism for SQL Server. -* [**xSQLServerMemory**](#xsqlservermemory) resource to manage Memory for SQL Server. -* [**xSQLServerNetwork**](#xsqlservernetwork) resource to manage SQL Server Network +* [**SqlServerMemory**](#sqlservermemory) resource to manage Memory for SQL Server. +* [**SqlServerNetwork**](#sqlservernetwork) resource to manage SQL Server Network Protocols. -* [**xSQLServerPermission**](#xsqlserverpermission) Grant or revoke permission on +* [**SqlServerPermission**](#sqlserverpermission) Grant or revoke permission on the SQL Server. -* [**xSQLServerRole**](#xsqlserverrole) resource to manage SQL server roles. -* [**xSQLServerReplication**](#xsqlserverreplication) resource to manage SQL Replication +* [**SqlServerReplication**](#sqlserverreplication) resource to manage SQL Replication distribution and publishing. -* [**xSQLServerRSConfig**](#xsqlserverrsconfig) configures SQL Server Reporting - Services to use a database engine in another instance. -* [**xSQLServerRSSecureConnectionLevel**](#xsqlserverrssecureconnectionlevel) sets - the secure connection level for SQL Server Reporting Services. -* [**xSQLServerScript**](#xsqlserverscript) resource to extend DSC Get/Set/Test - functionality to T-SQL. -* [**xSQLServerServiceAccount**](#xsqlserverserviceaccount) Manage the service account +* [**SqlServerRole**](#sqlserverrole) resource to manage SQL server roles. +* [**SqlServiceAccount**](#sqlserviceaccount) Manage the service account for SQL Server services. -* [**xSQLServerSetup**](#xsqlserversetup) installs a standalone SQL Server instance. -* [**xWaitForAvailabilityGroup**](#xwaitforavailabilitygroup) resource to wait until - availability group is created on primary server. - -### xSQLServerAlias - -No description. - -#### Requirements - -* Target machine must be running Windows Server 2008 R2 or later. - -#### Parameters - -* **`[String]` Name** _(Key)_: The name of Alias (e.g. svr01\inst01). -* **`[String]` ServerName** _(Key)_: The SQL Server you are aliasing (the NetBIOS - name or FQDN). -* **`[String]` Ensure** _(Write)_: Determines whether the alias should be added or - removed. Default value is 'Present'. { *Present* | Absent }. -* **`[String]` Protocol** _(Write)_: Protocol to use when connecting. Valid values - are 'TCP' or 'NP' (Named Pipes). Default value is 'TCP'. { *TCP* | NP }. -* **`[Uint16]` TCPPort** _(Write)_: The TCP port SQL is listening on. Only used when - protocol is set to 'TCP'. Default value is port 1433. -* **`[Boolean]` UseDynamicTcpPort** _(Write)_: The UseDynamicTcpPort specify that - the Net-Library will determine the port dynamically. The port specified in Port - number will not be used. Default value is '$false'. - -#### Read-Only Properties from Get-TargetResource - -* **`[String]` PipeName** _(Read)_: Named Pipes path from the Get-TargetResource - method. - -#### Examples - -* [Add an SQL Server alias](/Examples/Resources/xSQLServerAlias/1-AddSQLServerAlias.ps1) -* [Remove an SQL Server alias](/Examples/Resources/xSQLServerAlias/2-RemoveSQLServerAlias.ps1) +* [**SqlSetup**](#sqlsetup) installs a standalone SQL Server instance. +* [**SqlWaitForAG**](#sqlwaitforag) resource to + wait until availability group is created on primary server. +* [**SqlWindowsFirewall**](#sqlwindowsfirewall) configures firewall settings to + allow remote access to a SQL Server instance. -### xSQLServerAlwaysOnAvailabilityGroup +### SqlAG This resource is used to create, remove, and update an Always On Availability Group. It will also manage the Availability Group replica on the specified node. @@ -205,8 +179,8 @@ It will also manage the Availability Group replica on the specified node. #### Parameters * **`[String]` Name** _(Key)_: The name of the availability group. -* **`[String]` SQLServer** _(Required)_: Hostname of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` ServerName** _(Required)_: Hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. * **`[String]` Ensure** _(Write)_: Specifies if the availability group should be present or absent. Default is Present. { *Present* | Absent } * **`[String]` AutomatedBackupPreference** _(Write)_: Specifies the automated backup @@ -255,8 +229,6 @@ It will also manage the Availability Group replica on the specified node. availability group replica endpoint. * **`[Uint32]` EndpointPort** _(Read)_: Gets the port the database mirroring endpoint is listening on -* **`[String]` SQLServerNetName** _(Read)_: Gets the hostname the SQL Server - instance is listening on. * **`[Uint32]` Version** _(Read)_: Gets the major version of the SQL Server instance. * **`[Boolean]` IsActiveNode** _(Read)_: Determines if the current node is @@ -264,11 +236,11 @@ It will also manage the Availability Group replica on the specified node. #### Examples -* [Add a SQL Server Always On Availability Group](/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/1-CreateAvailabilityGroup.ps1) -* [Add a SQL Server Always On Availability Group and explicitly defines its properties](/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/3-CreateAvailabilityGroupDetailed.ps1) -* [Remove a SQL Server Always On Availability Group](/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroup/2-RemoveAvailabilityGroup.ps1) +* [Add a SQL Server Always On Availability Group](/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1) +* [Add a SQL Server Always On Availability Group and explicitly defines its properties](/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1) +* [Remove a SQL Server Always On Availability Group](/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1) -### xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership +### SqlAGDatabase This resource is used to add and/or remove databases to a specified availability group. @@ -283,11 +255,11 @@ group. * **`[String]` DatabaseName** _(Required)_: The name of the database(s) to add to the availability group. This accepts wildcards. -* **`[String]` SQLServer** _(Key)_: Hostname of the SQL Server where the primary +* **`[String]` ServerName** _(Key)_: Hostname of the SQL Server where the primary replica of the availability group lives. If the availability group is not currently on this server, the resource will attempt to connect to the server where the primary replica lives. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance where the primary +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance where the primary replica of the availability group lives. If the availability group is not currently on this instance, the resource will attempt to connect to the instance where the primary replica lives. @@ -323,7 +295,59 @@ group. * **`[Boolean]` IsActiveNode** _(Read)_: Determines if the current node is actively hosting the SQL Server instance. -### xSQLServerAlwaysOnAvailabilityGroupReplica +#### Examples + +* [Add a database to an Availability Group](/Examples/Resources/SqlAGDatabase/1-AddDatabaseToAvailabilityGroup.ps1) +* [Remove a database from an Availability Group](/Examples/Resources/SqlAGDatabase/2-RemoveDatabaseFromAvailabilityGroup.ps1) +* [Enforce only specified databases as member in an Availability Group](/Examples/Resources/SqlAGDatabase/3-MatchDefinedDatabaseInAvailabilityGroup.ps1) + +### SqlAGListener + +No description. + +#### Requirements + +* Target machine must be running Windows Server 2008 R2 or later. +* Target machine must be running SQL Server Database Engine 2012 or later. +* Target machine must have access to the SQLPS PowerShell module or the SqlServer + PowerShell module. +* Requires that the Cluster name Object (CNO) has been delegated the right + _Create Computer Object_ in the organizational unit (OU) in which the + Cluster Name Object (CNO) resides. + +#### Parameters + +* **`[String]` InstanceName** _(Key)_: The SQL Server instance name of the primary + replica. +* **`[String]` AvailabilityGroup** _(Key)_: The name of the availability group to + which the availability group listener is or will be connected. +* **`[String]` ServerName** _(Write)_: The host name or FQDN of the primary replica. +* **`[String]` Ensure** _(Write)_: If the availability group listener should be present + or absent. Default value is 'Present'. { *Present* | Absent }. +* **`[String]` Name** _(Write)_: The name of the availability group listener, max + 15 characters. This name will be used as the Virtual Computer Object (VCO). +* **`[String[]]` IpAddress** _(Write)_: The IP address used for the availability + group listener, in the format 192.168.10.45/255.255.252.0. If using DHCP, set + to the first IP-address of the DHCP subnet, in the format 192.168.8.1/255.255.252.0. + Must be valid in the cluster-allowed IP range. +* **`[Uint16]` Port** _(Write)_: The port used for the availability group listener. +* **`[Boolean]` DHCP** _(Write)_: If DHCP should be used for the availability group + listener instead of static IP address. + +#### Examples + +* [Adds an Availability Group listener with the same name as the + Availability Group VCO](/Examples/Resources/SqlAGListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1) +* [Adds an Availability Group listener with a different name than the + Availability Group VCO](/Examples/Resources/SqlAGListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1) +* [Removes an Availability Group listener with the same name as the + Availability Group VCO](/Examples/Resources/SqlAGListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1) +* [Removes an Availability Group listener with a different name than the + Availability Group VCO](/Examples/Resources/SqlAGListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1) +* [Adds an Availability Group listener using DHCP on the default server subnet](/Examples/Resources/SqlAGListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1) +* [Adds an Availability Group listener using DHCP with a specific subnet](/Examples/Resources/SqlAGListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1) + +### SqlAGReplica This resource is used to create, remove, and update an Always On Availability Group Replica. @@ -340,13 +364,13 @@ Always On Availability Group Replica. * **`[String]` Name** _(Key)_: The name of the availability group replica. For named instances this must be in the following format SQLServer\InstanceName. * **`[String]` AvailabilityGroupName** _(Key)_: The name of the availability group. -* **`[String]` SQLServer** _(Required)_: Hostname of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured. -* **`[String]` PrimaryReplicaSQLServer** _(Write)_: Hostname of the SQL Server where +* **`[String]` ServerName** _(Required)_: Hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` PrimaryReplicaServerName** _(Write)_: Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it. -* **`[String]` PrimaryReplicaSQLInstanceName** _(Write)_: Name of the SQL instance +* **`[String]` PrimaryReplicaInstanceName** _(Write)_: Name of the SQL instance where the primary replica lives. * **`[String]` Ensure** _(Write)_: Specifies if the availability group replica should be present or absent. Default is Present. { *Present* | Absent } @@ -384,121 +408,78 @@ Always On Availability Group Replica. listening on. Used by Get-TargetResource. * **`[String]` EndpointUrl** _(Read)_: Output the endpoint URL of the Availability Group Replica. Used by Get-TargetResource. -* **`[String]` SQLServerNetName** _(Read)_: Output the NetName property from the - SQL Server object. * **`[Boolean]` IsActiveNode** _(Read)_: Determines if the current node is actively hosting the SQL Server instance. #### Examples -* [Add a SQL Server Always On Availability Group Replica](/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/1-CreateAvailabilityGroupReplica.ps1) -* [Remove a SQL Server Always On Availability Group Replica](/Examples/Resources/xSQLServerAlwaysOnAvailabilityGroupReplica/2-RemoveAvailabilityGroupReplica.ps1) +* [Add a SQL Server Always On Availability Group Replica](/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1) +* [Remove a SQL Server Always On Availability Group Replica](/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1) -### xSQLServerAlwaysOnService +### SqlAlias -Enables or disabled SQL Server Always On high availability and disaster recovery -(Always On HADR). +No description. #### Requirements * Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Database Engine 2012 or later. #### Parameters -* **`[String]` SQLServer** _(Key)_: The hostname of the SQL Server to be configured. -* **`[String]` SQLInstance** _(Key)_: The name of the SQL instance to be configured. -* **`[String]` Ensure** _(Required)_: An enumerated value that describes if the SQL - Server should have Always On high availability and disaster recovery (HADR) - property enabled ('Present') or disabled ('Absent'). { Present | Absent }. -* **`[Sint32]` RestartTimeout** _(Write)_: The length of time, in seconds, to wait - for the service to restart. Default is 120 seconds. +* **`[String]` Name** _(Key)_: The name of Alias (e.g. svr01\inst01). +* **`[String]` ServerName** _(Key)_: The SQL Server you are aliasing (the NetBIOS + name or FQDN). +* **`[String]` Ensure** _(Write)_: Determines whether the alias should be added or + removed. Default value is 'Present'. { *Present* | Absent }. +* **`[String]` Protocol** _(Write)_: Protocol to use when connecting. Valid values + are 'TCP' or 'NP' (Named Pipes). Default value is 'TCP'. { *TCP* | NP }. +* **`[Uint16]` TCPPort** _(Write)_: The TCP port SQL is listening on. Only used when + protocol is set to 'TCP'. Default value is port 1433. +* **`[Boolean]` UseDynamicTcpPort** _(Write)_: The UseDynamicTcpPort specify that + the Net-Library will determine the port dynamically. The port specified in Port + number will not be used. Default value is '$false'. #### Read-Only Properties from Get-TargetResource -* **`[Boolean]` IsHadrEnabled** _(Read)_: Returns the status of AlwaysOn high - availability and disaster recovery (HADR). +* **`[String]` PipeName** _(Read)_: Named Pipes path from the Get-TargetResource + method. #### Examples -* [Enable SQL Server Always On](/Examples/Resources/xSQLServerAlwaysOnService/1-EnableAlwaysOn.ps1) -* [Disable SQL Server Always On](/Examples/Resources/xSQLServerAlwaysOnService/1-DisableAlwaysOn.ps1) +* [Add an SQL Server alias](/Examples/Resources/SqlAlias/1-AddSqlAlias.ps1) +* [Remove an SQL Server alias](/Examples/Resources/SqlAlias/2-RemoveSqlAlias.ps1) -### xSQLServerAvailabilityGroupListener +### SqlAlwaysOnService -No description. +Enables or disabled SQL Server Always On high availability and disaster recovery +(Always On HADR). #### Requirements * Target machine must be running Windows Server 2008 R2 or later. * Target machine must be running SQL Server Database Engine 2012 or later. -* Target machine must have access to the SQLPS PowerShell module or the SqlServer - PowerShell module. -* Requires that the Cluster name Object (CNO) has been delegated the right - _Create Computer Object_ in the organizational unit (OU) in which the - Cluster Name Object (CNO) resides. #### Parameters -* **`[String]` InstanceName** _(Key)_: The SQL Server instance name of the primary - replica. -* **`[String]` AvailabilityGroup** _(Key)_: The name of the availability group to - which the availability group listener is or will be connected. -* **`[String]` NodeName** _(Write)_: The host name or FQDN of the primary replica. -* **`[String]` Ensure** _(Write)_: If the availability group listener should be present - or absent. Default value is 'Present'. { *Present* | Absent }. -* **`[String]` Name** _(Write)_: The name of the availability group listener, max - 15 characters. This name will be used as the Virtual Computer Object (VCO). -* **`[String[]]` IpAddress** _(Write)_: The IP address used for the availability - group listener, in the format 192.168.10.45/255.255.252.0. If using DHCP, set - to the first IP-address of the DHCP subnet, in the format 192.168.8.1/255.255.252.0. - Must be valid in the cluster-allowed IP range. -* **`[Uint16]` Port** _(Write)_: The port used for the availability group listener. -* **`[Boolean]` DHCP** _(Write)_: If DHCP should be used for the availability group - listener instead of static IP address. - -#### Examples - -* [Adds an Availability Group listener with the same name as the - Availability Group VCO](/Examples/Resources/xSQLServerAvailabilityGroupListener/1-AddAvailabilityGroupListenerWithSameNameAsVCO.ps1) -* [Adds an Availability Group listener with a different name than the - Availability Group VCO](/Examples/Resources/xSQLServerAvailabilityGroupListener/2-AddAvailabilityGroupListenerWithDifferentNameAsVCO.ps1) -* [Removes an Availability Group listener with the same name as the - Availability Group VCO](/Examples/Resources/xSQLServerAvailabilityGroupListener/3-RemoveAvailabilityGroupListenerWithSameNameAsVCO.ps1) -* [Removes an Availability Group listener with a different name than the - Availability Group VCO](/Examples/Resources/xSQLServerAvailabilityGroupListener/4-RemoveAvailabilityGroupListenerWithDifferentNameAsVCO.ps1) -* [Adds an Availability Group listener using DHCP on the default server subnet](/Examples/Resources/xSQLServerAvailabilityGroupListener/5-AddAvailabilityGroupListenerUsingDHCPWithDefaultServerSubnet.ps1) -* [Adds an Availability Group listener using DHCP with a specific subnet](/Examples/Resources/xSQLServerAvailabilityGroupListener/6-AddAvailabilityGroupListenerUsingDHCPWithSpecificSubnet.ps1) - -### xSQLServerConfiguration - -No description. - -#### Requirements - -* Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Database Engine 2008 or later. - -#### Parameters - -* **`[String]` SQLServer** _(Key)_: The hostname of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured. -* **`[String]` OptionName** _(Key)_: The name of the SQL configuration option to - be checked. For all possible values reference [MSDN](https://msdn.microsoft.com/en-us/library/ms189631.aspx) - or run sp_configure. -* **`[Sint32]` OptionValue** _(Required)_: The desired value of the SQL configuration - option. -* **`[Boolean]` RestartService** _(Write)_: Determines whether the instance should - be restarted after updating the configuration option. +* **`[String]` ServerName** _(Key)_: The hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` Ensure** _(Required)_: An enumerated value that describes if the SQL + Server should have Always On high availability and disaster recovery (HADR) + property enabled ('Present') or disabled ('Absent'). { Present | Absent }. * **`[Sint32]` RestartTimeout** _(Write)_: The length of time, in seconds, to wait for the service to restart. Default is 120 seconds. +#### Read-Only Properties from Get-TargetResource + +* **`[Boolean]` IsHadrEnabled** _(Read)_: Returns the status of AlwaysOn high + availability and disaster recovery (HADR). + #### Examples -* [Configure two instances on the same server to have CLR enabled](/Examples/Resources/xSQLServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1) -* [Configure a instance to have 'Priority Boost' enabled](/Examples/Resources/xSQLServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1) +* [Enable SQL Server Always On](/Examples/Resources/SqlAlwaysOnService/1-EnableAlwaysOn.ps1) +* [Disable SQL Server Always On](/Examples/Resources/SqlAlwaysOnService/1-DisableAlwaysOn.ps1) -### xSQLServerDatabase +### SqlDatabase This resource is used to create or delete a database. For more information about database, please read: @@ -513,8 +494,8 @@ database, please read: #### Parameters -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` Name** _(Key)_: The name of database to be created or dropped. * **`[String]` Collation** _(Write)_: The name of the SQL collation to use for the new database. Defaults to server collation. @@ -523,10 +504,10 @@ database, please read: #### Examples -* [Create a Database](/Examples/Resources/xSQLServerDatabase/1-CreateDatabase.ps1) -* [Delete a database](/Examples/Resources/xSQLServerDatabase/2-DeleteDatabase.ps1) +* [Create a Database](/Examples/Resources/SqlDatabase/1-CreateDatabase.ps1) +* [Delete a database](/Examples/Resources/SqlDatabase/2-DeleteDatabase.ps1) -### xSQLServerDatabaseDefaultLocation +### SqlDatabaseDefaultLocation This resource is used to configure default locations for user databases. The types of default locations that can be changed are Data, Log, and Backup. For @@ -540,8 +521,8 @@ more information about database default locations, please read the article #### Parameters -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` Type** _(Key)_: The type of database default location to be configured. { Data | Log | Backup } @@ -560,9 +541,9 @@ more information about database default locations, please read the article #### Examples -* [Set database default locations](/Examples/Resources/xSQLServerDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1) +* [Set database default locations](/Examples/Resources/SqlDatabaseDefaultLocation/1-SetDatabaseDefaultLocation.ps1) -### xSQLServerDatabaseOwner +### SqlDatabaseOwner This resource is used to configure the owner of a database. For more information about database owner, please read the article @@ -578,14 +559,14 @@ For more information about database owner, please read the article * **`[String]` Database** _(Key)_: The name of database to be configured. * **`[String]` Name** _(Required)_: The name of the login that will become a owner of the desired sql database. -* **`[String]` SQLServer** _(Write)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstance** _(Write)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Write)_: The name of the SQL instance to be configured. #### Examples -* [Set database owner](/Examples/Resources/xSQLServerDatabaseOwner/1-SetDatabaseOwner.ps1) +* [Set database owner](/Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1) -### xSQLServerDatabasePermission +### SqlDatabasePermission This resource is used to grant, deny or revoke permissions for a user in a database. For more information about permissions, please read the article @@ -602,9 +583,9 @@ will also get their permission revoked. #### Parameters -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. Default values is '$env:COMPUTERNAME'. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. Default value is 'MSSQLSERVER'. * **`[String]` Database** _(Key)_: The name of the database. * **`[String]` Name** _(Key)_: The name of the user that should be granted or denied @@ -619,11 +600,11 @@ will also get their permission revoked. #### Examples -* [Grant Database Permission](/Examples/Resources/xSQLServerDatabasePermission/1-GrantDatabasePermissions.ps1) -* [Revoke Database Permission](/Examples/Resources/xSQLServerDatabasePermission/2-RevokeDatabasePermissions.ps1) -* [Deny Database Permission](/Examples/Resources/xSQLServerDatabasePermission/3-DenyDatabasePermissions.ps1) +* [Grant Database Permission](/Examples/Resources/SqlDatabasePermission/1-GrantDatabasePermissions.ps1) +* [Revoke Database Permission](/Examples/Resources/SqlDatabasePermission/2-RevokeDatabasePermissions.ps1) +* [Deny Database Permission](/Examples/Resources/SqlDatabasePermission/3-DenyDatabasePermissions.ps1) -### xSQLServerDatabaseRecoveryModel +### SqlDatabaseRecoveryModel This resource set the recovery model for a database. The recovery model controls how transactions are logged, whether the transaction log requires (and allows) @@ -640,16 +621,16 @@ Read more about recovery model in this article #### Parameters * **`[String]` Name** _(Key)_: The SQL database name. -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` RecoveryModel** _(Required)_: The recovery model to use for the database. { Full | Simple | BulkLogged }. #### Examples -* [Set the RecoveryModel of a database](/Examples/Resources/xSQLServerDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1) +* [Set the RecoveryModel of a database](/Examples/Resources/SqlDatabaseRecoveryModel/1-SetDatabaseRecoveryModel.ps1) -### xSQLServerDatabaseRole +### SqlDatabaseRole This resource is used to add or remove role for a login in a database. Read more about database role in this article [CREATE ROLE (Transact-SQL)](https://msdn.microsoft.com/en-us/library/ms187936.aspx) @@ -663,8 +644,8 @@ Read more about database role in this article [CREATE ROLE (Transact-SQL)](https * **`[String]` Name** _(Key)_: The name of the login that will become a member, or removed as a member, of the role(s). -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` Database** _(Key)_: The database in which the login (user) and role(s) exist. * **`[String]` Ensure** _(Write)_: If 'Present' (the default value) then the login @@ -675,190 +656,268 @@ Read more about database role in this article [CREATE ROLE (Transact-SQL)](https #### Examples -* [Add Role of a database](/Examples/Resources/xSQLServerDatabaseRole/1-AddDatabaseRole.ps1) -* [Remove Role of a database](/Examples/Resources/xSQLServerDatabaseRole/2-RemoveDatabaseRole.ps1) +* [Add Role of a database](/Examples/Resources/SqlDatabaseRole/1-AddDatabaseRole.ps1) +* [Remove Role of a database](/Examples/Resources/SqlDatabaseRole/2-RemoveDatabaseRole.ps1) -### xSQLServerEndpoint - -This resource is used to create an endpoint. Currently it only supports creating -a database mirror endpoint which can be used by, for example, AlwaysOn. +### SqlRS ->Note: The endpoint will be started after creation, but will not be enforced. Please -use [**xSQLServerEndpointState**](#xsqlserverendpointstate) to make sure the endpoint -remains in started state. To set connect permission to the endpoint, please use -the resource [**xSQLServerEndpointPermission**](#xsqlserverendpointpermission). +Initializes and configures SQL Reporting Services server. #### Requirements * Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Database Engine 2008 or later. +* Target machine must be running SQL Server Reporting Services 2008 or later. +* If `PsDscRunAsCredential` common parameter is used to run the resource, the + specified credential must have permissions to connect to the SQL Server specified + in `RSSQLServer` and create Reporting Services databases. -#### Security Requirements +#### Parameters -* The built-in parameter PsDscRunAsCredential must be set to the credentials of - an account with the permission to create and alter endpoints. +* **`[String]` InstanceName** _(Key)_: Name of the SQL Server Reporting Services + instance to be configured. +* **`[String]` DatabaseServerName** _(Required)_: Name of the SQL Server to host + the Reporting Service database. +* **`[String]` DatabaseInstanceName** _(Required)_: Name of the SQL Server instance + to host the Reporting Service database. +* **`[String]` ReportServerVirtualDir** _(Write)_: Report Server Web Service virtual + directory. Optional. +* **`[String]` ReportsVirtualDir** _(Write)_: Report Manager/Report Web App virtual + directory name. Optional. +* **`[String[]]` ReportServerReservedUrl** _(Write)_: Report Server URL reservations. + Optional. If not specified, 'http://+:80' URL reservation will be used. +* **`[String[]]` ReportsReservedUrl** _(Write)_: Report Manager/Report Web App URL + reservations. Optional. If not specified, 'http://+:80' URL reservation will be + used. -#### Parameters +#### Read-Only Properties from Get-TargetResource -* **`[String]` EndpointName** _(Key)_: The name of the endpoint. -* **`[String]` Ensure** _(Write)_: If the endpoint should be present or absent. - Default values is 'Present'. { *Present* | Absent }. -* **`[Uint16]` Port** _(Write)_: The network port the endpoint is listening on. - Default value is 5022. -* **`[String]` SQLServer** _(Write)_: The host name of the SQL Server to be configured. - Default value is $env:COMPUTERNAME. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. -* **`[String]` IpAddress** _(Write)_: The network IP address the endpoint is listening - on. Defaults to '0.0.0.0' which means listen on any valid IP address. +* **`[Boolean]` IsInitialized** _(Read)_: Output is the Reporting Services instance + initialized. #### Examples -None. +* [Default configuration](Examples/Resources/SqlRS/1-DefaultConfiguration.ps1) +* [Custom virtual directories and reserved URLs](Examples/Resources/SqlRS/2-CustomConfiguration.ps1) -### xSQLServerEndpointPermission +### SqlRSSecureConnectionLevel -This resource is used to give connect permission to an endpoint for a user (login). +No description. #### Requirements * Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Database Engine 2008 or later. +* Target machine must be running SQL Server Reporting Services 2008 or later. #### Parameters -* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. -* **`[String]` NodeName** _(Required)_: The host name of the SQL Server to be configured. -* **`[String]` Ensure** _(Write)_: If the permission should be present or absent. - Default value is 'Present'. { *Present* | Absent }. -* **`[String]` Name** _(Required)_: The name of the endpoint. -* **`[String]` Principal** _(Key)_: The login to which permission will be set. -* **`[String]` Permission** _(Write)_: The permission to set for the login. Valid - value for permission are only CONNECT. { Connect }. +* **`[String]` InstanceName** _(Key)_: SQL instance to set secure connection level + for. +* **`[Uint16]` SecureConnectionLevel** _(Key)_: SQL Server Reporting Service secure + connection level. +* **`[PSCredential]` SQLAdminCredential** _(Required)_: Credential with administrative + permissions to the SQL instance. #### Examples -* [Add connect permission to an Endpoint](/Examples/Resources/xSQLServerEndpointPermission/1-AddConnectPermission.ps1) -* [Remove the connect permission for an Endpoint](/Examples/Resources/xSQLServerEndpointPermission/2-RemoveConnectPermission.ps1) -* [Add connect permission to both an Always On primary replica and an Always On - secondary replica, and where each replica has a different SQL service account](/Examples/Resources/xSQLServerEndpointPermission/3-AddConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1) -* [Remove connect permission to both an Always On primary replica and an - Always On secondary replica, and where each replica has a different SQL service - account](/Examples/Resources/xSQLServerEndpointPermission/4-RemoveConnectPermissionToAlwaysOnPrimaryAndSecondaryReplicaEachWithDifferentSqlServiceAccounts.ps1) +None. -### xSQLServerEndpointState +### SqlScript -This resource is used to set the state of an endpoint. +Provides the means to run a user generated T-SQL script on the SQL Server instance. +Three scripts are required; Get T-SQL script, Set T-SQL script and the Test T-SQL +script. ->Note: Currently this resource can only be used with Database Mirror endpoints. +#### Scripts + +##### Get T-SQL Script (GetFilePath) + +The Get T-SQL script is used to query the status when running the cmdlet +Get-DscConfiguration, and the result can be found in the property `GetResult`. + +##### Test T-SQL Script (TestFilePath) + +The Test T-SQL script is used to test if the desired state is met. If Test +T-SQL raises an error or returns any value other than 'null' the test fails, thus +the Set T-SQL script is run. + +##### Set T-SQL Script (SetFilePath) + +The Set T-SQL script performs the actual change when Test T-SQL script fails. #### Requirements * Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Database Engine 2008 or later. +* Target machine must be running SQL Server 2008 or later. * Target machine must have access to the SQLPS PowerShell module or the SqlServer PowerShell module. +_Note: There is a known problem running this resource using PowerShell 4.0. +See [issue #273](https://github.com/PowerShell/SqlServerDsc/issues/273) +for more information._ + #### Parameters -* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. -* **`[String]` NodeName** _(Write)_: The host name of the SQL Server to be configured. - Default value is $env:COMPUTERNAME. -* **`[String]` Name** _(Key)_: The name of the endpoint. -* **`[String]` State** _(Write)_: The state of the endpoint. Valid states are Started, - Stopped or Disabled. Default value is 'Started'. - { *Started* | Stopped | Disabled }. +* **`[String]` ServerInstance** _(Key)_: The name of an instance of the Database + Engine. For a default instance, only specify the computer name. For a named + instances, use the format ComputerName\\InstanceName. +* **`[String]` SetFilePath** _(Key)_: Path to the T-SQL file that will perform Set + action. +* **`[String]` GetFilePath** _(Key)_: Path to the T-SQL file that will perform Get + action. Any values returned by the T-SQL queries will also be returned by the + cmdlet Get-DscConfiguration through the `GetResult` property. +* **`[String]` TestFilePath** _(Key)_: Path to the T-SQL file that will perform Test + action. Any script that does not throw an error or returns null is evaluated to + true. The cmdlet Invoke-Sqlcmd treats T-SQL Print statements as verbose text, + and will not cause the test to return false. +* **`[PSCredential]` Credential** _(Write)_: The credentials to authenticate with, + using SQL Authentication. To authenticate using Windows Authentication, assign + the credentials to the built-in parameter `PsDscRunAsCredential`. If both parameters + `Credential` and `PsDscRunAsCredential` are not assigned, then SYSTEM account will + be used to authenticate using Windows Authentication. +* **`[UInt32]` QueryTimeout** _(Write)_: Specifies, as an integer, the number of + seconds after which the T-SQL script execution will time out. In some SQL Server + versions there is a bug in Invoke-Sqlcmd where the normal default value 0 (no + timeout) is not respected and the default value is incorrectly set to 30 seconds. +* **`[String[]]` Variable** _(Write)_: Specifies, as a string array, a scripting + variable for use in the sql script, and sets a value for the variable. Use a + Windows PowerShell array to specify multiple variables and their values. For more + information how to use this, please go to the help documentation for [Invoke-Sqlcmd](https://technet.microsoft.com/en-us/library/mt683370.aspx). + +#### Read-Only Properties from Get-TargetResource + +* **`[String]` GetResult** _(Read)_: Contains the values returned from the T-SQL + script provided in the parameter `GetFilePath` when cmdlet Get-DscConfiguration + is run. #### Examples -* [Make sure that an endpoint is started](/Examples/Resources/xSQLServerEndpointState/1-MakeSureEndpointIsStarted.ps1) -* [Make sure that an endpoint is stopped](/Examples/Resources/xSQLServerEndpointState/2-MakeSureEndpointIsStopped.ps1) +* [Run a script using SQL Authentication](/Examples/Resources/SqlScript/1-RunScriptUsingSQLAuthentication.ps1) +* [Run a script using Windows Authentication](/Examples/Resources/SqlScript/2-RunScriptUsingWindowsAuthentication.ps1) -### xSQLServerFirewall +### SqlServerConfiguration -This will set default firewall rules for the supported features. Currently the -features supported are Database Engine, Analysis Services, SQL Browser, -SQL Reporting Services and Integration Services. +No description. -#### Firewall rules +#### Requirements -##### Database Engine (SQLENGINE) - Default instance +* Target machine must be running Windows Server 2008 R2 or later. +* Target machine must be running SQL Server Database Engine 2008 or later. -Firewall Rule | Firewall Display Name ---- | --- -Application: sqlservr.exe | SQL Server Database Engine instance MSSQLSERVER -Service: SQLBrowser | SQL Server Browser +#### Parameters -##### Database Engine (SQLENGINE) - Named instance +* **`[String]` ServerName** _(Key)_: The hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` OptionName** _(Key)_: The name of the SQL configuration option to + be checked. For all possible values reference [MSDN](https://msdn.microsoft.com/en-us/library/ms189631.aspx) + or run sp_configure. +* **`[Sint32]` OptionValue** _(Required)_: The desired value of the SQL configuration + option. +* **`[Boolean]` RestartService** _(Write)_: Determines whether the instance should + be restarted after updating the configuration option. +* **`[Sint32]` RestartTimeout** _(Write)_: The length of time, in seconds, to wait + for the service to restart. Default is 120 seconds. -Firewall Rule | Firewall Display Name ---- | --- -Application: sqlservr.exe | SQL Server Database Engine instance \ -Service: SQLBrowser | SQL Server Browser +#### Examples -##### Analysis Services (AS) - Default instance +* [Configure two instances on the same server to have CLR enabled](/Examples/Resources/SqlServerConfiguration/1-ConfigureTwoInstancesOnTheSameServerToEnableClr.ps1) +* [Configure a instance to have 'Priority Boost' enabled](/Examples/Resources/SqlServerConfiguration/2-ConfigureInstanceToEnablePriorityBoost.ps1) -Firewall Rule | Firewall Display Name ---- | --- -Service: MSSQLServerOLAPService | SQL Server Analysis Services instance MSSQLSERVER -Service: SQLBrowser | SQL Server Browser +### SqlServerEndpoint -##### Analysis Services (AS) - Named instance +This resource is used to create an endpoint. Currently it only supports creating +a database mirror endpoint which can be used by, for example, AlwaysOn. -Firewall Rule | Firewall Display Name ---- | --- -Service: MSOLAP$\ | SQL Server Analysis Services instance \ -Service: SQLBrowser | SQL Server Browser +>Note: The endpoint will be started after creation, but will not be enforced. Please +use [**SqlServerEndpointState**](#xsqlserverendpointstate) to make sure the endpoint +remains in started state. To set connect permission to the endpoint, please use +the resource [**SqlServerEndpointPermission**](#xsqlserverendpointpermission). + +#### Requirements + +* Target machine must be running Windows Server 2008 R2 or later. +* Target machine must be running SQL Server Database Engine 2008 or later. + +#### Security Requirements + +* The built-in parameter PsDscRunAsCredential must be set to the credentials of + an account with the permission to create and alter endpoints. + +#### Parameters + +* **`[String]` EndpointName** _(Key)_: The name of the endpoint. +* **`[String]` Ensure** _(Write)_: If the endpoint should be present or absent. + Default values is 'Present'. { *Present* | Absent }. +* **`[Uint16]` Port** _(Write)_: The network port the endpoint is listening on. + Default value is 5022. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is $env:COMPUTERNAME. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` IpAddress** _(Write)_: The network IP address the endpoint is listening + on. Defaults to '0.0.0.0' which means listen on any valid IP address. + +#### Examples + +None. + +### SqlServerEndpointPermission + +This resource is used to give connect permission to an endpoint for a user (login). + +#### Requirements + +* Target machine must be running Windows Server 2008 R2 or later. +* Target machine must be running SQL Server Database Engine 2008 or later. + +#### Parameters + +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Required)_: The host name of the SQL Server to be configured. +* **`[String]` Ensure** _(Write)_: If the permission should be present or absent. + Default value is 'Present'. { *Present* | Absent }. +* **`[String]` Name** _(Required)_: The name of the endpoint. +* **`[String]` Principal** _(Key)_: The login to which permission will be set. +* **`[String]` Permission** _(Write)_: The permission to set for the login. Valid + value for permission are only CONNECT. { Connect }. -##### Reporting Services (RS) +#### Examples -Firewall Rule | Firewall Display Name ---- | --- -Port: tcp/80 | SQL Server Reporting Services 80 -Port: tcp/443 | SQL Server Reporting Services 443 +* [Add connect permission to an Endpoint](/Examples/Resources/SqlServerEndpointPermission/1-AddConnectPermission.ps1) +* [Remove the connect permission for an Endpoint](/Examples/Resources/SqlServerEndpointPermission/2-RemoveConnectPermission.ps1) +* [Add connect permission to both an Always On primary replica and an Always On + secondary replica, and where each replica has a different SQL service account](/Examples/Resources/SqlServerEndpointPermission/3-AddConnectPermissionToTwoReplicasEachWithDifferentServiceAccount.ps1) +* [Remove connect permission to both an Always On primary replica and an + Always On secondary replica, and where each replica has a different SQL service + account](/Examples/Resources/SqlServerEndpointPermission/4-RemoveConnectPermissionForTwoReplicasEachWithDifferentServiceAccount.ps1) -##### Integration Services (IS) +### SqlServerEndpointState -Firewall Rule | Firewall Display Name ---- | --- -Application: MsDtsSrvr.exe | SQL Server Integration Services Application -Port: tcp/135 | SQL Server Integration Services Port +This resource is used to set the state of an endpoint. + +>Note: Currently this resource can only be used with Database Mirror endpoints. #### Requirements * Target machine must be running Windows Server 2008 R2 or later. +* Target machine must be running SQL Server Database Engine 2008 or later. +* Target machine must have access to the SQLPS PowerShell module or the SqlServer + PowerShell module. #### Parameters -* **`[String]` Features** _(Key)_: SQL features to enable firewall rules for. -* **`[String]` InstanceName** _(Key)_: SQL instance to enable firewall rules for. -* **`[String]` Ensure** _(Write)_: Ensures that SQL firewall rules are **Present** - or **Absent** on the machine. { *Present* | Absent }. -* **`[String]` SourcePath** _(Write)_: UNC path to the root of the source files for - installation. -* **`[String]` SourceCredential** _(Write)_: Credentials used to access the path - set in the parameter 'SourcePath'. This parameter is optional either if built-in - parameter 'PsDscRunAsCredential' is used, or if the source path can be access - using the SYSTEM account. - -#### Read-Only Properties from Get-TargetResource - -* **`[Boolean]` DatabaseEngineFirewall** _(Read)_: Is the firewall rule for the - Database Engine enabled? -* **`[Boolean]` BrowserFirewall** _(Read)_: Is the firewall rule for the Browser - enabled? -* **`[Boolean]` ReportingServicesFirewall** _(Read)_: Is the firewall rule for - Reporting Services enabled? -* **`[Boolean]` AnalysisServicesFirewall** _(Read)_: Is the firewall rule for - Analysis Services enabled? -* **`[Boolean]` IntegrationServicesFirewall** _(Read)_: Is the firewall rule for - the Integration Services enabled? +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is $env:COMPUTERNAME. +* **`[String]` Name** _(Key)_: The name of the endpoint. +* **`[String]` State** _(Write)_: The state of the endpoint. Valid states are Started, + Stopped or Disabled. Default value is 'Started'. + { *Started* | Stopped | Disabled }. #### Examples -* [Create inbound firewall rules](/Examples/Resources/xSQLServerFirewall/1-CreateInboundFirewallRules.ps1) -* [Remove inbound firewall rules](/Examples/Resources/xSQLServerFirewall/2-RemoveInboundFirewallRules.ps1) +* [Make sure that an endpoint is started](/Examples/Resources/SqlServerEndpointState/1-MakeSureEndpointIsStarted.ps1) +* [Make sure that an endpoint is stopped](/Examples/Resources/SqlServerEndpointState/2-MakeSureEndpointIsStopped.ps1) -### xSQLServerLogin +### SqlServerLogin No description. @@ -869,8 +928,8 @@ No description. #### Parameters -* **`[String]` SQLServer** _(Key)_:The hostname of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` ServerName** _(Key)_:The hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. * **`[String]` Name** _(Key)_: The name of the login. * **`[String]` Ensure** _(Write)_: The specified login is Present or Absent. { *Present* | Absent }. @@ -896,7 +955,7 @@ No description. None. -### xSQLServerMaxDop +### SqlServerMaxDop This resource set the max degree of parallelism server configuration option. The max degree of parallelism option is used to limit the number of processors to @@ -922,8 +981,8 @@ Read more about max degree of parallelism in this article #### Parameters -* **`[String]` SQLInstance** (Key): The name of the SQL instance to be configured. -* **`[String]` SQLServer** _(Write)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** (Key): The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. * **`[String]` Ensure** _(Write)_: When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured @@ -946,11 +1005,11 @@ Read more about max degree of parallelism in this article #### Examples -* [Set SQLServerMaxDop to 1](/Examples/Resources/xSQLServerMaxDop/1-SetMaxDopToOne.ps1) -* [Set SQLServerMaxDop to Auto](/Examples/Resources/xSQLServerMaxDop/2-SetMaxDopToAuto.ps1) -* [Set SQLServerMaxDop to Default](/Examples/Resources/xSQLServerMaxDop/3-SetMaxDopToDefault.ps1) +* [Set SQLServerMaxDop to 1](/Examples/Resources/SqlServerMaxDop/1-SetMaxDopToOne.ps1) +* [Set SQLServerMaxDop to Auto](/Examples/Resources/SqlServerMaxDop/2-SetMaxDopToAuto.ps1) +* [Set SQLServerMaxDop to Default](/Examples/Resources/SqlServerMaxDop/3-SetMaxDopToDefault.ps1) -### xSQLServerMemory +### SqlServerMemory This resource sets the minimum server memory and maximum server memory configuration option. @@ -996,8 +1055,8 @@ SQL Max Memory = TotalPhysicalMemory - (NumOfSQLThreads\*ThreadStackSize) - #### Parameters -* **`[String]` SQLInstance** _(Key)_: The name of the SQL instance to be configured. -* **`[String]` SQLServer** _(Write)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. * **`[Boolean]` DynamicAlloc** _(Write)_: If set to $true then max memory will be dynamically configured. When this is set parameter is set to $true, the parameter @@ -1021,12 +1080,12 @@ SQL Max Memory = TotalPhysicalMemory - (NumOfSQLThreads\*ThreadStackSize) - #### Examples -* [Set SQLServerMaxMemory to 12GB](/Examples/Resources/xSQLServerMemory/1-SetMaxMemoryTo12GB.ps1) -* [Set SQLServerMaxMemory to Auto](/Examples/Resources/xSQLServerMemory/2-SetMaxMemoryToAuto.ps1) -* [Set SQLServerMinMemory to 2GB and SQLServerMaxMemory to Auto](/Examples/Resources/xSQLServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1) -* [Set SQLServerMaxMemory to Default](/Examples/Resources/xSQLServerMemory/3-SetMaxMemoryToDefault.ps1) +* [Set SQLServerMaxMemory to 12GB](/Examples/Resources/SqlServerMemory/1-SetMaxMemoryTo12GB.ps1) +* [Set SQLServerMaxMemory to Auto](/Examples/Resources/SqlServerMemory/2-SetMaxMemoryToAuto.ps1) +* [Set SQLServerMinMemory to 2GB and SQLServerMaxMemory to Auto](/Examples/Resources/SqlServerMemory/3-SetMinMemoryToFixedValueAndMaxMemoryToAuto.ps1) +* [Set SQLServerMaxMemory to Default](/Examples/Resources/SqlServerMemory/3-SetMaxMemoryToDefault.ps1) -### xSQLServerNetwork +### SqlServerNetwork This resource is used to change the network settings for the instance. @@ -1045,7 +1104,7 @@ Read more about the network settings in the article * **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` ProtocolName** _(Required)_: The name of network protocol to be configured. Only tcp is currently supported. { tcp }. -* **`[String]` SQLServer** _(Write)_: The host name of the SQL Server to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. * **`[Boolean]` IsEnabled** _(Write)_: Enables or disables the network protocol. * **`[Boolean]` TcpDynamicPort** _(Write)_: Specifies whether the SQL Server @@ -1063,10 +1122,10 @@ Read more about the network settings in the article #### Examples -* [Enable TCP/IP with static port and restart SQL Server](/Examples/Resources/xSQLServerNetwork/1-EnableTcpIpWithStaticPort.ps1) -* [Enable TCP/IP with dynamic port](/Examples/Resources/xSQLServerNetwork/2-EnableTcpIpWithDynamicPort.ps1) +* [Enable TCP/IP with static port and restart SQL Server](/Examples/Resources/SqlServerNetwork/1-EnableTcpIpWithStaticPort.ps1) +* [Enable TCP/IP with dynamic port](/Examples/Resources/SqlServerNetwork/2-EnableTcpIpWithDynamicPort.ps1) -### xSQLServerPermission +### SqlServerPermission This resource sets server permissions to a user (login). @@ -1086,7 +1145,7 @@ AlterAnyEndPoint and ViewServerState. * **`[String]` Principal** _(Key)_: The login to which permission will be set. * **`[String]` Ensure** _(Write)_: If the permission should be present or absent. Default value is 'Present'. { Present | Absent }. -* **`[String]` NodeName** _(Write)_: The host name of the SQL Server to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. * **`[String[]]` Permission** _(Write)_: The permission to set for the login. Valid values are ConnectSql, AlterAnyAvailabilityGroup, ViewServerState or AlterAnyEndPoint. @@ -1094,10 +1153,10 @@ AlterAnyEndPoint and ViewServerState. #### Examples -* [Add server permission for a login](/Examples/Resources/xSQLServerPermission/1-AddServerPermissionForLogin.ps1) -* [Remove server permission for a login](/Examples/Resources/xSQLServerPermission/2-RemoveServerPermissionForLogin.ps1) +* [Add server permission for a login](/Examples/Resources/SqlServerPermission/1-AddServerPermissionForLogin.ps1) +* [Remove server permission for a login](/Examples/Resources/SqlServerPermission/2-RemoveServerPermissionForLogin.ps1) -### xSQLServerReplication +### SqlServerReplication No description. @@ -1130,10 +1189,10 @@ No description. #### Examples -* [Configure a instance as the distributor](/Examples/Resources/xSQLServerReplication/1-ConfigureInstanceAsDistributor.ps1) -* [Configure a instance as the publisher](/Examples/Resources/xSQLServerReplication/2-ConfigureInstanceAsPublisher.ps1) +* [Configure a instance as the distributor](/Examples/Resources/SqlServerReplication/1-ConfigureInstanceAsDistributor.ps1) +* [Configure a instance as the publisher](/Examples/Resources/SqlServerReplication/2-ConfigureInstanceAsPublisher.ps1) -### xSQLServerRole +### SqlServerRole This resource is used to create a server role, when Ensure is set to 'Present'. Or remove a server role, when Ensure is set to 'Absent'. The resource also manages @@ -1151,8 +1210,8 @@ server roles, please read the below articles. #### Parameters * **`[String]` ServerRoleName** _(Key)_: The name of of SQL role to add or remove. -* **`[String]` SQLServer** _(Key)_: The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: The name of the SQL instance to be configured. +* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. * **`[String]` Ensure** _(Write)_: An enumerated value that describes if the server role is added (Present) or dropped (Absent). Default value is 'Present'. { *Present* | Absent }. @@ -1169,147 +1228,13 @@ server roles, please read the below articles. #### Examples -* [Add server role](/Examples/Resources/xSQLServerRole/1-AddServerRole.ps1) -* [Remove server role](/Examples/Resources/xSQLServerRole/2-RemoveServerRole.ps1) -* [Add members to server role](/Examples/Resources/xSQLServerRole/3-AddMembersToServerRole.ps1) -* [Members to include in server role](/Examples/Resources/xSQLServerRole/4-MembersToIncludeInServerRole.ps1) -* [Members to exclude from server role](/Examples/Resources/xSQLServerRole/5-MembersToExcludeInServerRole.ps1) - -### xSQLServerRSConfig - -Initializes and configures SQL Reporting Services server. - -#### Requirements - -* Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Reporting Services 2008 or later. -* If `PsDscRunAsCredential` common parameter is used to run the resource, the - specified credential must have permissions to connect to the SQL Server specified - in `RSSQLServer` and create Reporting Services databases. - -#### Parameters - -* **`[String]` InstanceName** _(Key)_: Name of the SQL Server Reporting Services - instance to be configured. -* **`[String]` RSSQLServer** _(Required)_: Name of the SQL Server to host the - Reporting Service database. -* **`[String]` RSSQLInstanceName** _(Required)_: Name of the SQL Server instance - to host the Reporting Service database. -* **`[String]` ReportServerVirtualDir** _(Write)_: Report Server Web Service virtual - directory. Optional. -* **`[String]` ReportsVirtualDir** _(Write)_: Report Manager/Report Web App virtual - directory name. Optional. -* **`[String[]]` ReportServerReservedUrl** _(Write)_: Report Server URL reservations. - Optional. If not specified, 'http://+:80' URL reservation will be used. -* **`[String[]]` ReportsReservedUrl** _(Write)_: Report Manager/Report Web App URL - reservations. Optional. If not specified, 'http://+:80' URL reservation will be - used. - -#### Read-Only Properties from Get-TargetResource - -* **`[Boolean]` IsInitialized** _(Read)_: Output is the Reporting Services instance - initialized. - -#### Examples - -* [Default configuration](Examples/Resources/xSQLServerRSConfig/1-DefaultConfiguration.ps1) -* [Custom virtual directories and reserved URLs](Examples/Resources/xSQLServerRSConfig/2-CustomConfiguration.ps1) - -### xSQLServerRSSecureConnectionLevel - -No description. - -#### Requirements - -* Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server Reporting Services 2008 or later. - -#### Parameters - -* **`[String]` InstanceName** _(Key)_: SQL instance to set secure connection level - for. -* **`[Uint16]` SecureConnectionLevel** _(Key)_: SQL Server Reporting Service secure - connection level. -* **`[PSCredential]` SQLAdminCredential** _(Required)_: Credential with administrative - permissions to the SQL instance. - -#### Examples - -None. - -### xSQLServerScript - -Provides the means to run a user generated T-SQL script on the SQL Server instance. -Three scripts are required; Get T-SQL script, Set T-SQL script and the Test T-SQL -script. - -#### Scripts - -##### Get T-SQL Script (GetFilePath) - -The Get T-SQL script is used to query the status when running the cmdlet -Get-DscConfiguration, and the result can be found in the property `GetResult`. - -##### Test T-SQL Script (TestFilePath) - -The Test T-SQL script is used to test if the desired state is met. If Test -T-SQL raises an error or returns any value other than 'null' the test fails, thus -the Set T-SQL script is run. - -##### Set T-SQL Script (SetFilePath) - -The Set T-SQL script performs the actual change when Test T-SQL script fails. - -#### Requirements - -* Target machine must be running Windows Server 2008 R2 or later. -* Target machine must be running SQL Server 2008 or later. -* Target machine must have access to the SQLPS PowerShell module or the SqlServer - PowerShell module. - -_Note: There is a known problem running this resource using PowerShell 4.0. -See [issue #273](https://github.com/PowerShell/xSQLServer/issues/273) for more information._ - -#### Parameters - -* **`[String]` ServerInstance** _(Key)_: The name of an instance of the Database - Engine. For a default instance, only specify the computer name. For a named - instances, use the format ComputerName\\InstanceName. -* **`[String]` SetFilePath** _(Key)_: Path to the T-SQL file that will perform Set - action. -* **`[String]` GetFilePath** _(Key)_: Path to the T-SQL file that will perform Get - action. Any values returned by the T-SQL queries will also be returned by the - cmdlet Get-DscConfiguration through the `GetResult` property. -* **`[String]` TestFilePath** _(Key)_: Path to the T-SQL file that will perform Test - action. Any script that does not throw an error or returns null is evaluated to - true. The cmdlet Invoke-Sqlcmd treats T-SQL Print statements as verbose text, - and will not cause the test to return false. -* **`[PSCredential]` Credential** _(Write)_: The credentials to authenticate with, - using SQL Authentication. To authenticate using Windows Authentication, assign - the credentials to the built-in parameter `PsDscRunAsCredential`. If both parameters - `Credential` and `PsDscRunAsCredential` are not assigned, then SYSTEM account will - be used to authenticate using Windows Authentication. -* **`[UInt32]` QueryTimeout** _(Write)_: Specifies, as an integer, the number of - seconds after which the T-SQL script execution will time out. In some SQL Server - versions there is a bug in Invoke-Sqlcmd where the normal default value 0 (no - timeout) is not respected and the default value is incorrectly set to 30 seconds. -* **`[String[]]` Variable** _(Write)_: Specifies, as a string array, a scripting - variable for use in the sql script, and sets a value for the variable. Use a - Windows PowerShell array to specify multiple variables and their values. For more - information how to use this, please go to the help documentation for [Invoke-Sqlcmd](https://technet.microsoft.com/en-us/library/mt683370.aspx). - -#### Read-Only Properties from Get-TargetResource - -* **`[String]` GetResult** _(Read)_: Contains the values returned from the T-SQL - script provided in the parameter `GetFilePath` when cmdlet Get-DscConfiguration - is run. - -#### Examples - -* [Run a script using SQL Authentication](/Examples/Resources/xSQLServerScript/1-RunScriptUsingSQLAuthentication.ps1) -* [Run a script using Windows Authentication](/Examples/Resources/xSQLServerScript/2-RunScriptUsingWindowsAuthentication.ps1) +* [Add server role](/Examples/Resources/SqlServerRole/1-AddServerRole.ps1) +* [Remove server role](/Examples/Resources/SqlServerRole/2-RemoveServerRole.ps1) +* [Add members to server role](/Examples/Resources/SqlServerRole/3-AddMembersToServerRole.ps1) +* [Members to include in server role](/Examples/Resources/SqlServerRole/4-MembersToIncludeInServerRole.ps1) +* [Members to exclude from server role](/Examples/Resources/SqlServerRole/5-MembersToExcludeInServerRole.ps1) -### xSQLServerServiceAccount +### SqlServiceAccount Manage the service account for SQL Server services. @@ -1320,9 +1245,9 @@ Manage the service account for SQL Server services. #### Parameters -* **`[String]` SQLServer** (Key): The host name of the SQL Server to be configured. -* **`[String]` SQLInstanceName** (Key): The name of the SQL instance to be configured. -* **`[String]` ServiceType** (Key): The service type for **SQLInstanceName**. +* **`[String]` ServerName** (Key): The host name of the SQL Server to be configured. +* **`[String]` InstanceName** (Key): The name of the SQL instance to be configured. +* **`[String]` ServiceType** (Key): The service type for **InstanceName**. { DatabaseEngine | SQLServerAgent | Search | IntegrationServices | AnalysisServices | ReportingServices | SQLServerBrowser | NotificationServices } @@ -1336,10 +1261,10 @@ Manage the service account for SQL Server services. #### Examples -* [Run service under a user account](/Examples/Resources/xSQLServerServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1) -* [Run service with a virtual account](/Examples/Resources/xSQLServerServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1) +* [Run service under a user account](/Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1) +* [Run service with a virtual account](/Examples/Resources/SqlServiceAccount/2-ConfigureServiceAccount-VirtualAccount.ps1) -### xSQLServerSetup +### SqlSetup Installs SQL Server on the target node. @@ -1483,15 +1408,15 @@ installing feature Database Engine and Analysis Services respectively. #### Examples -* [Install a default instance on a single server](/Examples/Resources/xSQLServerSetup/1-InstallDefaultInstanceSingleServer.ps1) -* [Install a named instance on a single server](/Examples/Resources/xSQLServerSetup/2-InstallNamedInstanceSingleServer.ps1) -* [Install a named instance on a single server from an UNC path using SourceCredential](/Examples/Resources/xSQLServerSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1) -* [Install a named instance as the first node in SQL Server Failover Cluster](/Examples/Resources/xSQLServerSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1) -* [Install a named instance as the second node in SQL Server Failover Cluster](/Examples/Resources/xSQLServerSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1) +* [Install a default instance on a single server](/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1) +* [Install a named instance on a single server](/Examples/Resources/SqlSetup/2-InstallNamedInstanceSingleServer.ps1) +* [Install a named instance on a single server from an UNC path using SourceCredential](/Examples/Resources/SqlSetup/3-InstallNamedInstanceSingleServerFromUncPathUsingSourceCredential.ps1) +* [Install a named instance as the first node in SQL Server Failover Cluster](/Examples/Resources/SqlSetup/4-InstallNamedInstanceInFailoverClusterFirstNode.ps1) +* [Install a named instance as the second node in SQL Server Failover Cluster](/Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1) #### Known issues -All issues are not listed here, see [here for all open issues](https://github.com/PowerShell/xSQLServer/issues?q=is%3Aissue%20is%3Aopen%20xSQLServerSetup). +All issues are not listed here, see [here for all open issues](https://github.com/PowerShell/SqlServerDsc/issues?q=is%3Aissue%20is%3Aopen%20SqlSetup). ##### Severe known issues @@ -1499,7 +1424,7 @@ This is a list of known issues that severely impact the use of the resource. There are currently no known severe issues. -### xWaitForAvailabilityGroup +### SqlWaitForAG This resource will wait for a cluster role/group to be created. This is used to wait for an Availability Group to create the cluster role/group in the cluster. @@ -1538,5 +1463,90 @@ or that it has finished creating the Availability Group. #### Examples -* [Wait for a cluster role/group to be available](/Examples/Resources/xWaitForAvailabilityGroup/1-WaitForASingleClusterGroup.ps1) -* [Wait for multiple cluster roles/groups to be available](/Examples/Resources/xWaitForAvailabilityGroup/2-WaitForMultipleClusterGroups.ps1) +* [Wait for a cluster role/group to be available](/Examples/Resources/SqlWaitForAG/1-WaitForASingleClusterGroup.ps1) +* [Wait for multiple cluster roles/groups to be available](/Examples/Resources/SqlWaitForAG/2-WaitForMultipleClusterGroups.ps1) + +### SqlWindowsFirewall + +This will set default firewall rules for the supported features. Currently the +features supported are Database Engine, Analysis Services, SQL Browser, +SQL Reporting Services and Integration Services. + +#### Firewall rules + +##### Database Engine (SQLENGINE) - Default instance + +Firewall Rule | Firewall Display Name +--- | --- +Application: sqlservr.exe | SQL Server Database Engine instance MSSQLSERVER +Service: SQLBrowser | SQL Server Browser + +##### Database Engine (SQLENGINE) - Named instance + +Firewall Rule | Firewall Display Name +--- | --- +Application: sqlservr.exe | SQL Server Database Engine instance \ +Service: SQLBrowser | SQL Server Browser + +##### Analysis Services (AS) - Default instance + +Firewall Rule | Firewall Display Name +--- | --- +Service: MSSQLServerOLAPService | SQL Server Analysis Services instance MSSQLSERVER +Service: SQLBrowser | SQL Server Browser + +##### Analysis Services (AS) - Named instance + +Firewall Rule | Firewall Display Name +--- | --- +Service: MSOLAP$\ | SQL Server Analysis Services instance \ +Service: SQLBrowser | SQL Server Browser + +##### Reporting Services (RS) + +Firewall Rule | Firewall Display Name +--- | --- +Port: tcp/80 | SQL Server Reporting Services 80 +Port: tcp/443 | SQL Server Reporting Services 443 + +##### Integration Services (IS) + +Firewall Rule | Firewall Display Name +--- | --- +Application: MsDtsSrvr.exe | SQL Server Integration Services Application +Port: tcp/135 | SQL Server Integration Services Port + +#### Requirements + +* Target machine must be running Windows Server 2008 R2 or later. + +#### Parameters + +* **`[String]` Features** _(Key)_: SQL features to enable firewall rules for. +* **`[String]` InstanceName** _(Key)_: SQL instance to enable firewall rules for. +* **`[String]` Ensure** _(Write)_: Ensures that SQL firewall rules are **Present** + or **Absent** on the machine. { *Present* | Absent }. +* **`[String]` SourcePath** _(Write)_: UNC path to the root of the source files for + installation. +* **`[String]` SourceCredential** _(Write)_: Credentials used to access the path + set in the parameter 'SourcePath'. This parameter is optional either if built-in + parameter 'PsDscRunAsCredential' is used, or if the source path can be access + using the SYSTEM account. + +#### Read-Only Properties from Get-TargetResource + +* **`[Boolean]` DatabaseEngineFirewall** _(Read)_: Is the firewall rule for the + Database Engine enabled? +* **`[Boolean]` BrowserFirewall** _(Read)_: Is the firewall rule for the Browser + enabled? +* **`[Boolean]` ReportingServicesFirewall** _(Read)_: Is the firewall rule for + Reporting Services enabled? +* **`[Boolean]` AnalysisServicesFirewall** _(Read)_: Is the firewall rule for + Analysis Services enabled? +* **`[Boolean]` IntegrationServicesFirewall** _(Read)_: Is the firewall rule for + the Integration Services enabled? + +#### Examples + +* [Create inbound firewall rules](/Examples/Resources/SqlWindowsFirewall/1-CreateInboundFirewallRules.ps1) +* [Remove inbound firewall rules](/Examples/Resources/SqlWindowsFirewall/2-RemoveInboundFirewallRules.ps1) diff --git a/SQLServerDsc.psd1 b/SQLServerDsc.psd1 new file mode 100644 index 000000000..dd9df3aa0 --- /dev/null +++ b/SQLServerDsc.psd1 @@ -0,0 +1,187 @@ +@{ + # Version number of this module. + ModuleVersion = '10.0.0.0' + + # ID used to uniquely identify this module + GUID = '693ee082-ed36-45a7-b490-88b07c86b42f' + + # Author of this module + Author = 'Microsoft Corporation' + + # Company or vendor of this module + CompanyName = 'Microsoft Corporation' + + # Copyright statement for this module + Copyright = '(c) 2017 Microsoft Corporation. All rights reserved.' + + # Description of the functionality provided by this module + Description = 'Module with DSC Resources for deployment and configuration of Microsoft SQL Server.' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.0' + + # Minimum version of the common language runtime (CLR) required by this module + CLRVersion = '4.0' + + # Functions to export from this module + FunctionsToExport = '*' + + # Cmdlets to export from this module + CmdletsToExport = '*' + + RequiredAssemblies = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') + + # A URL to the license for this module. + LicenseUri = 'https://github.com/PowerShell/SqlServerDsc/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/PowerShell/SqlServerDsc' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + ReleaseNotes = '- BREAKING CHANGE: Resource module has been renamed to SqlServerDsc + ([issue 916](https://github.com/PowerShell/SqlServerDsc/issues/916)). +- BREAKING CHANGE: Significant rename to reduce length of resource names + - See [issue 851](https://github.com/PowerShell/SqlServerDsc/issues/851) for a + complete table mapping rename changes. + - Impact to all resources. +- Changes to CONTRIBUTING.md + - Added details to the naming convention used in SqlServerDsc. +- Changes to SqlServerDsc + - The examples in the root of the Examples folder are obsolete. A note was + added to the comment-based help in each example stating it is obsolete. + This is a temporary measure until they are replaced + ([issue 904](https://github.com/PowerShell/SqlServerDsc/issues/904)). + - Added new common test (regression test) for validating the long path + issue for compiling resources in Azure Automation. + - Fix resources in alphabetical order in README.md ([issue 908](https://github.com/PowerShell/SqlServerDsc/issues/908)). +- Changes to SqlAG + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - BREAKING CHANGE: The read-only property SQLServerNetName was removed in favor + of EndpointHostName ([issue 924](https://github.com/PowerShell/SqlServerDsc/issues/924)). + Get-TargetResource will now return the value of property [NetName](https://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.netname(v=sql.105).aspx) + for the property EndpointHostName. +- Changes to SqlAGDatabase + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - Changed the Get-MatchingDatabaseNames function to be case insensitive when + matching database names ([issue 912](https://github.com/PowerShell/SqlServerDsc/issues/912)). +- Changes to SqlAGListener + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlAGReplica + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - BREAKING CHANGE: Parameters PrimaryReplicaSQLServer and PrimaryReplicaSQLInstanceName + has been renamed to PrimaryReplicaServerName and PrimaryReplicaInstanceName + respectively ([issue 922](https://github.com/PowerShell/SqlServerDsc/issues/922)). + - BREAKING CHANGE: The read-only property SQLServerNetName was removed in favor + of EndpointHostName ([issue 924](https://github.com/PowerShell/SqlServerDsc/issues/924)). + Get-TargetResource will now return the value of property [NetName](https://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.netname(v=sql.105).aspx) + for the property EndpointHostName. +- Changes to SqlAlwaysOnService + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabase + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes SqlDatabaseDefaultLocation + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseOwner + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabasePermission + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseRecoveryModel + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlDatabaseRole + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlRS + - BREAKING CHANGE: Parameters RSSQLServer and RSSQLInstanceName has been renamed + to DatabaseServerName and DatabaseInstanceName respectively + ([issue 923](https://github.com/PowerShell/SqlServerDsc/issues/923)). +- Changes to SqlServerConfiguration + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerEndpoint + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerEndpointPermission + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + - Now the examples files have a shorter name so that resources will not fail + to compile in Azure Automation ([issue 934](https://github.com/PowerShell/SqlServerDsc/issues/934)). +- Changes to SqlServerEndpointState + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerLogin + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerMaxDop + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerMemory + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerNetwork + - BREAKING CHANGE: Parameters SQLServer has been renamed to ServerName + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerPermission + - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerRole + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). +- Changes to SqlServerServiceAccount + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectively + ([issue 308](https://github.com/PowerShell/SqlServerDsc/issues/308)). + +' + + } # End of PSData hashtable + + } # End of PrivateData hashtable + } + + + + + + + + + + + diff --git a/xSQLServerHelper.psm1 b/SqlServerDscHelper.psm1 similarity index 98% rename from xSQLServerHelper.psm1 rename to SqlServerDscHelper.psm1 index 62e6e1d25..bc8048448 100644 --- a/xSQLServerHelper.psm1 +++ b/SqlServerDscHelper.psm1 @@ -3,7 +3,7 @@ Import-Module -Name (Join-Path -Path (Join-Path -Path $PSScriptRoot ` -ChildPath 'DscResources') ` -ChildPath 'CommonResourceHelper.psm1') -$script:localizedData = Get-LocalizedData -ResourceName 'xSQLServerHelper' -ScriptRoot $PSScriptRoot +$script:localizedData = Get-LocalizedData -ResourceName 'SqlServerDscHelper' -ScriptRoot $PSScriptRoot <# .SYNOPSIS @@ -342,8 +342,8 @@ function Get-SqlInstanceMajorVersion Returns a localized error message. This helper function is obsolete, should use new helper functions. - https://github.com/PowerShell/xSQLServer/blob/dev/CONTRIBUTING.md#localization - https://github.com/PowerShell/xSQLServer/blob/dev/DSCResources/CommonResourceHelper.psm1 + https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#localization + https://github.com/PowerShell/SqlServerDsc/blob/dev/DSCResources/CommonResourceHelper.psm1 Strings in this function has not been localized since this helper function should be removed when all resources has moved over to the new localization, @@ -441,7 +441,7 @@ function New-TerminatingError This helper function is obsolete, should use Write-Warning together with individual resource localization strings. - https://github.com/PowerShell/xSQLServer/blob/dev/CONTRIBUTING.md#localization + https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#localization Strings in this function has not been localized since this helper function should be removed when all resources has moved over to the new localization, @@ -496,7 +496,7 @@ function New-WarningMessage This helper function is obsolete, should use Write-Verbose together with individual resource localization strings. - https://github.com/PowerShell/xSQLServer/blob/dev/CONTRIBUTING.md#localization + https://github.com/PowerShell/SqlServerDsc/blob/dev/CONTRIBUTING.md#localization Strings in this function has not been localized since this helper function should be removed when all resources has moved over to the new localization, diff --git a/Tests/Integration/MSFT_xSQLServerAlwaysOnService.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 similarity index 98% rename from Tests/Integration/MSFT_xSQLServerAlwaysOnService.Integration.Tests.ps1 rename to Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 index b93a57c94..09d3ed29b 100644 --- a/Tests/Integration/MSFT_xSQLServerAlwaysOnService.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlAlwaysOnService.Integration.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceFriendlyName = 'xSQLServerAlwaysOnService' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceFriendlyName = 'SqlAlwaysOnService' $script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" if (-not $env:APPVEYOR -eq $true) diff --git a/Tests/Integration/MSFT_xSQLServerAlwaysOnService.config.ps1 b/Tests/Integration/MSFT_SqlAlwaysOnService.config.ps1 similarity index 90% rename from Tests/Integration/MSFT_xSQLServerAlwaysOnService.config.ps1 rename to Tests/Integration/MSFT_SqlAlwaysOnService.config.ps1 index 973013303..c4d79906b 100644 --- a/Tests/Integration/MSFT_xSQLServerAlwaysOnService.config.ps1 +++ b/Tests/Integration/MSFT_SqlAlwaysOnService.config.ps1 @@ -15,7 +15,7 @@ $ConfigurationData = @{ ) } -Configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config +Configuration MSFT_SqlAlwaysOnService_EnableAlwaysOn_Config { param ( @@ -26,7 +26,7 @@ Configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config ) Import-DscResource -ModuleName 'PSDscResources' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { WindowsFeature 'AddFeatureFailoverClustering' @@ -123,11 +123,11 @@ Configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config } } - xSQLServerAlwaysOnService 'Integration_Test' + SqlAlwaysOnService 'Integration_Test' { Ensure = 'Present' - SQLServer = $Node.ComputerName - SQLInstanceName = $Node.InstanceName + ServerName = $Node.ComputerName + InstanceName = $Node.InstanceName RestartTimeout = $Node.RestartTimeout PsDscRunAsCredential = $SqlInstallCredential @@ -141,7 +141,7 @@ Configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config } } -Configuration MSFT_xSQLServerAlwaysOnService_DisableAlwaysOn_Config +Configuration MSFT_SqlAlwaysOnService_DisableAlwaysOn_Config { param ( @@ -151,14 +151,14 @@ Configuration MSFT_xSQLServerAlwaysOnService_DisableAlwaysOn_Config $SqlInstallCredential ) - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { - xSQLServerAlwaysOnService 'Integration_Test' + SqlAlwaysOnService 'Integration_Test' { Ensure = 'Absent' - SQLServer = $Node.ComputerName - SQLInstanceName = $Node.InstanceName + ServerName = $Node.ComputerName + InstanceName = $Node.InstanceName RestartTimeout = $Node.RestartTimeout PsDscRunAsCredential = $SqlInstallCredential diff --git a/Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 similarity index 98% rename from Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.Integration.Tests.ps1 rename to Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 index 5db3676f6..281c8ca91 100644 --- a/Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.Integration.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceFriendlyName = 'xSQLServerDatabaseDefaultLocation' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceFriendlyName = 'SqlDatabaseDefaultLocation' $script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" if (-not $env:APPVEYOR -eq $true) diff --git a/Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.config.ps1 b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 similarity index 67% rename from Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.config.ps1 rename to Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 index 048c9b47e..4fdd6a7a1 100644 --- a/Tests/Integration/MSFT_xSQLServerDatabaseDefaultLocation.config.ps1 +++ b/Tests/Integration/MSFT_SqlDatabaseDefaultLocation.config.ps1 @@ -19,7 +19,7 @@ $ConfigurationData = @{ ) } -Configuration MSFT_xSQLServerDatabaseDefaultLocation_Data_Config +Configuration MSFT_SqlDatabaseDefaultLocation_Data_Config { param ( @@ -30,7 +30,7 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Data_Config ) Import-DscResource -ModuleName 'PSDesiredStateConfiguration' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { File 'SQLDataPath' @@ -42,22 +42,22 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Data_Config Type = 'Directory' } - xSQLServerDatabaseDefaultLocation 'Integration_Test' + SqlDatabaseDefaultLocation 'Integration_Test' { - Type = 'Data' - Path = $Node.DataFilePath + Type = 'Data' + Path = $Node.DataFilePath RestartService = $true - SQLServer = $Node.ComputerName - SQLInstanceName = $Node.InstanceName + ServerName = $Node.ComputerName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SqlInstallCredential - DependsOn = '[File]SQLDataPath' + DependsOn = '[File]SQLDataPath' } } } -Configuration MSFT_xSQLServerDatabaseDefaultLocation_Log_Config +Configuration MSFT_SqlDatabaseDefaultLocation_Log_Config { param ( @@ -68,7 +68,7 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Log_Config ) Import-DscResource -ModuleName 'PSDesiredStateConfiguration' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { File 'SQLLogPath' @@ -80,22 +80,22 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Log_Config Type = 'Directory' } - xSQLServerDatabaseDefaultLocation 'Integration_Test' + SqlDatabaseDefaultLocation 'Integration_Test' { - Type = 'Log' - Path = $Node.LogFilePath + Type = 'Log' + Path = $Node.LogFilePath RestartService = $true - SQLServer = $Node.ComputerName - SQLInstanceName = $Node.InstanceName + ServerName = $Node.ComputerName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SqlInstallCredential - DependsOn = '[File]SQLLogPath' + DependsOn = '[File]SQLLogPath' } } } -Configuration MSFT_xSQLServerDatabaseDefaultLocation_Backup_Config +Configuration MSFT_SqlDatabaseDefaultLocation_Backup_Config { param ( @@ -106,7 +106,7 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Backup_Config ) Import-DscResource -ModuleName 'PSDesiredStateConfiguration' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { File 'SQLBackupPath' @@ -118,17 +118,17 @@ Configuration MSFT_xSQLServerDatabaseDefaultLocation_Backup_Config Type = 'Directory' } - xSQLServerDatabaseDefaultLocation 'Integration_Test' + SqlDatabaseDefaultLocation 'Integration_Test' { - Type = 'Backup' - Path = $Node.BackupFilePath + Type = 'Backup' + Path = $Node.BackupFilePath RestartService = $false - SQLServer = $Node.ComputerName - SQLInstanceName = $Node.InstanceName + ServerName = $Node.ComputerName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SqlInstallCredential - DependsOn = '[File]SQLBackupPath' + DependsOn = '[File]SQLBackupPath' } } } diff --git a/Tests/Integration/MSFT_xSQLServerRSConfig.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 similarity index 94% rename from Tests/Integration/MSFT_xSQLServerRSConfig.Integration.Tests.ps1 rename to Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 index 9f49456c6..67cbb9ecb 100644 --- a/Tests/Integration/MSFT_xSQLServerRSConfig.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlRS.Integration.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceFriendlyName = 'xSQLServerRSConfig' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceFriendlyName = 'SqlRS' $script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" if (-not $env:APPVEYOR -eq $true) @@ -43,8 +43,8 @@ try . $configFile $mockInstanceName = $ConfigurationData.AllNodes.InstanceName - $mockRSSQLServer = $ConfigurationData.AllNodes.RSSQLServer - $mockRSSQLInstanceName = $ConfigurationData.AllNodes.RSSQLInstanceName + $mockDatabaseServerName = $ConfigurationData.AllNodes.DatabaseServerName + $mockDatabaseInstanceName = $ConfigurationData.AllNodes.DatabaseInstanceName Describe "$($script:DSCResourceName)_Integration" { BeforeAll { @@ -94,8 +94,8 @@ try } $resourceCurrentState.InstanceName | Should -Be $mockInstanceName - $resourceCurrentState.RSSQLServer | Should -Be $mockRSSQLServer - $resourceCurrentState.RSSQLInstanceName | Should -Be $mockRSSQLInstanceName + $resourceCurrentState.DatabaseServerName | Should -Be $mockDatabaseServerName + $resourceCurrentState.DatabaseInstanceName | Should -Be $mockDatabaseInstanceName $resourceCurrentState.IsInitialized | Should -Be $true } diff --git a/Tests/Integration/MSFT_xSQLServerRSConfig.config.ps1 b/Tests/Integration/MSFT_SqlRS.config.ps1 similarity index 88% rename from Tests/Integration/MSFT_xSQLServerRSConfig.config.ps1 rename to Tests/Integration/MSFT_SqlRS.config.ps1 index 7b65b390c..f94963670 100644 --- a/Tests/Integration/MSFT_xSQLServerRSConfig.config.ps1 +++ b/Tests/Integration/MSFT_SqlRS.config.ps1 @@ -22,15 +22,15 @@ $ConfigurationData = @{ ImagePath = "$env:TEMP\SQL2016.iso" DriveLetter = $mockIsoMediaDriveLetter - RSSQLServer = $env:COMPUTERNAME - RSSQLInstanceName = 'DSCSQL2016' + DatabaseServerName = $env:COMPUTERNAME + DatabaseInstanceName = 'DSCSQL2016' PSDscAllowPlainTextPassword = $true } ) } -Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config +Configuration MSFT_SqlRS_InstallReportingServices_Config { param ( @@ -52,7 +52,7 @@ Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config Import-DscResource -ModuleName 'PSDscResources' Import-DscResource -ModuleName 'xStorage' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { xMountImage 'MountIsoMedia' @@ -82,7 +82,7 @@ Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config Ensure = 'Present' } - xSQLServerSetup 'InstallReportingServicesInstance' + SqlSetup 'InstallReportingServicesInstance' { InstanceName = $Node.InstanceName Features = $Node.Features @@ -109,7 +109,7 @@ Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config PsDscRunAsCredential = $SqlInstallCredential } - xSQLServerRSConfig 'Integration_Test' + SqlRS 'Integration_Test' { # Instance name for the Reporting Services. InstanceName = $Node.InstanceName @@ -118,13 +118,13 @@ Configuration MSFT_xSQLServerRSConfig_InstallReportingServices_Config Instance for Reporting Services databases. Note: This instance is created in a prior integration test. #> - RSSQLServer = $Node.RSSQLServer - RSSQLInstanceName = $Node.RSSQLInstanceName + DatabaseServerName = $Node.DatabaseServerName + DatabaseInstanceName = $Node.DatabaseInstanceName PsDscRunAsCredential = $SqlInstallCredential DependsOn = @( - '[xSQLServerSetup]InstallReportingServicesInstance' + '[SqlSetup]InstallReportingServicesInstance' ) } } diff --git a/Tests/Integration/MSFT_xSQLServerSetup.Integration.Tests.ps1 b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 similarity index 99% rename from Tests/Integration/MSFT_xSQLServerSetup.Integration.Tests.ps1 rename to Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 index d3d11d27c..7a86c282d 100644 --- a/Tests/Integration/MSFT_xSQLServerSetup.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceFriendlyName = 'xSQLServerSetup' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceFriendlyName = 'SqlSetup' $script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" if (-not $env:APPVEYOR -eq $true) diff --git a/Tests/Integration/MSFT_xSQLServerSetup.config.ps1 b/Tests/Integration/MSFT_SqlSetup.config.ps1 similarity index 95% rename from Tests/Integration/MSFT_xSQLServerSetup.config.ps1 rename to Tests/Integration/MSFT_SqlSetup.config.ps1 index 2279a8d89..8843f48aa 100644 --- a/Tests/Integration/MSFT_xSQLServerSetup.config.ps1 +++ b/Tests/Integration/MSFT_SqlSetup.config.ps1 @@ -28,7 +28,7 @@ $ConfigurationData = @{ ) } -Configuration MSFT_xSQLServerSetup_InstallSqlEngineAsSystem_Config +Configuration MSFT_SqlSetup_InstallSqlEngineAsSystem_Config { param ( @@ -55,7 +55,7 @@ Configuration MSFT_xSQLServerSetup_InstallSqlEngineAsSystem_Config Import-DscResource -ModuleName 'PSDscResources' Import-DscResource -ModuleName 'xStorage' - Import-DscResource -ModuleName 'xSQLServer' + Import-DscResource -ModuleName 'SqlServerDsc' node localhost { xMountImage 'MountIsoMedia' @@ -113,7 +113,7 @@ Configuration MSFT_xSQLServerSetup_InstallSqlEngineAsSystem_Config Ensure = 'Present' } - xSQLServerSetup 'Integration_Test' + SqlSetup 'Integration_Test' { InstanceName = $Node.InstanceName Features = $Node.Features @@ -134,7 +134,7 @@ Configuration MSFT_xSQLServerSetup_InstallSqlEngineAsSystem_Config $SqlAdministratorCredential.UserName <# Must have permission to properties IsClustered and - IsHadrEnable for xSQLServerAlwaysOnService. + IsHadrEnable for SqlAlwaysOnService. #> $SqlInstallCredential.UserName ) diff --git a/Tests/xSQLServerCommon.Tests.ps1 b/Tests/SqlServerDscCommon.Tests.ps1 similarity index 74% rename from Tests/xSQLServerCommon.Tests.ps1 rename to Tests/SqlServerDscCommon.Tests.ps1 index 618dcd463..625006361 100644 --- a/Tests/xSQLServerCommon.Tests.ps1 +++ b/Tests/SqlServerDscCommon.Tests.ps1 @@ -5,7 +5,7 @@ param() $script:moduleRoot = Split-Path $PSScriptRoot -Parent -Describe 'xSQLServer module common tests' { +Describe 'SqlServerDsc module common tests' { Context -Name 'When there are example file for resource' { <# For Appveyor builds copy the module to the system modules directory so it falls @@ -13,7 +13,7 @@ Describe 'xSQLServer module common tests' { #> if ($env:APPVEYOR) { - $powershellModulePath = Join-Path -Path (($env:PSModulePath -split ';')[0]) -ChildPath 'xSQLServer' + $powershellModulePath = Join-Path -Path (($env:PSModulePath -split ';')[0]) -ChildPath 'SqlServerDsc' Copy-item -Path $env:APPVEYOR_BUILD_FOLDER -Destination $powershellModulePath -Recurse -Force } @@ -69,7 +69,32 @@ Describe 'xSQLServer module common tests' { Remove-item -Path $powershellModulePath -Recurse -Force -Confirm:$false # Restore the module in 'memory' to ensure other tests after this test have access to it - Import-Module -Name "$script:moduleRoot\xSQLServer.psd1" -Global -Force + Import-Module -Name "$script:moduleRoot\SqlServerDsc.psd1" -Global -Force + } + } + + Context -Name 'When the resource should be used to compile a configuration in Azure Automation' { + $fullPathHardLimit = 129 # 129 characters is the current maxmium for a relative path to be able to compile configurations in Azure Automation. + $allModuleFiles = Get-ChildItem -Path $script:moduleRoot -Recurse + + $testCaseModuleFile = @() + $allModuleFiles | ForEach-Object -Process { + $testCaseModuleFile += @( + @{ + FullRelativePath = $_.FullName -replace ($script:moduleRoot -replace '\\','\\') + } + ) + } + + It 'The length of the full path '''' should not exceed the max hard limit' -TestCases $testCaseModuleFile { + param + ( + [Parameter()] + [System.String] + $FullRelativePath + ) + + $FullRelativePath.Length | Should -Not -BeGreaterThan $fullPathHardLimit } } } diff --git a/Tests/TestHelpers/CommonTestHelper.psm1 b/Tests/TestHelpers/CommonTestHelper.psm1 index 9a23339c0..964edf35c 100644 --- a/Tests/TestHelpers/CommonTestHelper.psm1 +++ b/Tests/TestHelpers/CommonTestHelper.psm1 @@ -6,7 +6,7 @@ The major version of the SQL instance. .PARAMETER ModuleName - The name of the module to load the stubs for. Default is 'SQLServer'. + The name of the module to load the stubs for. Default is 'SqlServer'. #> function Import-SQLModuleStub { @@ -18,15 +18,15 @@ function Import-SQLModuleStub $SQLVersion, [Parameter(ParameterSetName = 'Module')] - [ValidateSet('SQLPS','SQLServer')] + [ValidateSet('SQLPS','SqlServer')] [System.String] - $ModuleName = 'SQLServer' + $ModuleName = 'SqlServer' ) # Translate the module names to their appropriate stub name $modulesAndStubs = @{ SQLPS = 'SQLPSStub' - SQLServer = 'SQLServerStub' + SqlServer = 'SqlServerStub' } # Determine which module to ensure is loaded based on the parameters passed @@ -38,7 +38,7 @@ function Import-SQLModuleStub } elseif ( $SQLVersion -ge 13 ) { - $ModuleName = 'SQLServer' + $ModuleName = 'SqlServer' } } @@ -46,7 +46,9 @@ function Import-SQLModuleStub $stubModuleName = $modulesAndStubs.$ModuleName # Ensure none of the other stub modules are loaded - [System.Array] $otherStubModules = $modulesAndStubs.Values | Where-Object -FilterScript { $_ -ne $stubModuleName } + [System.Array] $otherStubModules = $modulesAndStubs.Values | Where-Object -FilterScript { + $_ -ne $stubModuleName + } if ( Get-Module -Name $otherStubModules ) { diff --git a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroup.Tests.ps1 b/Tests/Unit/MSFT_SqlAG.Tests.ps1 similarity index 88% rename from Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroup.Tests.ps1 rename to Tests/Unit/MSFT_SqlAG.Tests.ps1 index 0a0409bca..67d0c09bb 100644 --- a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAG.Tests.ps1 @@ -12,8 +12,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'CommonTestHelper.psm1'))) -Force -Global $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xSQLServer' ` - -DSCResourceName 'MSFT_xSQLServerAlwaysOnAvailabilityGroup' ` + -DSCModuleName 'SqlServerDsc' ` + -DSCResourceName 'MSFT_SqlAG' ` -TestType Unit #endregion HEADER @@ -35,7 +35,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_xSQLServerAlwaysOnAvailabilityGroup' { + InModuleScope 'MSFT_SqlAG' { #region parameter mocks @@ -48,7 +48,7 @@ try RemoveAvailabilityGroupFailed = 'AvailabilityGroup3' } - # Define the values that could be passed into the SQLServer parameter + # Define the values that could be passed into the ServerName parameter $mockSqlServerParameters = @{ Server1 = @{ FQDN = 'Server1.contoso.com' @@ -63,7 +63,7 @@ try } } - # Define the values that could be passed into the SQLInstanceName parameter + # Define the values that could be passed into the InstanceName parameter $mockSqlInstanceNameParameters = @( 'MSSQLSERVER', 'NamedInstance' @@ -166,7 +166,7 @@ try ( Get-Command -Name Test-TargetResource ).Parameters.Values | Where-Object -FilterScript { ( # Ignore these specific parameters. These get tested enough. - @('Ensure', 'Name', 'SQLServer', 'SQLInstanceName', 'DtcSupportEnabled', 'ProcessOnlyOnActiveNode') -notcontains $_.Name + @('Ensure', 'Name', 'ServerName', 'InstanceName', 'DtcSupportEnabled', 'ProcessOnlyOnActiveNode') -notcontains $_.Name ) -and ( # Ignore the CmdletBinding parameters $_.Attributes.TypeId.Name -notcontains 'AliasAttribute' @@ -212,15 +212,15 @@ try { $getTargetResourceAbsentTestCases += @{ Name = $mockNameParameters.AbsentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } $getTargetResourcePresentTestCases += @{ Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -230,8 +230,8 @@ try ErrorResult = $createAvailabilityGroupFailureToTest.Value Ensure = 'Present' Name = $createAvailabilityGroupFailureToTest.Key - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -240,8 +240,8 @@ try Ensure = 'Present' Name = $mockNameParameters.AbsentAvailabilityGroup Result = 'DatabaseMirroringEndpointNotFound' - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -249,16 +249,16 @@ try Ensure = 'Present' Name = $mockNameParameters.AbsentAvailabilityGroup Result = 'HadrNotEnabled' - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } $setTargetResourceRemoveAvailabilityGroupTestCases += @{ Ensure = 'Absent' Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -282,8 +282,8 @@ try ErrorResult = $setTargetResourceRemoveAvailabilityGroupErrorTestCaseErrorResult Ensure = 'Absent' Name = $setTargetResourceRemoveAvailabilityGroupErrorTestCaseName - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -293,8 +293,8 @@ try Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup ProcessOnlyOnActiveNode = $processOnlyOnActiveNode - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -306,8 +306,8 @@ try Ensure = $ensureCaseToTest Name = $mockNameParameters.AbsentAvailabilityGroup Result = ( $ensureCaseToTest -eq 'Absent' ) - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -315,8 +315,8 @@ try Ensure = $ensureCaseToTest Name = $mockNameParameters.PresentAvailabilityGroup Result = ( $ensureCaseToTest -eq 'Present' ) - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -379,8 +379,8 @@ try Name = $mockNameParameters.AbsentAvailabilityGroup ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -391,8 +391,8 @@ try ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -402,8 +402,8 @@ try ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -430,8 +430,8 @@ try EndpointPropertyValue = $endpointPropertyValue Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } @@ -441,8 +441,8 @@ try Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockSqlServerParameter + InstanceName = $mockSqlInstanceNameParameter Version = $majorVersionToTest } } @@ -681,19 +681,19 @@ try #endregion cmdlet mocks - Describe 'xSQLServerAlwaysOnAvailabilityGroup\Get-TargetResource' -Tag 'Get' { + Describe 'SqlAG\Get-TargetResource' -Tag 'Get' { BeforeAll { Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable } Context 'When the Availability Group is Absent' { - It 'Should not return an Availability Group when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $getTargetResourceAbsentTestCases { + It 'Should not return an Availability Group when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $getTargetResourceAbsentTestCases { param ( $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -702,8 +702,8 @@ try $getTargetResourceParameters = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } $result = Get-TargetResource @getTargetResourceParameters @@ -715,12 +715,12 @@ try } Context 'When the Availability Group is Present' { - It 'Should return the correct Availability Group properties when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $getTargetResourcePresentTestCases { + It 'Should return the correct Availability Group properties when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $getTargetResourcePresentTestCases { param ( $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -729,18 +729,18 @@ try $getTargetResourceParameters = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } # Determine which SQL Server mock data will be used - $mockSqlServer = ( $mockSqlServerParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $SQLServer } ).Name + $mockSqlServer = ( $mockSqlServerParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $ServerName } ).Name $result = Get-TargetResource @getTargetResourceParameters $result.Name | Should -Be $Name - $result.SQLServer | Should -Be $SQLServer - $result.SQLInstanceName | Should -Be $SQLInstanceName + $result.ServerName | Should -Be $ServerName + $result.InstanceName | Should -Be $InstanceName $result.Ensure | Should -Be 'Present' $result.AutomatedBackupPreference | Should -Be $mockAvailabilityGroupProperties.AutomatedBackupPreference $result.AvailabilityMode | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.AvailabilityMode @@ -770,7 +770,7 @@ try } } - Describe 'xSQLServerAlwaysOnAvailabilityGroup\Set-TargetResource' -Tag 'Set' { + Describe 'SqlAG\Set-TargetResource' -Tag 'Set' { BeforeAll { Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable Mock -CommandName Get-PrimaryReplicaServerObject -MockWith $mockConnectSql -Verifiable @@ -794,7 +794,7 @@ try } Context 'When the Availability Group is Absent and the desired state is Present and a parameter is supplied' { - It 'Should create the availability group "" with the parameter "" set to "" when Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupWithParameterTestCases { + It 'Should create the availability group "" with the parameter "" set to "" when Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupWithParameterTestCases { param ( $DomainInstanceName, @@ -802,8 +802,8 @@ try $Name, $ParameterName, $ParameterValue, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -813,8 +813,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -839,14 +839,14 @@ try } Context 'When the Availability Group is Absent, the desired state is Present, and creating the Availability Group fails' { - It 'Should throw "" when creating the availability group "" fails, Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupFailedTestCases { + It 'Should throw "" when creating the availability group "" fails, Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupFailedTestCases { param ( $ErrorResult, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -869,8 +869,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw "$($ErrorResult)" @@ -894,7 +894,7 @@ try } Context 'When the Availability Group is Present and a value is passed to a parameter' { - It 'Should set "" to "" when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcePropertyIncorrectTestCases { + It 'Should set "" to "" when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcePropertyIncorrectTestCases { param ( $Ensure, @@ -902,8 +902,8 @@ try $ParameterName, $ParameterValue, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -913,8 +913,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -951,13 +951,13 @@ try } Context 'When the Availability Group is Present and the desired state is Absent' { - It 'Should remove the Availability Group "" when Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupTestCases { + It 'Should remove the Availability Group "" when Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupTestCases { param ( $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -967,8 +967,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -992,14 +992,14 @@ try } Context 'When the Availability Group is Present and throws an error when removal is attempted' { - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupErrorTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupErrorTestCases { param ( $ErrorResult, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1022,8 +1022,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw "$($ErrorResult)" @@ -1055,14 +1055,14 @@ try $mockIsHadrEnabled = $false } - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceHadrDisabledTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceHadrDisabledTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1072,8 +1072,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw $Result @@ -1105,14 +1105,14 @@ try $mockIsDatabaseMirroringEndpointPresent = $false } - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceEndpointMissingTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceEndpointMissingTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1122,8 +1122,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw $Result @@ -1159,15 +1159,15 @@ try $mockAvailabilityGroupReplicaPropertiesServer2Original = $mockAvailabilityGroupReplicaProperties.Server2.Clone() } - It 'Should set "" to "" when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcesEndpointUrlTestCases { + It 'Should set "" to "" when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcesEndpointUrlTestCases { param ( $EndpointPropertyName, $EndpointPropertyValue, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1180,8 +1180,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -1205,7 +1205,7 @@ try } } - Describe 'xSQLServerAlwaysOnAvailabilityGroup\Test-TargetResource' -Tag 'Test' { + Describe 'SqlAG\Test-TargetResource' -Tag 'Test' { BeforeAll { Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable Mock -CommandName Test-ActiveNode -MockWith { @@ -1214,14 +1214,14 @@ try } Context 'When the Availability Group is Absent' { - It 'Should be "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceAbsentTestCases { + It 'Should be "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceAbsentTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1231,8 +1231,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1243,14 +1243,14 @@ try } Context 'When the Availability Group is Present and the default parameters are passed' { - It 'Should be "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePresentTestCases { + It 'Should be "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePresentTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1260,8 +1260,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1272,7 +1272,7 @@ try } Context 'When the Availability Group is Present and a value is passed to a parameter' { - It 'Should be "" when "" is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePropertyIncorrectTestCases { + It 'Should be "" when "" is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePropertyIncorrectTestCases { param ( $Ensure, @@ -1280,8 +1280,8 @@ try $ParameterName, $ParameterValue, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1291,8 +1291,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -1316,7 +1316,7 @@ try $mockAvailabilityGroupReplicaPropertiesServer2Original = $mockAvailabilityGroupReplicaProperties.Server2.Clone() } - It 'Should be "" when "" is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceEndpointIncorrectTestCases { + It 'Should be "" when "" is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceEndpointIncorrectTestCases { param ( $EndpointPropertyName, @@ -1324,8 +1324,8 @@ try $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1338,8 +1338,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1359,14 +1359,14 @@ try $mockProcessOnlyOnActiveNode = $false } - It 'Should be "true" when ProcessOnlyOnActiveNode is "", Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceProcessOnlyOnActiveNodeTestCases { + It 'Should be "true" when ProcessOnlyOnActiveNode is "", Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceProcessOnlyOnActiveNodeTestCases { param ( $Ensure, $Name, $ProcessOnlyOnActiveNode, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1377,8 +1377,8 @@ try Ensure = $Ensure Name = $Name ProcessOnlyOnActiveNode = $ProcessOnlyOnActiveNode - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should Be $true @@ -1389,7 +1389,7 @@ try } } - Describe 'xSQLServerAlwaysOnAvailabilityGroup\Update-AvailabilityGroup' -Tag 'Helper' { + Describe 'SqlAG\Update-AvailabilityGroup' -Tag 'Helper' { BeforeAll { Mock -CommandName New-TerminatingError -MockWith { $ErrorType diff --git a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.Tests.ps1 b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 similarity index 98% rename from Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.Tests.ps1 rename to Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 index 95e108627..599642481 100644 --- a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 @@ -9,15 +9,15 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR } Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath 'xSQLServerHelper.psm1') -Scope Global -Force +Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath 'SqlServerDscHelper.psm1') -Scope Global -Force Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global # Loading mocked classes Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xSQLServer' ` - -DSCResourceName 'MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership' ` + -DSCModuleName 'SqlServerDsc' ` + -DSCResourceName 'MSFT_SqlAGDatabase' ` -TestType Unit #endregion HEADER @@ -37,7 +37,7 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership' { + InModuleScope 'MSFT_SqlAGDatabase' { #region Parameter Mocks @@ -354,7 +354,7 @@ WITH NORECOVERY' #endregion Invoke Query Mock - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Get-TargetResource' { + Describe 'SqlAGDatabase\Get-TargetResource' { BeforeAll { Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable @@ -363,8 +363,8 @@ WITH NORECOVERY' BeforeEach { $getTargetResourceParameters = @{ DatabaseName = $mockDatabaseNameParameter.Clone() - SqlServer = 'Server1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'Server1' + InstanceName = 'MSSQLSERVER' AvailabilityGroupName = 'AvailabilityGroup1' BackupPath = $($mockBackupPath) } @@ -376,8 +376,8 @@ WITH NORECOVERY' $result = Get-TargetResource @getTargetResourceParameters - $result.SqlServer | Should -Be $getTargetResourceParameters.SqlServer - $result.SQLInstanceName | Should -Be $getTargetResourceParameters.SQLInstanceName + $result.ServerName | Should -Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName $result.AvailabilityGroupName | Should -BeNullOrEmpty $result.DatabaseName | Should -BeNullOrEmpty @@ -390,8 +390,8 @@ WITH NORECOVERY' $result = Get-TargetResource @getTargetResourceParameters - $result.SqlServer | Should -Be $getTargetResourceParameters.SqlServer - $result.SQLInstanceName | Should -Be $getTargetResourceParameters.SQLInstanceName + $result.ServerName | Should -Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName $result.AvailabilityGroupName | Should -Be $mockAvailabilityGroupWithoutDatabasesObject.Name $result.DatabaseName | Should -BeNullOrEmpty @@ -402,8 +402,8 @@ WITH NORECOVERY' It 'Should return databases when there are databases in the availability group' { $result = Get-TargetResource @getTargetResourceParameters - $result.SqlServer | Should -Be $getTargetResourceParameters.SqlServer - $result.SQLInstanceName | Should -Be $getTargetResourceParameters.SQLInstanceName + $result.ServerName | Should -Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName $result.AvailabilityGroupName | Should -Be $mockAvailabilityGroupObject.Name foreach ( $resultDatabaseName in $result.DatabaseName ) @@ -422,7 +422,7 @@ WITH NORECOVERY' } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Set-TargetResource' { + Describe 'SqlAGDatabase\Set-TargetResource' { BeforeAll { Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' } @@ -439,8 +439,8 @@ WITH NORECOVERY' BeforeEach { $mockSetTargetResourceParameters = @{ DatabaseName = $($mockDatabaseNameParameter) - SQLServer = $($mockServerObject.DomainInstanceName) - SQLInstanceName = $('MSSQLSERVER') + ServerName = $($mockServerObject.DomainInstanceName) + InstanceName = $('MSSQLSERVER') AvailabilityGroupName = $($mockAvailabilityGroupObjectName) BackupPath = $($mockBackupPath) Ensure = 'Present' @@ -1137,7 +1137,7 @@ WITH NORECOVERY' } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Test-TargetResource' { + Describe 'SqlAGDatabase\Test-TargetResource' { BeforeAll { Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -1150,8 +1150,8 @@ WITH NORECOVERY' BeforeEach { $mockTestTargetResourceParameters = @{ DatabaseName = $mockDatabaseNameParameter.Clone() - SqlServer = $mockServerObject.DomainInstanceName - SQLInstanceName = 'MSSQLSERVER' + ServerName = $mockServerObject.DomainInstanceName + InstanceName = 'MSSQLSERVER' AvailabilityGroupName = $mockAvailabilityGroupObject.Name BackupPath = $($mockBackupPath) Ensure = 'Present' @@ -1331,7 +1331,7 @@ WITH NORECOVERY' } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Get-DatabasesToAddToAvailabilityGroup' { + Describe 'SqlAGDatabase\Get-DatabasesToAddToAvailabilityGroup' { BeforeEach { $getDatabasesToAddToAvailabilityGroup = @{ DatabaseName = $mockDatabaseNameParameter.Clone() @@ -1370,7 +1370,7 @@ WITH NORECOVERY' } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Get-DatabasesToRemoveFromAvailabilityGroup' { + Describe 'SqlAGDatabase\Get-DatabasesToRemoveFromAvailabilityGroup' { BeforeEach { $getDatabasesToRemoveFromAvailabilityGroupParameters = @{ DatabaseName = $mockDatabaseNameParameter.Clone() @@ -1447,7 +1447,7 @@ WITH NORECOVERY' } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Get-MatchingDatabaseNames' { + Describe 'SqlAGDatabase\Get-MatchingDatabaseNames' { BeforeEach { $getMatchingDatabaseNamesParameters = @{ DatabaseName = $mockDatabaseNameParameter.Clone() @@ -1476,10 +1476,21 @@ WITH NORECOVERY' $mockPresentDatabaseNames -contains $result | Should -Be $true } } + + It 'Should return an array of database names that match the defined databases when the case does not match' { + $getMatchingDatabaseNamesParameters.DatabaseName = $getMatchingDatabaseNamesParameters.DatabaseName | ForEach-Object -Process { $_.ToLower() } + + $results = Get-MatchingDatabaseNames @getMatchingDatabaseNamesParameters + + foreach ( $result in $results ) + { + $mockPresentDatabaseNames -contains $result | Should -Be $true + } + } } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership\Get-DatabaseNamesNotFoundOnTheInstance' { + Describe 'SqlAGDatabase\Get-DatabaseNamesNotFoundOnTheInstance' { Context 'When the Get-DatabaseNamesNotFoundOnTheInstance function is called' { BeforeAll { # The defined databases that should be identified as missing diff --git a/Tests/Unit/MSFT_xSQLServerAvailabilityGroupListener.Tests.ps1 b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 similarity index 86% rename from Tests/Unit/MSFT_xSQLServerAvailabilityGroupListener.Tests.ps1 rename to Tests/Unit/MSFT_SqlAGListener.Tests.ps1 index d3ec63a44..0431d8066 100644 --- a/Tests/Unit/MSFT_xSQLServerAvailabilityGroupListener.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerAvailabilityGroupListener' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAGListener' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading stub cmdlets Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -44,7 +46,7 @@ try $mockUnknownPortNumber = 9001 # Static parameter values - $mockNodeName = 'localhost' + $mockServerName = 'localhost' $mockInstanceName = 'MSSQLSERVER' $mockDynamicAvailabilityGroup = $mockKnownAvailabilityGroup $mockDynamicListenerName = $mockKnownListenerName @@ -55,45 +57,45 @@ try $mockConnectSql = { return New-Object Object | Add-Member ScriptProperty AvailabilityGroups { - return @( - @{ - $mockDynamicAvailabilityGroup = New-Object Object | - Add-Member ScriptProperty AvailabilityGroupListeners { - @( - @{ - $mockDynamicListenerName = New-Object Object | - Add-Member NoteProperty PortNumber $mockDynamicPortNumber -PassThru | - Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress - Add-Member NoteProperty IsDHCP $mockDynamicIsDhcp -PassThru | - Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | - Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) - ) - } -PassThru | - Add-Member ScriptMethod Drop { - $script:mockMethodDropRan = $true - } -PassThru -Force - } - ) - } -PassThru -Force - } - ) - } -PassThru -Force + return @( + @{ + $mockDynamicAvailabilityGroup = New-Object Object | + Add-Member ScriptProperty AvailabilityGroupListeners { + @( + @{ + $mockDynamicListenerName = New-Object Object | + Add-Member NoteProperty PortNumber $mockDynamicPortNumber -PassThru | + Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + Add-Member NoteProperty IsDHCP $mockDynamicIsDhcp -PassThru | + Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | + Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru + ) + ) + } -PassThru | + Add-Member ScriptMethod Drop { + $script:mockMethodDropRan = $true + } -PassThru -Force + } + ) + } -PassThru -Force + } + ) + } -PassThru -Force } $defaultParameters = @{ - InstanceName = $mockInstanceName - NodeName = $mockNodeName - Name = $mockKnownListenerName + InstanceName = $mockInstanceName + ServerName = $mockServerName + Name = $mockKnownListenerName AvailabilityGroup = $mockKnownAvailabilityGroup } #endregion Pester Test Initialization - Describe 'xSQLServerAvailabilityGroupListener\Get-TargetResource' { + Describe 'SqlAGListener\Get-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -111,7 +113,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.AvailabilityGroup | Should -Be $testParameters.AvailabilityGroup @@ -146,7 +148,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.AvailabilityGroup | Should -Be $testParameters.AvailabilityGroup @@ -183,7 +185,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.AvailabilityGroup | Should -Be $testParameters.AvailabilityGroup @@ -224,7 +226,7 @@ try Assert-VerifiableMock } - Describe 'xSQLServerAvailabilityGroupListener\Test-TargetResource' { + Describe 'SqlAGListener\Test-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() } @@ -249,15 +251,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5030 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $false -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is absent when wanted desired state is to be Absent' { @@ -307,15 +309,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5555 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $false -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is absent when port is different' { @@ -337,15 +339,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5030 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $true -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is absent when DHCP is present but should be absent' { @@ -374,15 +376,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5555 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $true -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is absent when port is the only set parameter' { @@ -415,15 +417,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5030 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $false -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is present when wanted desired state is to be Present, without DHCP' { @@ -463,15 +465,15 @@ try return New-Object Object | Add-Member NoteProperty PortNumber 5030 -PassThru | Add-Member ScriptProperty AvailabilityGroupListenerIPAddresses { - return @( - # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection - (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress + return @( + # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddressCollection + (New-Object Object | # TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupListenerIPAddress Add-Member NoteProperty IsDHCP $true -PassThru | Add-Member NoteProperty IPAddress '192.168.0.1' -PassThru | Add-Member NoteProperty SubnetMask '255.255.255.0' -PassThru - ) ) - } -PassThru -Force + ) + } -PassThru -Force } -Verifiable It 'Should return that desired state is present when wanted desired state is to be Present, with DHCP' { @@ -509,7 +511,7 @@ try Assert-VerifiableMock } - Describe 'xSQLServerAvailabilityGroupListener\Set-TargetResource' { + Describe 'SqlAGListener\Set-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -606,7 +608,7 @@ try $mockDynamicPortNumber = $mockKnownPortNumber It 'Should call the cmdlet Add-SqlAvailabilityGroupListenerStaticIp, when adding another IP address, and system is not in desired state' { - $testParameters['IpAddress'] = @('192.168.0.1/255.255.255.0','10.0.0.1/255.255.252.0') + $testParameters['IpAddress'] = @('192.168.0.1/255.255.255.0', '10.0.0.1/255.255.252.0') $testParameters['Port'] = 5030 $testParameters['DHCP'] = $false @@ -698,12 +700,12 @@ try Mock -CommandName Get-TargetResource -MockWith { return @{ - Ensure = 'Present' - Name = $mockUnknownListenerName + Ensure = 'Present' + Name = $mockUnknownListenerName AvailabilityGroup = $mockKnownAvailabilityGroup - IpAddress = '192.168.0.1/255.255.255.0' - Port = $mockKnownPortNumber - DHCP = $false + IpAddress = '192.168.0.1/255.255.255.0' + Port = $mockKnownPortNumber + DHCP = $false } } @@ -721,12 +723,12 @@ try Mock -CommandName Get-TargetResource -MockWith { return @{ - Ensure = 'Present' - Name = $mockUnknownListenerName + Ensure = 'Present' + Name = $mockUnknownListenerName AvailabilityGroup = $mockUnknownAvailabilityGroup - IpAddress = '192.168.0.1/255.255.255.0' - Port = $mockKnownPortNumber - DHCP = $false + IpAddress = '192.168.0.1/255.255.255.0' + Port = $mockKnownPortNumber + DHCP = $false } } diff --git a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.Tests.ps1 b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 similarity index 96% rename from Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.Tests.ps1 rename to Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 index 24a24b8a4..d94ba1a20 100644 --- a/Tests/Unit/MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 @@ -13,8 +13,8 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xSQLServer' ` - -DSCResourceName 'MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica' ` + -DSCModuleName 'SqlServerDsc' ` + -DSCResourceName 'MSFT_SqlAGReplica' ` -TestType Unit #endregion HEADER @@ -33,25 +33,25 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_xSQLServerAlwaysOnAvailabilityGroupReplica' { + InModuleScope 'MSFT_SqlAGReplica' { #region parameter mocks - $mockSqlServer = 'Server1' - $mockSqlInstanceName = 'MSSQLSERVER' - $mockPrimaryReplicaSQLServer = 'Server2' - $mockPrimaryReplicaSQLInstanceName = 'MSSQLSERVER' + $mockServerName = 'Server1' + $mockInstanceName = 'MSSQLSERVER' + $mockPrimaryReplicaServerName = 'Server2' + $mockPrimaryReplicaInstanceName = 'MSSQLSERVER' $mockAvailabilityGroupName = 'AG_AllServers' - $mockAvailabilityGroupReplicaName = $mockSqlServer + $mockAvailabilityGroupReplicaName = $mockServerName $mockEnsure = 'Present' $mockAvailabilityMode = 'AsynchronousCommit' $mockBackupPriority = 50 $mockConnectionModeInPrimaryRole = 'AllowAllConnections' $mockConnectionModeInSecondaryRole = 'AllowNoConnections' - $mockEndpointHostName = $mockSqlServer + $mockEndpointHostName = $mockServerName $mockFailoverMode = 'Manual' - $mockReadOnlyRoutingConnectionUrl = "TCP://$($mockSqlServer).domain.com:1433" - $mockReadOnlyRoutingList = @($mockSqlServer) + $mockReadOnlyRoutingConnectionUrl = "TCP://$($mockServerName).domain.com:1433" + $mockReadOnlyRoutingList = @($mockServerName) $mockProcessOnlyOnActiveNode = $false #endregion @@ -85,16 +85,16 @@ try $mockAllLoginsAbsent = @{} $mockNtServiceClusSvcPresent = @{ - $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtServiceClusSvcName) ) + $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtServiceClusSvcName) ) } $mockNtAuthoritySystemPresent = @{ - $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtAuthoritySystemName) ) + $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtAuthoritySystemName) ) } $mockAllLoginsPresent = @{ - $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtServiceClusSvcName) ) - $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtAuthoritySystemName) ) + $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtServiceClusSvcName) ) + $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtAuthoritySystemName) ) } #endregion @@ -530,13 +530,13 @@ try #endregion - Describe 'xSQLServerAlwaysOnAvailabilityGroupReplica\Get-TargetResource' { + Describe 'SqlAGReplica\Get-TargetResource' { BeforeEach { $getTargetResourceParameters = @{ Name = $mockAvailabilityGroupReplicaName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName } $mockDatabaseMirroringEndpoint = $true @@ -565,9 +565,9 @@ try $getTargetResourceResult.Name | Should -BeNullOrEmpty $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -BeNullOrEmpty $getTargetResourceResult.ReadOnlyRoutingList | Should -BeNullOrEmpty - $getTargetResourceResult.SQLServer | Should -Be $mockSqlServer - $getTargetResourceResult.SQLInstanceName | Should -Be $mockSqlInstanceName - $getTargetResourceResult.SQLServerNetName | Should -Be $mockSqlServer + $getTargetResourceResult.ServerName | Should -Be $mockServerName + $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName + $getTargetResourceResult.EndpointHostName | Should -Be $mockServerName Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly } @@ -590,19 +590,19 @@ try $getTargetResourceResult.EndpointPort | Should -Be $mockendpointPort $getTargetResourceResult.Ensure | Should -Be $mockEnsure $getTargetResourceResult.FailoverMode | Should -Be $mockFailoverMode - $getTargetResourceResult.Name | Should -Be $mockSqlServer + $getTargetResourceResult.Name | Should -Be $mockServerName $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -Be $mockReadOnlyRoutingConnectionUrl - $getTargetResourceResult.ReadOnlyRoutingList | Should -Be $mockSqlServer - $getTargetResourceResult.SQLServer | Should -Be $mockSqlServer - $getTargetResourceResult.SQLInstanceName | Should -Be $mockSqlInstanceName - $getTargetResourceResult.SQLServerNetName | Should -Be $mockSqlServer + $getTargetResourceResult.ReadOnlyRoutingList | Should -Be $mockServerName + $getTargetResourceResult.ServerName | Should -Be $mockServerName + $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName + $getTargetResourceResult.EndpointHostName | Should -Be $mockServerName Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly } } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupReplica\Set-TargetResource' { + Describe 'SqlAGReplica\Set-TargetResource' { BeforeAll { Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable @@ -649,10 +649,10 @@ try BeforeEach { $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName Ensure = 'Absent' } } @@ -733,12 +733,12 @@ try BeforeEach { $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroup2Name - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName - PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer - PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName + PrimaryReplicaServerName = $mockPrimaryReplicaServerName + PrimaryReplicaInstanceName = $mockPrimaryReplicaInstanceName Ensure = $mockEnsure AvailabilityMode = $mockAvailabilityMode BackupPriority = $mockBackupPriority @@ -918,7 +918,7 @@ try It 'Should create the availability group replica when primary replica server is incorrectly supplied and the availability group exists' { - $setTargetResourceParameters.PrimaryReplicaSQLServer = $mockServer3Name + $setTargetResourceParameters.PrimaryReplicaServerName = $mockServer3Name { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -1072,12 +1072,12 @@ try $mockAlternateEndpointProtocol = $false $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName - PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer - PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName + PrimaryReplicaServerName = $mockPrimaryReplicaServerName + PrimaryReplicaInstanceName = $mockPrimaryReplicaInstanceName Ensure = $mockEnsure AvailabilityMode = $mockAvailabilityMode BackupPriority = $mockBackupPriority @@ -1266,7 +1266,7 @@ try } } - Describe 'xSQLServerAlwaysOnAvailabilityGroupReplica\Test-TargetResource' { + Describe 'SqlAGReplica\Test-TargetResource' { BeforeEach { $mockAlternateEndpointPort = $false @@ -1274,12 +1274,12 @@ try $mockDatabaseMirroringEndpoint = $true $testTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName - PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer - PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName + PrimaryReplicaServerName = $mockPrimaryReplicaServerName + PrimaryReplicaInstanceName = $mockPrimaryReplicaInstanceName Ensure = $mockEnsure AvailabilityMode = $mockAvailabilityMode BackupPriority = $mockBackupPriority diff --git a/Tests/Unit/MSFT_xSQLServerAlias.Tests.ps1 b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 similarity index 99% rename from Tests/Unit/MSFT_xSQLServerAlias.Tests.ps1 rename to Tests/Unit/MSFT_SqlAlias.Tests.ps1 index ff796b22c..8ff0a6fc8 100644 --- a/Tests/Unit/MSFT_xSQLServerAlias.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerAlias' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAlias' #region HEADER diff --git a/Tests/Unit/MSFT_xSQLServerAlwaysOnService.Tests.ps1 b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 similarity index 93% rename from Tests/Unit/MSFT_xSQLServerAlwaysOnService.Tests.ps1 rename to Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 index 59547d7b0..4bf7eca6a 100644 --- a/Tests/Unit/MSFT_xSQLServerAlwaysOnService.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 @@ -1,12 +1,12 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerAlwaysOnService' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlAlwaysOnService' # Unit Test Template Version: 1.1.0 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -16,27 +16,27 @@ $TestEnvironment = Initialize-TestEnvironment ` -TestType Unit $disableHadr = @{ - Ensure = 'Absent' - SQLServer = 'Server01' - SQLInstanceName = 'MSSQLSERVER' + Ensure = 'Absent' + ServerName = 'Server01' + InstanceName = 'MSSQLSERVER' } $enableHadr = @{ - Ensure = 'Present' - SQLServer = 'Server01' - SQLInstanceName = 'MSSQLSERVER' + Ensure = 'Present' + ServerName = 'Server01' + InstanceName = 'MSSQLSERVER' } $disableHadrNamedInstance = @{ - Ensure = 'Absent' - SQLServer = 'Server01' - SQLInstanceName = 'NamedInstance' + Ensure = 'Absent' + ServerName = 'Server01' + InstanceName = 'NamedInstance' } $enableHadrNamedInstance = @{ - Ensure = 'Present' - SQLServer = 'Server01' - SQLInstanceName = 'NamedInstance' + Ensure = 'Present' + ServerName = 'Server01' + InstanceName = 'NamedInstance' } # Begin Testing @@ -139,7 +139,7 @@ try It 'Should disable SQL Always On when Ensure is set to Absent' { Mock -CommandName Connect-SQL -MockWith { - return New-Object PSObject -Property @{ + return New-Object PSObject -Property @{ IsHadrEnabled = $false } } -ModuleName $script:DSCResourceName -Verifiable diff --git a/Tests/Unit/MSFT_xSQLServerDatabase.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 similarity index 69% rename from Tests/Unit/MSFT_xSQLServerDatabase.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabase.Tests.ps1 index 5a1ae80ed..546322030 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabase.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabase.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerDatabase' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabase' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,11 +20,13 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading mocked classes } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -34,20 +36,20 @@ try Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlDatabaseName = 'AdventureWorks' + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlDatabaseName = 'AdventureWorks' $mockInvalidOperationForCreateMethod = $false - $mockInvalidOperationForDropMethod = $false - $mockInvalidOperationForAlterMethod = $false - $mockExpectedDatabaseNameToCreate = 'Contoso' - $mockExpectedDatabaseNameToDrop = 'Sales' - $mockSqlDatabaseCollation = 'SQL_Latin1_General_CP1_CI_AS' + $mockInvalidOperationForDropMethod = $false + $mockInvalidOperationForAlterMethod = $false + $mockExpectedDatabaseNameToCreate = 'Contoso' + $mockExpectedDatabaseNameToDrop = 'Sales' + $mockSqlDatabaseCollation = 'SQL_Latin1_General_CP1_CI_AS' # Default parameters that are used for the It-blocks $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName + InstanceName = $mockInstanceName + ServerName = $mockServerName } #region Function mocks @@ -56,48 +58,48 @@ try return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | Add-Member -MemberType NoteProperty -Name Collation -Value $mockSqlDatabaseCollation -PassThru | Add-Member -MemberType ScriptMethod -Name EnumCollations -Value { - return @( - ( New-Object Object | + return @( + ( New-Object Object | Add-Member -MemberType NoteProperty Name -Value $mockSqlDatabaseCollation -PassThru - ), - ( New-Object Object | + ), + ( New-Object Object | Add-Member -MemberType NoteProperty Name -Value 'SQL_Latin1_General_CP1_CS_AS' -PassThru - ), - ( New-Object Object | + ), + ( New-Object Object | Add-Member -MemberType NoteProperty Name -Value 'SQL_Latin1_General_Pref_CP850_CI_AS' -PassThru - ) ) - } -PassThru -Force | + ) + } -PassThru -Force | Add-Member -MemberType ScriptProperty -Name Databases -Value { - return @{ - $mockSqlDatabaseName = ( New-Object Object | + return @{ + $mockSqlDatabaseName = ( New-Object Object | Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | Add-Member -MemberType NoteProperty -Name Collation -Value $mockSqlDatabaseCollation -PassThru | Add-Member -MemberType ScriptMethod -Name Drop -Value { - if ($mockInvalidOperationForDropMethod) - { - throw 'Mock Drop Method was called with invalid operation.' - } - - if ( $this.Name -ne $mockExpectedDatabaseNameToDrop ) - { - throw "Called mocked Drop() method without dropping the right database. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedDatabaseNameToDrop, $this.Name - } - } -PassThru | + if ($mockInvalidOperationForDropMethod) + { + throw 'Mock Drop Method was called with invalid operation.' + } + + if ( $this.Name -ne $mockExpectedDatabaseNameToDrop ) + { + throw "Called mocked Drop() method without dropping the right database. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedDatabaseNameToDrop, $this.Name + } + } -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value { - if ($mockInvalidOperationForAlterMethod) - { - throw 'Mock Alter Method was called with invalid operation.' - } - } -PassThru - ) - } - } -PassThru -Force + if ($mockInvalidOperationForAlterMethod) + { + throw 'Mock Alter Method was called with invalid operation.' + } + } -PassThru + ) + } + } -PassThru -Force ) ) } @@ -109,23 +111,23 @@ try Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | Add-Member -MemberType NoteProperty -Name Collation -Value '' -PassThru | Add-Member -MemberType ScriptMethod -Name Create -Value { - if ($mockInvalidOperationForCreateMethod) - { - throw 'Mock Create Method was called with invalid operation.' - } - - if ( $this.Name -ne $mockExpectedDatabaseNameToCreate ) - { - throw "Called mocked Create() method without adding the right database. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedDatabaseNameToCreate, $this.Name - } - } -PassThru -Force + if ($mockInvalidOperationForCreateMethod) + { + throw 'Mock Create Method was called with invalid operation.' + } + + if ( $this.Name -ne $mockExpectedDatabaseNameToCreate ) + { + throw "Called mocked Create() method without adding the right database. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedDatabaseNameToCreate, $this.Name + } + } -PassThru -Force ) ) } #endregion - Describe "MSFT_xSQLServerDatabase\Get-TargetResource" -Tag 'Get'{ + Describe "MSFT_SqlDatabase\Get-TargetResource" -Tag 'Get' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -133,7 +135,7 @@ try Context 'When the system is not in the desired state' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'UnknownDatabase' + Name = 'UnknownDatabase' Collation = 'SQL_Latin1_General_CP1_CI_AS' } @@ -144,8 +146,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.Collation | Should -Be $testParameters.Collation } @@ -160,7 +162,7 @@ try $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' Collation = 'SQL_Latin1_General_CP1_CI_AS' } @@ -171,8 +173,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.Collation | Should -Be $testParameters.Collation } @@ -185,7 +187,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabase\Test-TargetResource" -Tag 'Test'{ + Describe "MSFT_SqlDatabase\Test-TargetResource" -Tag 'Test' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -194,8 +196,8 @@ try It 'Should return the state as false when desired database does not exist' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'UnknownDatabase' - Ensure = 'Present' + Name = 'UnknownDatabase' + Ensure = 'Present' Collation = 'SQL_Latin1_General_CP1_CS_AS' } @@ -206,8 +208,8 @@ try It 'Should return the state as false when desired database exists but has the incorrect collation' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' - Ensure = 'Present' + Name = 'AdventureWorks' + Ensure = 'Present' Collation = 'SQL_Latin1_General_CP1_CS_AS' } @@ -224,8 +226,8 @@ try It 'Should return the state as false when non-desired database exist' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' - Ensure = 'Absent' + Name = 'AdventureWorks' + Ensure = 'Absent' } $result = Test-TargetResource @testParameters @@ -241,8 +243,8 @@ try It 'Should return the state as true when desired database exist' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' - Ensure = 'Present' + Name = 'AdventureWorks' + Ensure = 'Present' Collation = 'SQL_Latin1_General_CP1_CI_AS' } @@ -253,8 +255,8 @@ try It 'Should return the state as true when desired database exists and has the correct collation' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' - Ensure = 'Present' + Name = 'AdventureWorks' + Ensure = 'Present' Collation = 'SQL_Latin1_General_CP1_CI_AS' } @@ -271,8 +273,8 @@ try It 'Should return the state as true when desired database does not exist' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'UnknownDatabase' - Ensure = 'Absent' + Name = 'UnknownDatabase' + Ensure = 'Absent' } $result = Test-TargetResource @testParameters @@ -287,7 +289,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabase\Set-TargetResource" -Tag 'Set'{ + Describe "MSFT_SqlDatabase\Set-TargetResource" -Tag 'Set' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName New-Object -MockWith $mockNewObjectDatabase -ParameterFilter { @@ -295,15 +297,15 @@ try } -Verifiable } - $mockSqlDatabaseName = 'Contoso' - $mockExpectedDatabaseNameToCreate = 'Contoso' + $mockSqlDatabaseName = 'Contoso' + $mockExpectedDatabaseNameToCreate = 'Contoso' Context 'When the system is not in the desired state and Ensure is set to Present' { It 'Should not throw when creating the database' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'NewDatabase' - Ensure = 'Present' + Name = 'NewDatabase' + Ensure = 'Present' } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -312,8 +314,8 @@ try It 'Should not throw when changing the database collation' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'Contoso' - Ensure = 'Present' + Name = 'Contoso' + Ensure = 'Present' Collation = 'SQL_Latin1_General_CP1_CS_AS' } @@ -332,14 +334,14 @@ try } $mockExpectedDatabaseNameToDrop = 'Sales' - $mockSqlDatabaseName = 'Sales' + $mockSqlDatabaseName = 'Sales' Context 'When the system is not in the desired state and Ensure is set to Absent' { It 'Should not throw when dropping the database' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'Sales' - Ensure = 'Absent' + Name = 'Sales' + Ensure = 'Absent' } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -351,18 +353,18 @@ try } $mockInvalidOperationForCreateMethod = $true - $mockInvalidOperationForAlterMethod = $true + $mockInvalidOperationForAlterMethod = $true Context 'When the system is not in the desired state and Ensure is set to Present' { It 'Should throw the correct error when Create() method was called with invalid operation' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'NewDatabase' - Ensure = 'Present' + Name = 'NewDatabase' + Ensure = 'Present' } $throwInvalidOperation = ('InnerException: Exception calling "Create" ' + ` - 'with "0" argument(s): "Mock Create Method was called with invalid operation."') + 'with "0" argument(s): "Mock Create Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -370,12 +372,12 @@ try It 'Should throw the correct error when invalid collation is specified' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'Sales' - Ensure = 'Present' + Name = 'Sales' + Ensure = 'Present' Collation = 'InvalidCollation' } - $throwInvalidOperation = ("The specified collation '{3}' is not a valid collation for database {2} on {0}\{1}." -f $mockSqlServerName, $mockSqlServerInstanceName, $testParameters.Name, $testParameters.Collation) + $throwInvalidOperation = ("The specified collation '{3}' is not a valid collation for database {2} on {0}\{1}." -f $mockServerName, $mockInstanceName, $testParameters.Name, $testParameters.Collation) { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -397,14 +399,14 @@ try Context 'When the system is not in the desired state and Ensure is set to Absent' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' - Ensure = 'Absent' + Name = 'AdventureWorks' + Ensure = 'Absent' Collation = 'SQL_Latin1_General_CP1_CS_AS' } It 'Should throw the correct error when Drop() method was called with invalid operation' { $throwInvalidOperation = ('InnerException: Exception calling "Drop" ' + ` - 'with "0" argument(s): "Mock Drop Method was called with invalid operation."') + 'with "0" argument(s): "Mock Drop Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } diff --git a/Tests/Unit/MSFT_xSQLServerDatabaseDefaultLocation.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 similarity index 74% rename from Tests/Unit/MSFT_xSQLServerDatabaseDefaultLocation.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 index 9b79817a8..97b66d99e 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabaseDefaultLocation.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseDefaultLocation.Tests.ps1 @@ -3,9 +3,9 @@ # Unit Test Template Version: 1.2.1 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) } Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global @@ -13,15 +13,18 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xSQLServer' ` - -DSCResourceName 'MSFT_xSQLServerDatabaseDefaultLocation' ` + -DSCModuleName 'SqlServerDsc' ` + -DSCResourceName 'MSFT_SqlDatabaseDefaultLocation' ` -TestType Unit #endregion HEADER -function Invoke-TestSetup {} +function Invoke-TestSetup +{ +} -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -31,9 +34,9 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_xSQLServerDatabaseDefaultLocation' { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' + InModuleScope 'MSFT_SqlDatabaseDefaultLocation' { + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' $mockSQLDataPath = 'C:\Program Files\Data\' $mockSqlLogPath = 'C:\Program Files\Log\' $mockSqlBackupPath = 'C:\Program Files\Backup\' @@ -56,52 +59,52 @@ try # Default parameters that are used for the It-blocks $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName + InstanceName = $mockInstanceName + ServerName = $mockServerName } $mockConnectSQL = { return New-Object Object -TypeName Microsoft.SqlServer.Management.Smo.Server | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru -Force | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru -Force | - Add-Member -MemberType NoteProperty -Name DefaultFile -Value $mockSqlDataPath -PassThru -Force | - Add-Member -MemberType NoteProperty -Name DefaultLog -Value $mockSqlLogPath -PassThru -Force | - Add-Member -MemberType NoteProperty -Name BackupDirectory -Value $mockSqlBackupPath -PassThru -Force | - Add-Member -MemberType ScriptMethod -Name Alter -Value { - if ($mockInvalidOperationForAlterMethod) - { - throw 'Mock Alter Method was called with invalid operation.' - } - $script:WasMethodAlterCalled = $true - } -PassThru -Force + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru -Force | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru -Force | + Add-Member -MemberType NoteProperty -Name DefaultFile -Value $mockSqlDataPath -PassThru -Force | + Add-Member -MemberType NoteProperty -Name DefaultLog -Value $mockSqlLogPath -PassThru -Force | + Add-Member -MemberType NoteProperty -Name BackupDirectory -Value $mockSqlBackupPath -PassThru -Force | + Add-Member -MemberType ScriptMethod -Name Alter -Value { + if ($mockInvalidOperationForAlterMethod) + { + throw 'Mock Alter Method was called with invalid operation.' + } + $script:WasMethodAlterCalled = $true + } -PassThru -Force } $testCases = @( @{ - Type = 'Data' - Path = $mockSqlDataPath - AlterPath = $mockSqlAlterDataPath + Type = 'Data' + Path = $mockSqlDataPath + AlterPath = $mockSqlAlterDataPath ExepectedAlterPath = $mockExpectedAlterDataPath - InvalidPath = $mockInvalidPathForData + InvalidPath = $mockInvalidPathForData }, @{ - Type = 'Log' - Path = $mockSqlLogPath - AlterPath = $mockSqlAlterLogPath + Type = 'Log' + Path = $mockSqlLogPath + AlterPath = $mockSqlAlterLogPath ExepectedAlterPath = $mockExpectedAlterLogPath - InvalidPath = $mockInvalidPathForLog + InvalidPath = $mockInvalidPathForLog }, @{ - Type = 'Backup' - Path = $mockSqlBackupPath - AlterPath = $mockSqlAlterBackupPath + Type = 'Backup' + Path = $mockSqlBackupPath + AlterPath = $mockSqlAlterBackupPath ExepectedAlterPath = $mockExpectedAlterBackupPath - InvalidPath = $mockInvalidPathForBackup + InvalidPath = $mockInvalidPathForBackup } ) #endregion - Describe 'MSFT_xSQLServerDatabaseDefaultLocation\Get-TargetResource' -Tag 'Get'{ + Describe 'MSFT_SqlDatabaseDefaultLocation\Get-TargetResource' -Tag 'Get' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Test-ActiveNode -Mockwith { @@ -127,15 +130,15 @@ try $getTargetResourceResult.Path | Should -Be $Path $getTargetResourceResult.Type | Should -Be $Type - $getTargetResourceResult.SQLServer | Should -Be $mockDefaultParameters.SQLServer - $getTargetResourceResult.SQLInstanceName | Should -Be $mockDefaultParameters.SQLInstanceName + $getTargetResourceResult.ServerName | Should -Be $mockDefaultParameters.ServerName + $getTargetResourceResult.InstanceName | Should -Be $mockDefaultParameters.InstanceName Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It } - } + } } - Describe 'MSFT_xSQLServerDatabaseDefaultLocation\Test-TargetResource' -Tag 'Test'{ + Describe 'MSFT_SqlDatabaseDefaultLocation\Test-TargetResource' -Tag 'Test' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Test-ActiveNode -MockWith { @@ -186,8 +189,8 @@ try It 'Should be "true" when ProcessOnlyOnActiveNode is .' { $testTargetResourceParameters = $mockDefaultParameters $testTargetResourceParameters += @{ - Path = $mockSqlDataPath - Type = 'Data' + Path = $mockSqlDataPath + Type = 'Data' ProcessOnlyOnActiveNode = $mockProcessOnlyOnActiveNode } @@ -200,8 +203,8 @@ try It 'Should be "true" when ProcessOnlyOnActiveNode is .' { $testTargetResourceParameters = $mockDefaultParameters $testTargetResourceParameters += @{ - Path = $mockSqlDataPath - Type = 'Data' + Path = $mockSqlDataPath + Type = 'Data' ProcessOnlyOnActiveNode = $mockProcessOnlyOnActiveNodeOriginal } @@ -213,7 +216,7 @@ try } } - Describe 'MSFT_xSQLServerDatabaseDefaultLocation\Set-TargetResource' -Tag 'Set'{ + Describe 'MSFT_SqlDatabaseDefaultLocation\Set-TargetResource' -Tag 'Set' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Restart-SqlService -Verifiable @@ -232,8 +235,8 @@ try ) $setTargetResourceParameters = @{ - Type = $Type - Path = $AlterPath + Type = $Type + Path = $AlterPath RestartService = $mockRestartService } @@ -253,8 +256,8 @@ try ) $setTargetResourceParameters = @{ - Type = $Type - Path = $InvalidPath + Type = $Type + Path = $InvalidPath RestartService = $mockRestartService } @@ -281,8 +284,8 @@ try $throwInvalidOperation = "Changing the default path failed." $setTargetResourceParameters = @{ - Type = $Type - Path = $ExepectedAlterPath + Type = $Type + Path = $ExepectedAlterPath RestartService = $mockRestartService } diff --git a/Tests/Unit/MSFT_xSQLServerDatabaseOwner.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 similarity index 62% rename from Tests/Unit/MSFT_xSQLServerDatabaseOwner.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 index ee95cb492..a3930a6c7 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabaseOwner.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseOwner.Tests.ps1 @@ -1,303 +1,305 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerDatabaseOwner' - -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { -} - -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -# Begin Testing -try -{ - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlDatabaseName = 'AdventureWorks' - $mockSqlServerLogin = 'Zebes\SamusAran' - $mockSqlServerLoginType = 'WindowsUser' - $mockDatabaseOwner = 'Elysia\Chozo' - $mockInvalidOperationForSetOwnerMethod = $false - $mockExpectedDatabaseOwner = 'Elysia\Chozo' - - # Default parameters that are used for the It-blocks - $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName - } - - #region Function mocks - $mockConnectSQL = { - return @( - ( - New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | - Add-Member -MemberType ScriptProperty -Name Databases -Value { - return @{ - $mockSqlDatabaseName = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | - Add-Member -MemberType NoteProperty -Name Owner -Value $mockDatabaseOwner -PassThru | - Add-Member -MemberType ScriptMethod -Name SetOwner -Value { - if ($mockInvalidOperationForSetOwnerMethod) - { - throw 'Mock of method SetOwner() was called with invalid operation.' - } - - if ( $this.Owner -ne $mockExpectedDatabaseOwner ) - { - throw "Called mocked SetOwner() method without setting the right login. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedDatabaseOwner, $this.Owner - } - } -PassThru -Force - )) - } - } -PassThru -Force | - Add-Member -MemberType ScriptProperty -Name Logins -Value { - return @{ - $mockSqlServerLogin = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru - )) - } - } -PassThru -Force - ) - ) - } - #endregion - - Describe "MSFT_xSQLServerDatabaseOwner\Get-TargetResource" -Tag 'Get'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When passing values to parameters and database name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = 'unknownDatabaseName' - Name = $mockSqlServerLogin - } - - $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is either in the desired state or not in the desired state' { - It 'Should not throw' { - $testParameters = $defaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - $result = Get-TargetResource @testParameters - } - - It 'Should return the name of the owner from the get method' { - $result.Name | Should -Be $testParameters.Name - } - - It 'Should return the same values as passed as parameters' { - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.Database | Should -Be $testParameters.Database - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerDatabaseOwner\Test-TargetResource" -Tag 'Test'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When the system is not in the desired state' { - It 'Should return the state as false when desired login is not the database owner' { - $testParameters = $defaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $false - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is in the desired state' { - It 'Should return the state as true when desired login is the database owner' { - $mockDatabaseOwner = 'Zebes\SamusAran' - $mockSqlServerLogin = 'Zebes\SamusAran' - $testParameters = $defaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $true - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerDatabaseOwner\Set-TargetResource" -Tag 'Set'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When the system is not in the desired state and database name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = 'unknownDatabaseName' - Name = $mockSqlServerLogin - } - - $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is not in the desired state and login name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = 'John' - } - - $throwInvalidOperation = ("Login 'John' does not exist on " + ` - "SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is not in the desired state' { - It 'Should not throw' { - $mockExpectedDatabaseOwner = $mockSqlServerLogin - $mockDatabaseOwner = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is not in the desired state' { - It 'Should throw the correct error when the method SetOwner() set the wrong login' { - $mockExpectedDatabaseOwner = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - $throwInvalidOperation = ('Failed to set owner named Zebes\SamusAran of the database ' + ` - 'named AdventureWorks on localhost\MSSQLSERVER. InnerException: ' + ` - 'Exception calling "SetOwner" with "1" argument(s): "Called mocked ' + ` - 'SetOwner() method without setting the right login. ' + ` - "Expected 'Zebes\SamusAran'. But was 'Elysia\Chozo'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is not in the desired state' { - It 'Should throw the correct error when the method SetOwner() was called' { - $mockInvalidOperationForSetOwnerMethod = $true - $mockExpectedDatabaseOwner = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - } - - $throwInvalidOperation = ('Failed to set owner named Zebes\SamusAran of the database ' + ` - 'named AdventureWorks on localhost\MSSQLSERVER. InnerException: ' + ` - 'Exception calling "SetOwner" with "1" argument(s): "Mock ' + ` - 'of method SetOwner() was called with invalid operation.') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Assert-VerifiableMock - } - } -} -finally -{ - Invoke-TestCleanup -} +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabaseOwner' + +#region HEADER + +# Unit Test Template Version: 1.2.0 +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +function Invoke-TestSetup +{ +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} + +# Begin Testing +try +{ + Invoke-TestSetup + + InModuleScope $script:DSCResourceName { + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlDatabaseName = 'AdventureWorks' + $mockSqlServerLogin = 'Zebes\SamusAran' + $mockSqlServerLoginType = 'WindowsUser' + $mockDatabaseOwner = 'Elysia\Chozo' + $mockInvalidOperationForSetOwnerMethod = $false + $mockExpectedDatabaseOwner = 'Elysia\Chozo' + + # Default parameters that are used for the It-blocks + $mockDefaultParameters = @{ + InstanceName = $mockInstanceName + ServerName = $mockServerName + } + + #region Function mocks + $mockConnectSQL = { + return @( + ( + New-Object Object | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | + Add-Member -MemberType ScriptProperty -Name Databases -Value { + return @{ + $mockSqlDatabaseName = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | + Add-Member -MemberType NoteProperty -Name Owner -Value $mockDatabaseOwner -PassThru | + Add-Member -MemberType ScriptMethod -Name SetOwner -Value { + if ($mockInvalidOperationForSetOwnerMethod) + { + throw 'Mock of method SetOwner() was called with invalid operation.' + } + + if ( $this.Owner -ne $mockExpectedDatabaseOwner ) + { + throw "Called mocked SetOwner() method without setting the right login. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedDatabaseOwner, $this.Owner + } + } -PassThru -Force + )) + } + } -PassThru -Force | + Add-Member -MemberType ScriptProperty -Name Logins -Value { + return @{ + $mockSqlServerLogin = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru + )) + } + } -PassThru -Force + ) + ) + } + #endregion + + Describe "MSFT_SqlDatabaseOwner\Get-TargetResource" -Tag 'Get' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When passing values to parameters and database name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = 'unknownDatabaseName' + Name = $mockSqlServerLogin + } + + $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is either in the desired state or not in the desired state' { + It 'Should not throw' { + $testParameters = $defaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + $result = Get-TargetResource @testParameters + } + + It 'Should return the name of the owner from the get method' { + $result.Name | Should -Be $testParameters.Name + } + + It 'Should return the same values as passed as parameters' { + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.Database | Should -Be $testParameters.Database + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlDatabaseOwner\Test-TargetResource" -Tag 'Test' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When the system is not in the desired state' { + It 'Should return the state as false when desired login is not the database owner' { + $testParameters = $defaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $false + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is in the desired state' { + It 'Should return the state as true when desired login is the database owner' { + $mockDatabaseOwner = 'Zebes\SamusAran' + $mockSqlServerLogin = 'Zebes\SamusAran' + $testParameters = $defaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $true + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlDatabaseOwner\Set-TargetResource" -Tag 'Set' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When the system is not in the desired state and database name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = 'unknownDatabaseName' + Name = $mockSqlServerLogin + } + + $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is not in the desired state and login name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = 'John' + } + + $throwInvalidOperation = ("Login 'John' does not exist on " + ` + "SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is not in the desired state' { + It 'Should not throw' { + $mockExpectedDatabaseOwner = $mockSqlServerLogin + $mockDatabaseOwner = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is not in the desired state' { + It 'Should throw the correct error when the method SetOwner() set the wrong login' { + $mockExpectedDatabaseOwner = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + $throwInvalidOperation = ('Failed to set owner named Zebes\SamusAran of the database ' + ` + 'named AdventureWorks on localhost\MSSQLSERVER. InnerException: ' + ` + 'Exception calling "SetOwner" with "1" argument(s): "Called mocked ' + ` + 'SetOwner() method without setting the right login. ' + ` + "Expected 'Zebes\SamusAran'. But was 'Elysia\Chozo'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is not in the desired state' { + It 'Should throw the correct error when the method SetOwner() was called' { + $mockInvalidOperationForSetOwnerMethod = $true + $mockExpectedDatabaseOwner = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + } + + $throwInvalidOperation = ('Failed to set owner named Zebes\SamusAran of the database ' + ` + 'named AdventureWorks on localhost\MSSQLSERVER. InnerException: ' + ` + 'Exception calling "SetOwner" with "1" argument(s): "Mock ' + ` + 'of method SetOwner() was called with invalid operation.') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Assert-VerifiableMock + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/Tests/Unit/MSFT_xSQLServerDatabasePermission.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 similarity index 58% rename from Tests/Unit/MSFT_xSQLServerDatabasePermission.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 index 5e8ca8aa9..dd8440891 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabasePermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabasePermission.Tests.ps1 @@ -1,860 +1,862 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerDatabasePermission' - -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { - # Loading mocked classes - Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') -} - -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -# Begin Testing -try -{ - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlDatabaseName = 'AdventureWorks' - $mockSqlServerLogin = 'Zebes\SamusAran' - $mockSqlServerLoginUnknown = 'Elysia\Chozo' - $mockLoginType = 'WindowsUser' - $mockInvalidOperationEnumDatabasePermissions = $false - $mockInvalidOperationForCreateMethod = $false - $mockExpectedSqlServerLogin = 'Zebes\SamusAran' - $mockSqlPermissionState = 'Grant' - - $mockSqlPermissionType01 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabasePermissionSet -ArgumentList ($true, $false) - $mockSqlPermissionType02 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabasePermissionSet -ArgumentList ($false, $true) - - $script:mockMethodGrantRan = $false - $script:mockMethodDenyRan = $false - $script:mockMethodRevokeRan = $false - $script:mockMethodCreateLoginRan = $false - - # Default parameters that are used for the It-blocks - $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName - } - - #region Function mocks - $mockConnectSQL = { - return @( - ( - New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | - Add-Member -MemberType ScriptProperty -Name Databases -Value { - return @{ - $mockSqlDatabaseName = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | - Add-Member -MemberType ScriptProperty -Name Users -Value { - return @{ - $mockSqlServerLogin = @(( - New-Object Object | - Add-Member -MemberType ScriptMethod -Name IsMember -Value { - return $true - } -PassThru - )) - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name EnumDatabasePermissions -Value { - param - ( - [Parameter()] - [System.String] - $SqlServerLogin - ) - if ($mockInvalidOperationEnumDatabasePermissions) - { - throw 'Mock EnumDatabasePermissions Method was called with invalid operation.' - } - - if ( $SqlServerLogin -eq $mockExpectedSqlServerLogin ) - { - $mockEnumDatabasePermissions = @() - $mockEnumDatabasePermissions += New-Object Object | - Add-Member -MemberType NoteProperty -Name PermissionType -Value $mockSqlPermissionType01 -PassThru | - Add-Member -MemberType NoteProperty -Name PermissionState -Value $mockSqlPermissionState -PassThru | - Add-Member -MemberType NoteProperty -Name Grantee -Value $mockExpectedSqlServerLogin -PassThru | - Add-Member -MemberType NoteProperty -Name GrantorType -Value 'User' -PassThru | - Add-Member -MemberType NoteProperty -Name ObjectClass -Value 'Database' -PassThru | - Add-Member -MemberType NoteProperty -Name ObjectName -Value $mockSqlDatabaseName -PassThru - $mockEnumDatabasePermissions += New-Object Object | - Add-Member -MemberType NoteProperty -Name PermissionType -Value $mockSqlPermissionType02 -PassThru | - Add-Member -MemberType NoteProperty -Name PermissionState -Value $mockSqlPermissionState -PassThru | - Add-Member -MemberType NoteProperty -Name Grantee -Value $mockExpectedSqlServerLogin -PassThru | - Add-Member -MemberType NoteProperty -Name GrantorType -Value 'User' -PassThru | - Add-Member -MemberType NoteProperty -Name ObjectClass -Value 'Database' -PassThru | - Add-Member -MemberType NoteProperty -Name ObjectName -Value $mockSqlDatabaseName -PassThru - - $mockEnumDatabasePermissions - } - else - { - return $null - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name Grant -Value { - param - ( - [Parameter()] - [System.Object] - $permissionSet, - - [Parameter()] - [System.String] - $SqlServerLogin - ) - - $script:mockMethodGrantRan = $true - - if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) - { - throw "Called mocked Grant() method without setting the right login name. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedSqlServerLogin, $SqlServerLogin - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name Revoke -Value { - param - ( - [Parameter()] - [System.Object] - $permissionSet, - - [Parameter()] - [System.String] - $SqlServerLogin - ) - - $script:mockMethodRevokeRan = $true - - if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) - { - throw "Called mocked Revoke() method without setting the right login name. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedSqlServerLogin, $SqlServerLogin - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name Deny -Value { - param - ( - [Parameter()] - [System.Object] - $permissionSet, - - [Parameter()] - [System.String] - $SqlServerLogin - ) - - $script:mockMethodDenyRan = $true - - if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) - { - throw "Called mocked Deny() method without setting the right login name. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedSqlServerLogin, $SqlServerLogin - } - } -PassThru -Force - )) - } - } -PassThru -Force | - Add-Member -MemberType ScriptProperty -Name Logins -Value { - return @{ - $mockSqlServerLogin = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockLoginType -PassThru - )) - $mockSqlServerLoginUnknown= @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockLoginType -PassThru - )) - } - } -PassThru -Force - ) - ) - } - - $mockNewObjectUser = { - return @( - ( - New-Object Object | - Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerLoginUnknown -PassThru | - Add-Member -MemberType NoteProperty -Name Login -Value $mockSqlServerLoginUnknown -PassThru | - Add-Member -MemberType ScriptMethod -Name Create -Value { - $script:mockMethodCreateLoginRan = $true - - if ($mockInvalidOperationForCreateMethod) - { - throw 'Mock Create Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedSqlServerLogin ) - { - throw "Called mocked Create() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedSqlServerLogin, $this.Name - } - } -PassThru -Force - ) - ) - } - - #endregion - - Describe "MSFT_xSQLServerDatabasePermission\Get-TargetResource" -Tag 'Get'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When passing values to parameters and database name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = 'unknownDatabaseName' - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - } - - $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and login name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = 'unknownLoginName' - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - } - - $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and database name and login name do exist' { - It 'Should throw the correct error with EnumDatabasePermissions method' { - $mockInvalidOperationEnumDatabasePermissions = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - } - - $throwInvalidOperation = ('Failed to get permission for login named Zebes\SamusAran of ' + ` - 'the database named AdventureWorks on localhost\MSSQLSERVER.') - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update','Select' ) - } - - It 'Should return the state as absent when the desired permission does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - } - - It 'Should not return the state as absent when the desired permission does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Not -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - } - - It 'Should return the state as absent when the desired permission does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Present' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update','Select' ) - } - - It 'Should not return the state as absent when the desired permission does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Not -Be 'Present' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerDatabasePermission\Test-TargetResource" -Tag 'Test'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When passing values to parameters and database name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = 'unknownDatabaseName' - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and login name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = 'unknownLoginName' - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and database name and login name do exist' { - It 'Should throw the correct error with EnumDatabasePermissions method' { - $mockInvalidOperationEnumDatabasePermissions = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ('Failed to get permission for login named Zebes\SamusAran of ' + ` - 'the database named AdventureWorks on localhost\MSSQLSERVER.') - - { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Absent' { - It 'Should return the state as true when the desired permission does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update','Select' ) - Ensure = 'Absent' - } - - Test-TargetResource @testParameters | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - It 'Should return the state as false when the desired permission does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - Test-TargetResource @testParameters | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Present' { - It 'Should return the state as false when the desired permission does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update','Select' ) - Ensure = 'Present' - } - - Test-TargetResource @testParameters | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Present' { - It 'Should return the state as true when the desired permission does exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - Test-TargetResource @testParameters | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerDatabasePermission\Set-TargetResource" -Tag 'Set'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - Mock -CommandName New-Object -MockWith $mockNewObjectUser -ParameterFilter { - $TypeName -eq 'Microsoft.SqlServer.Management.Smo.User' - } -Verifiable - - $script:mockMethodGrantRan = $false - $script:mockMethodDenyRan = $false - $script:mockMethodRevokeRan = $false - $script:mockMethodCreateLoginRan = $false - } - - Context 'When passing values to parameters and database name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = 'unknownDatabaseName' - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and login name does not exist' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = 'unknownLoginName' - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the login cannot be created' { - It 'Should throw the correct error' { - $mockInvalidOperationForCreateMethod = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLoginUnknown - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - $throwInvalidOperation = ('Failed adding the login Elysia\Chozo ' + ` - 'as a user of the database AdventureWorks, ' + ` - 'on the instance localhost\MSSQLSERVER.') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodCreateLoginRan | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state' { - Context 'When the mock methods fail (testing the test)' { - BeforeAll { - $throwInvalidOperation = ('Failed to set permission for login named ' + ` - 'Zebes\SamusAran of the database named ' + ` - 'AdventureWorks on localhost\MSSQLSERVER.') - - $mockExpectedSqlServerLogin = $mockSqlServerLoginUnknown - } - - It 'Should throw the correct error when mock Grant() method is called' { - $testParameters = $mockDefaultParameters.Clone() - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodGrantRan | Should -Be $true - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $false - } - - It 'Should throw the correct error when mock Grant() method is called (for GrantWithGrant)' { - $testParameters = $mockDefaultParameters.Clone() - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'GrantWithGrant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodGrantRan | Should -Be $true - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $false - } - - - It 'Should throw the correct error when mock Deny() method is called' { - $testParameters = $mockDefaultParameters.Clone() - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Deny' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $true - $script:mockMethodRevokeRan | Should -Be $false - } - - It 'Should throw the correct error when mock Revoke() method is called' { - $testParameters = $mockDefaultParameters.Clone() - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $true - } - - It 'Should throw the correct error when mock Revoke() method is called' { - $testParameters = $mockDefaultParameters.Clone() - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'GrantWithGrant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $true - } - } - - Context 'When Ensure is set to Present' { - Context 'When the login does not exist' { - It 'Should create the login without throwing an error' { - $mockInvalidOperationForCreateMethod = $false - $mockExpectedSqlServerLogin = $mockSqlServerLoginUnknown - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLoginUnknown - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodCreateLoginRan | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - It 'Should call the method Grant() without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $true - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the method Grant() (WithGrant) without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'GrantWithGrant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $true - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the method Deny() without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Deny' - Permissions = @( 'Connect','Update' ) - Ensure = 'Present' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $true - $script:mockMethodRevokeRan | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When Ensure is set to Absent' { - It 'Should call the method Revoke() for permission state ''Grant'' without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Grant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the method Revoke() for permission state ''GrantWithGrant'' without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'GrantWithGrant' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the method Revoke() for permission state ''Deny'' without throwing' { - $mockExpectedSqlServerLogin = $mockSqlServerLogin - $testParameters = $mockDefaultParameters - $testParameters += @{ - Database = $mockSqlDatabaseName - Name = $mockSqlServerLogin - PermissionState = 'Deny' - Permissions = @( 'Connect','Update' ) - Ensure = 'Absent' - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - $script:mockMethodGrantRan | Should -Be $false - $script:mockMethodDenyRan | Should -Be $false - $script:mockMethodRevokeRan | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - } - - Assert-VerifiableMock - } - } -} -finally -{ - Invoke-TestCleanup -}#endregion +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabasePermission' + +#region HEADER + +# Unit Test Template Version: 1.2.0 +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +function Invoke-TestSetup +{ + # Loading mocked classes + Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} + +# Begin Testing +try +{ + Invoke-TestSetup + + InModuleScope $script:DSCResourceName { + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlDatabaseName = 'AdventureWorks' + $mockSqlServerLogin = 'Zebes\SamusAran' + $mockSqlServerLoginUnknown = 'Elysia\Chozo' + $mockLoginType = 'WindowsUser' + $mockInvalidOperationEnumDatabasePermissions = $false + $mockInvalidOperationForCreateMethod = $false + $mockExpectedSqlServerLogin = 'Zebes\SamusAran' + $mockSqlPermissionState = 'Grant' + + $mockSqlPermissionType01 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabasePermissionSet -ArgumentList ($true, $false) + $mockSqlPermissionType02 = New-Object -TypeName Microsoft.SqlServer.Management.Smo.DatabasePermissionSet -ArgumentList ($false, $true) + + $script:mockMethodGrantRan = $false + $script:mockMethodDenyRan = $false + $script:mockMethodRevokeRan = $false + $script:mockMethodCreateLoginRan = $false + + # Default parameters that are used for the It-blocks + $mockDefaultParameters = @{ + InstanceName = $mockInstanceName + ServerName = $mockServerName + } + + #region Function mocks + $mockConnectSQL = { + return @( + ( + New-Object Object | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | + Add-Member -MemberType ScriptProperty -Name Databases -Value { + return @{ + $mockSqlDatabaseName = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | + Add-Member -MemberType ScriptProperty -Name Users -Value { + return @{ + $mockSqlServerLogin = @(( + New-Object Object | + Add-Member -MemberType ScriptMethod -Name IsMember -Value { + return $true + } -PassThru + )) + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name EnumDatabasePermissions -Value { + param + ( + [Parameter()] + [System.String] + $SqlServerLogin + ) + if ($mockInvalidOperationEnumDatabasePermissions) + { + throw 'Mock EnumDatabasePermissions Method was called with invalid operation.' + } + + if ( $SqlServerLogin -eq $mockExpectedSqlServerLogin ) + { + $mockEnumDatabasePermissions = @() + $mockEnumDatabasePermissions += New-Object Object | + Add-Member -MemberType NoteProperty -Name PermissionType -Value $mockSqlPermissionType01 -PassThru | + Add-Member -MemberType NoteProperty -Name PermissionState -Value $mockSqlPermissionState -PassThru | + Add-Member -MemberType NoteProperty -Name Grantee -Value $mockExpectedSqlServerLogin -PassThru | + Add-Member -MemberType NoteProperty -Name GrantorType -Value 'User' -PassThru | + Add-Member -MemberType NoteProperty -Name ObjectClass -Value 'Database' -PassThru | + Add-Member -MemberType NoteProperty -Name ObjectName -Value $mockSqlDatabaseName -PassThru + $mockEnumDatabasePermissions += New-Object Object | + Add-Member -MemberType NoteProperty -Name PermissionType -Value $mockSqlPermissionType02 -PassThru | + Add-Member -MemberType NoteProperty -Name PermissionState -Value $mockSqlPermissionState -PassThru | + Add-Member -MemberType NoteProperty -Name Grantee -Value $mockExpectedSqlServerLogin -PassThru | + Add-Member -MemberType NoteProperty -Name GrantorType -Value 'User' -PassThru | + Add-Member -MemberType NoteProperty -Name ObjectClass -Value 'Database' -PassThru | + Add-Member -MemberType NoteProperty -Name ObjectName -Value $mockSqlDatabaseName -PassThru + + $mockEnumDatabasePermissions + } + else + { + return $null + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name Grant -Value { + param + ( + [Parameter()] + [System.Object] + $permissionSet, + + [Parameter()] + [System.String] + $SqlServerLogin + ) + + $script:mockMethodGrantRan = $true + + if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) + { + throw "Called mocked Grant() method without setting the right login name. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedSqlServerLogin, $SqlServerLogin + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name Revoke -Value { + param + ( + [Parameter()] + [System.Object] + $permissionSet, + + [Parameter()] + [System.String] + $SqlServerLogin + ) + + $script:mockMethodRevokeRan = $true + + if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) + { + throw "Called mocked Revoke() method without setting the right login name. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedSqlServerLogin, $SqlServerLogin + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name Deny -Value { + param + ( + [Parameter()] + [System.Object] + $permissionSet, + + [Parameter()] + [System.String] + $SqlServerLogin + ) + + $script:mockMethodDenyRan = $true + + if ( $SqlServerLogin -ne $mockExpectedSqlServerLogin ) + { + throw "Called mocked Deny() method without setting the right login name. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedSqlServerLogin, $SqlServerLogin + } + } -PassThru -Force + )) + } + } -PassThru -Force | + Add-Member -MemberType ScriptProperty -Name Logins -Value { + return @{ + $mockSqlServerLogin = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockLoginType -PassThru + )) + $mockSqlServerLoginUnknown = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockLoginType -PassThru + )) + } + } -PassThru -Force + ) + ) + } + + $mockNewObjectUser = { + return @( + ( + New-Object Object | + Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerLoginUnknown -PassThru | + Add-Member -MemberType NoteProperty -Name Login -Value $mockSqlServerLoginUnknown -PassThru | + Add-Member -MemberType ScriptMethod -Name Create -Value { + $script:mockMethodCreateLoginRan = $true + + if ($mockInvalidOperationForCreateMethod) + { + throw 'Mock Create Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedSqlServerLogin ) + { + throw "Called mocked Create() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedSqlServerLogin, $this.Name + } + } -PassThru -Force + ) + ) + } + + #endregion + + Describe "MSFT_SqlDatabasePermission\Get-TargetResource" -Tag 'Get' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When passing values to parameters and database name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = 'unknownDatabaseName' + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + } + + $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and login name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = 'unknownLoginName' + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + } + + $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and database name and login name do exist' { + It 'Should throw the correct error with EnumDatabasePermissions method' { + $mockInvalidOperationEnumDatabasePermissions = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + } + + $throwInvalidOperation = ('Failed to get permission for login named Zebes\SamusAran of ' + ` + 'the database named AdventureWorks on localhost\MSSQLSERVER.') + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update', 'Select' ) + } + + It 'Should return the state as absent when the desired permission does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + } + + It 'Should not return the state as absent when the desired permission does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Not -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + } + + It 'Should return the state as absent when the desired permission does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Present' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update', 'Select' ) + } + + It 'Should not return the state as absent when the desired permission does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Not -Be 'Present' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlDatabasePermission\Test-TargetResource" -Tag 'Test' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When passing values to parameters and database name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = 'unknownDatabaseName' + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and login name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = 'unknownLoginName' + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and database name and login name do exist' { + It 'Should throw the correct error with EnumDatabasePermissions method' { + $mockInvalidOperationEnumDatabasePermissions = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ('Failed to get permission for login named Zebes\SamusAran of ' + ` + 'the database named AdventureWorks on localhost\MSSQLSERVER.') + + { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Absent' { + It 'Should return the state as true when the desired permission does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update', 'Select' ) + Ensure = 'Absent' + } + + Test-TargetResource @testParameters | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + It 'Should return the state as false when the desired permission does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + Test-TargetResource @testParameters | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Present' { + It 'Should return the state as false when the desired permission does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update', 'Select' ) + Ensure = 'Present' + } + + Test-TargetResource @testParameters | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Present' { + It 'Should return the state as true when the desired permission does exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + Test-TargetResource @testParameters | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlDatabasePermission\Set-TargetResource" -Tag 'Set' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + Mock -CommandName New-Object -MockWith $mockNewObjectUser -ParameterFilter { + $TypeName -eq 'Microsoft.SqlServer.Management.Smo.User' + } -Verifiable + + $script:mockMethodGrantRan = $false + $script:mockMethodDenyRan = $false + $script:mockMethodRevokeRan = $false + $script:mockMethodCreateLoginRan = $false + } + + Context 'When passing values to parameters and database name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = 'unknownDatabaseName' + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and login name does not exist' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = 'unknownLoginName' + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` + "on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the login cannot be created' { + It 'Should throw the correct error' { + $mockInvalidOperationForCreateMethod = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLoginUnknown + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + $throwInvalidOperation = ('Failed adding the login Elysia\Chozo ' + ` + 'as a user of the database AdventureWorks, ' + ` + 'on the instance localhost\MSSQLSERVER.') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodCreateLoginRan | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state' { + Context 'When the mock methods fail (testing the test)' { + BeforeAll { + $throwInvalidOperation = ('Failed to set permission for login named ' + ` + 'Zebes\SamusAran of the database named ' + ` + 'AdventureWorks on localhost\MSSQLSERVER.') + + $mockExpectedSqlServerLogin = $mockSqlServerLoginUnknown + } + + It 'Should throw the correct error when mock Grant() method is called' { + $testParameters = $mockDefaultParameters.Clone() + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodGrantRan | Should -Be $true + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $false + } + + It 'Should throw the correct error when mock Grant() method is called (for GrantWithGrant)' { + $testParameters = $mockDefaultParameters.Clone() + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'GrantWithGrant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodGrantRan | Should -Be $true + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $false + } + + + It 'Should throw the correct error when mock Deny() method is called' { + $testParameters = $mockDefaultParameters.Clone() + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Deny' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $true + $script:mockMethodRevokeRan | Should -Be $false + } + + It 'Should throw the correct error when mock Revoke() method is called' { + $testParameters = $mockDefaultParameters.Clone() + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $true + } + + It 'Should throw the correct error when mock Revoke() method is called' { + $testParameters = $mockDefaultParameters.Clone() + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'GrantWithGrant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $true + } + } + + Context 'When Ensure is set to Present' { + Context 'When the login does not exist' { + It 'Should create the login without throwing an error' { + $mockInvalidOperationForCreateMethod = $false + $mockExpectedSqlServerLogin = $mockSqlServerLoginUnknown + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLoginUnknown + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodCreateLoginRan | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + It 'Should call the method Grant() without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $true + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the method Grant() (WithGrant) without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'GrantWithGrant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $true + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the method Deny() without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Deny' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Present' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $true + $script:mockMethodRevokeRan | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When Ensure is set to Absent' { + It 'Should call the method Revoke() for permission state ''Grant'' without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Grant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the method Revoke() for permission state ''GrantWithGrant'' without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'GrantWithGrant' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the method Revoke() for permission state ''Deny'' without throwing' { + $mockExpectedSqlServerLogin = $mockSqlServerLogin + $testParameters = $mockDefaultParameters + $testParameters += @{ + Database = $mockSqlDatabaseName + Name = $mockSqlServerLogin + PermissionState = 'Deny' + Permissions = @( 'Connect', 'Update' ) + Ensure = 'Absent' + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + $script:mockMethodGrantRan | Should -Be $false + $script:mockMethodDenyRan | Should -Be $false + $script:mockMethodRevokeRan | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + } + + Assert-VerifiableMock + } + } +} +finally +{ + Invoke-TestCleanup +}#endregion diff --git a/Tests/Unit/MSFT_xSQLServerDatabaseRecoveryModel.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 similarity index 70% rename from Tests/Unit/MSFT_xSQLServerDatabaseRecoveryModel.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 index 5c0e09105..da6da4c71 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabaseRecoveryModel.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerDatabaseRecoveryModel' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabaseRecoveryModel' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,10 +20,12 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -32,17 +34,17 @@ try { Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlDatabaseName = 'AdventureWorks' - $mockSqlDatabaseRecoveryModel = 'Simple' - $mockInvalidOperationForAlterMethod = $false - $mockExpectedRecoveryModel = 'Simple' + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlDatabaseName = 'AdventureWorks' + $mockSqlDatabaseRecoveryModel = 'Simple' + $mockInvalidOperationForAlterMethod = $false + $mockExpectedRecoveryModel = 'Simple' # Default parameters that are used for the It-blocks $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName + InstanceName = $mockInstanceName + ServerName = $mockServerName } #region Function mocks @@ -50,34 +52,34 @@ try return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | Add-Member -MemberType ScriptProperty -Name Databases -Value { - return @{ - $mockSqlDatabaseName = ( New-Object Object | + return @{ + $mockSqlDatabaseName = ( New-Object Object | Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | Add-Member -MemberType NoteProperty -Name RecoveryModel -Value $mockSqlDatabaseRecoveryModel -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value { - if ($mockInvalidOperationForAlterMethod) - { - throw 'Mock Alter Method was called with invalid operation.' - } - - if ( $this.RecoveryModel -ne $mockExpectedRecoveryModel ) - { - throw "Called Alter Drop() method without setting the right recovery model. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedRecoveryModel, $this.RecoveryModel - } - } -PassThru - ) - } - } -PassThru -Force + if ($mockInvalidOperationForAlterMethod) + { + throw 'Mock Alter Method was called with invalid operation.' + } + + if ( $this.RecoveryModel -ne $mockExpectedRecoveryModel ) + { + throw "Called Alter Drop() method without setting the right recovery model. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedRecoveryModel, $this.RecoveryModel + } + } -PassThru + ) + } + } -PassThru -Force ) ) } #endregion - Describe "MSFT_xSQLServerDatabaseRecoveryModel\Get-TargetResource" -Tag 'Get'{ + Describe "MSFT_SqlDatabaseRecoveryModel\Get-TargetResource" -Tag 'Get' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -86,12 +88,12 @@ try It 'Should throw the correct error' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'UnknownDatabase' + Name = 'UnknownDatabase' RecoveryModel = 'Full' } $throwInvalidOperation = ("Database 'UnknownDatabase' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + "on SQL server 'localhost\MSSQLSERVER'.") { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -105,7 +107,7 @@ try It 'Should return wrong RecoveryModel' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Full' } @@ -114,8 +116,8 @@ try } It 'Should return the same values as passed as parameters' { - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -128,7 +130,7 @@ try It 'Should return the correct RecoveryModel' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Simple' } @@ -137,8 +139,8 @@ try } It 'Should return the same values as passed as parameters' { - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -150,7 +152,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabaseRecoveryModel\Test-TargetResource" -Tag 'Test'{ + Describe "MSFT_SqlDatabaseRecoveryModel\Test-TargetResource" -Tag 'Test' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -159,7 +161,7 @@ try It 'Should return the state as false when desired recovery model is not correct' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Full' } @@ -176,7 +178,7 @@ try It 'Should return the state as true when desired recovery model is correct' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Simple' } @@ -192,7 +194,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabaseRecoveryModel\Set-TargetResource" -Tag 'Set'{ + Describe "MSFT_SqlDatabaseRecoveryModel\Set-TargetResource" -Tag 'Set' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -201,12 +203,12 @@ try It 'Should throw the correct error' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'UnknownDatabase' + Name = 'UnknownDatabase' RecoveryModel = 'Full' } $throwInvalidOperation = ("Database 'UnknownDatabase' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + "on SQL server 'localhost\MSSQLSERVER'.") { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -221,7 +223,7 @@ try $mockExpectedRecoveryModel = 'Full' $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Full' } @@ -235,16 +237,16 @@ try Context 'When the system is not in the desired state' { It 'Should throw when calling the alter method when desired recovery model should be set' { - $mockInvalidOperationForAlterMethod = $true + $mockInvalidOperationForAlterMethod = $true $mockExpectedRecoveryModel = 'Full' $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'AdventureWorks' + Name = 'AdventureWorks' RecoveryModel = 'Full' } $throwInvalidOperation = ('Exception calling "Alter" with "0" argument(s): ' + - '"Mock Alter Method was called with invalid operation."') + '"Mock Alter Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } diff --git a/Tests/Unit/MSFT_xSQLServerDatabaseRole.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 similarity index 58% rename from Tests/Unit/MSFT_xSQLServerDatabaseRole.Tests.ps1 rename to Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 index d8af7bd41..bdfc490bb 100644 --- a/Tests/Unit/MSFT_xSQLServerDatabaseRole.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRole.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerDatabaseRole' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlDatabaseRole' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading mocked classes Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -35,27 +37,27 @@ try Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlDatabaseName = 'AdventureWorks' - $mockSqlServerLogin = 'John' - $mockSqlServerLoginOne = 'CONTOSO\KingJulian' - $mockSqlServerLoginTwo = 'CONTOSO\SQLAdmin' - $mockSqlServerLoginType = 'WindowsUser' - $mockSqlDatabaseRole = 'MyRole' - $mockSqlDatabaseRoleSecond = 'MySecondRole' - $mockExpectedSqlDatabaseRole = 'MyRole' - $mockInvalidOperationForAddMemberMethod = $false - $mockInvalidOperationForDropMemberMethod = $false - $mockInvalidOperationForCreateMethod = $false - $mockExpectedForAddMemberMethod = 'MySecondRole' - $mockExpectedForDropMemberMethod = 'MyRole' - $mockExpectedForCreateMethod = 'John' + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlDatabaseName = 'AdventureWorks' + $mockSqlServerLogin = 'John' + $mockSqlServerLoginOne = 'CONTOSO\KingJulian' + $mockSqlServerLoginTwo = 'CONTOSO\SQLAdmin' + $mockSqlServerLoginType = 'WindowsUser' + $mockSqlDatabaseRole = 'MyRole' + $mockSqlDatabaseRoleSecond = 'MySecondRole' + $mockExpectedSqlDatabaseRole = 'MyRole' + $mockInvalidOperationForAddMemberMethod = $false + $mockInvalidOperationForDropMemberMethod = $false + $mockInvalidOperationForCreateMethod = $false + $mockExpectedForAddMemberMethod = 'MySecondRole' + $mockExpectedForDropMemberMethod = 'MyRole' + $mockExpectedForCreateMethod = 'John' # Default parameters that are used for the It-blocks $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName + InstanceName = $mockInstanceName + ServerName = $mockServerName } #region Function mocks @@ -63,131 +65,131 @@ try return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | Add-Member -MemberType ScriptProperty -Name Databases -Value { - return @{ - $mockSqlDatabaseName = @(( + return @{ + $mockSqlDatabaseName = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseName -PassThru | Add-Member -MemberType ScriptProperty -Name Users -Value { - return @{ - $mockSqlServerLoginOne = @(( + return @{ + $mockSqlServerLoginOne = @(( New-Object Object | Add-Member -MemberType ScriptMethod -Name IsMember -Value { - param( - [String] - $mockSqlDatabaseRole - ) - if ( $mockSqlDatabaseRole -eq $mockExpectedSqlDatabaseRole ) - { - return $true - } - else - { - return $false - } - } -PassThru + param( + [String] + $mockSqlDatabaseRole + ) + if ( $mockSqlDatabaseRole -eq $mockExpectedSqlDatabaseRole ) + { + return $true + } + else + { + return $false + } + } -PassThru )) - $mockSqlServerLoginTwo = @(( + $mockSqlServerLoginTwo = @(( New-Object Object | Add-Member -MemberType ScriptMethod -Name IsMember -Value { - return $true - } -PassThru + return $true + } -PassThru )) - } - } -PassThru | + } + } -PassThru | Add-Member -MemberType ScriptProperty -Name Roles -Value { - return @{ - $mockSqlDatabaseRole = @(( + return @{ + $mockSqlDatabaseRole = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseRole -PassThru | Add-Member -MemberType ScriptMethod -Name AddMember -Value { - param( - [String] - $mockSqlServerLogin - ) - if ($mockInvalidOperationForAddMemberMethod) - { - throw 'Mock AddMember Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedForAddMemberMethod ) - { - throw "Called mocked AddMember() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedForAddMemberMethod, $this.Name - } - } -PassThru | + param( + [String] + $mockSqlServerLogin + ) + if ($mockInvalidOperationForAddMemberMethod) + { + throw 'Mock AddMember Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedForAddMemberMethod ) + { + throw "Called mocked AddMember() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedForAddMemberMethod, $this.Name + } + } -PassThru | Add-Member -MemberType ScriptMethod -Name DropMember -Value { - param( - [String] - $mockSqlServerLogin - ) - if ($mockInvalidOperationForDropMemberMethod) - { - throw 'Mock DropMember Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedForDropMemberMethod ) - { - throw "Called mocked Drop() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedForDropMemberMethod, $this.Name - } - } -PassThru + param( + [String] + $mockSqlServerLogin + ) + if ($mockInvalidOperationForDropMemberMethod) + { + throw 'Mock DropMember Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedForDropMemberMethod ) + { + throw "Called mocked Drop() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedForDropMemberMethod, $this.Name + } + } -PassThru )) - $mockSqlDatabaseRoleSecond = @(( + $mockSqlDatabaseRoleSecond = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlDatabaseRoleSecond -PassThru | Add-Member -MemberType ScriptMethod -Name AddMember -Value { - param( - [String] - $mockSqlServerLogin - ) - if ($mockInvalidOperationForAddMemberMethod) - { - throw 'Mock AddMember Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedForAddMemberMethod ) - { - throw "Called mocked AddMember() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedForAddMemberMethod, $this.Name - } - } -PassThru | + param( + [String] + $mockSqlServerLogin + ) + if ($mockInvalidOperationForAddMemberMethod) + { + throw 'Mock AddMember Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedForAddMemberMethod ) + { + throw "Called mocked AddMember() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedForAddMemberMethod, $this.Name + } + } -PassThru | Add-Member -MemberType ScriptMethod -Name DropMember -Value { - param( - [String] - $mockSqlServerLogin - ) - if ($mockInvalidOperationForDropMemberMethod) - { - throw 'Mock DropMember Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedForDropMemberMethod ) - { - throw "Called mocked Drop() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedForDropMemberMethod, $this.Name - } - } -PassThru + param( + [String] + $mockSqlServerLogin + ) + if ($mockInvalidOperationForDropMemberMethod) + { + throw 'Mock DropMember Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedForDropMemberMethod ) + { + throw "Called mocked Drop() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedForDropMemberMethod, $this.Name + } + } -PassThru )) - } - }-PassThru -Force - )) - } - } -PassThru -Force | + } + }-PassThru -Force + )) + } + } -PassThru -Force | Add-Member -MemberType ScriptProperty -Name Logins -Value { - return @{ - $mockSqlServerLoginOne = @(( + return @{ + $mockSqlServerLoginOne = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru )) - $mockSqlServerLoginTwo = @(( + $mockSqlServerLoginTwo = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru )) - $mockSqlServerLogin = @(( + $mockSqlServerLogin = @(( New-Object Object | Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru )) - } - } -PassThru -Force + } + } -PassThru -Force ) ) @@ -200,22 +202,22 @@ try Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerLogin -PassThru | Add-Member -MemberType NoteProperty -Name Login -Value $mockSqlServerLogin -PassThru | Add-Member -MemberType ScriptMethod -Name Create -Value { - if ($mockInvalidOperationForCreateMethod) - { - throw 'Mock Create Method was called with invalid operation.' - } - if ( $this.Name -ne $mockExpectedForCreateMethod ) - { - throw "Called mocked Create() method without adding the right user. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedForCreateMethod, $this.Name - } - } -PassThru -Force + if ($mockInvalidOperationForCreateMethod) + { + throw 'Mock Create Method was called with invalid operation.' + } + if ( $this.Name -ne $mockExpectedForCreateMethod ) + { + throw "Called mocked Create() method without adding the right user. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedForCreateMethod, $this.Name + } + } -PassThru -Force ) ) } #endregion - Describe "MSFT_xSQLServerDatabaseRole\Get-TargetResource" -Tag 'Get'{ + Describe "MSFT_SqlDatabaseRole\Get-TargetResource" -Tag 'Get' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -224,13 +226,13 @@ try It 'Should throw the correct error' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = 'unknownDatabaseName' - Role = $mockSqlDatabaseRole + Name = $mockSqlServerLoginOne + Database = 'unknownDatabaseName' + Role = $mockSqlDatabaseRole } $throwInvalidOperation = ("Database 'unknownDatabaseName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + "on SQL server 'localhost\MSSQLSERVER'.") { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -244,13 +246,13 @@ try It 'Should throw the correct error' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = 'unknownRoleName' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = 'unknownRoleName' } - $throwInvalidOperation = ("Role 'unknownRoleName' does not exist on database " + ` - "'AdventureWorks' on SQL server 'localhost\MSSQLSERVER'.") + $throwInvalidOperation = ("Role 'unknownRoleName' does not exist on database " + ` + "'AdventureWorks' on SQL server 'localhost\MSSQLSERVER'.") { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -264,9 +266,9 @@ try It 'Should not throw' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = @($mockSqlDatabaseRole,$mockSqlDatabaseRoleSecond) + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = @($mockSqlDatabaseRole, $mockSqlDatabaseRoleSecond) } { Get-TargetResource @testParameters } | Should -Not -Throw @@ -281,13 +283,13 @@ try It 'Should throw the correct error' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = 'unknownLoginName' - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole + Name = 'unknownLoginName' + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole } $throwInvalidOperation = ("Login 'unknownLoginName' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + "on SQL server 'localhost\MSSQLSERVER'.") { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -300,9 +302,9 @@ try Context 'When the system is not in the desired state, with one role' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond } It 'Should return the state as absent' { @@ -321,8 +323,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Database | Should -Be $testParameters.Database $result.Name | Should -Be $testParameters.Name @@ -333,9 +335,9 @@ try Context 'When the system is not in the desired state, with two roles' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = @($mockSqlDatabaseRole,$mockSqlDatabaseRoleSecond) + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = @($mockSqlDatabaseRole, $mockSqlDatabaseRoleSecond) } It 'Should return the state as absent' { @@ -354,8 +356,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Database | Should -Be $testParameters.Database $result.Name | Should -Be $testParameters.Name @@ -366,9 +368,9 @@ try Context 'When the system is not in the desired state, and login is not a member of the database' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLogin - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole + Name = $mockSqlServerLogin + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole } It 'Should return the state as absent' { @@ -380,8 +382,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Database | Should -Be $testParameters.Database $result.Name | Should -Be $testParameters.Name @@ -392,9 +394,9 @@ try Context 'When the system is in the desired state for a Windows user' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole } It 'Should return the state as absent' { @@ -406,8 +408,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.Database | Should -Be $testParameters.Database $result.Name | Should -Be $testParameters.Name $result.Role | Should -Be $testParameters.Role @@ -419,7 +421,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabaseRole\Test-TargetResource" -Tag 'Test'{ + Describe "MSFT_SqlDatabaseRole\Test-TargetResource" -Tag 'Test' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } @@ -428,10 +430,10 @@ try It 'Should return the state as false when one desired role is not configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond - Ensure = 'Present' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond + Ensure = 'Present' } $result = Test-TargetResource @testParameters @@ -447,10 +449,10 @@ try It 'Should return the state as false when two desired roles are not configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = @($mockSqlDatabaseRole,$mockSqlDatabaseRoleSecond) - Ensure = 'Present' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = @($mockSqlDatabaseRole, $mockSqlDatabaseRoleSecond) + Ensure = 'Present' } $result = Test-TargetResource @testParameters @@ -466,10 +468,10 @@ try It 'Should return the state as false when undesired roles are not configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginTwo - Database = $mockSqlDatabaseName - Role = @($mockSqlDatabaseRole,$mockSqlDatabaseRoleSecond) - Ensure = 'Absent' + Name = $mockSqlServerLoginTwo + Database = $mockSqlDatabaseName + Role = @($mockSqlDatabaseRole, $mockSqlDatabaseRoleSecond) + Ensure = 'Absent' } $result = Test-TargetResource @testParameters @@ -485,10 +487,10 @@ try It 'Should return the state as true when one desired role is correctly configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole - Ensure = 'Present' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole + Ensure = 'Present' } $result = Test-TargetResource @testParameters @@ -504,10 +506,10 @@ try It 'Should return the state as true when two desired role are correctly configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginTwo - Database = $mockSqlDatabaseName - Role = @($mockSqlDatabaseRole,$mockSqlDatabaseRoleSecond) - Ensure = 'Present' + Name = $mockSqlServerLoginTwo + Database = $mockSqlDatabaseName + Role = @($mockSqlDatabaseRole, $mockSqlDatabaseRoleSecond) + Ensure = 'Present' } $result = Test-TargetResource @testParameters @@ -523,10 +525,10 @@ try It 'Should return the state as true when two desired role are correctly configured' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond - Ensure = 'Absent' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond + Ensure = 'Absent' } $result = Test-TargetResource @testParameters @@ -541,7 +543,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerDatabaseRole\Set-TargetResource" -Tag 'Set'{ + Describe "MSFT_SqlDatabaseRole\Set-TargetResource" -Tag 'Set' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName New-Object -MockWith $mockNewObjectUser -ParameterFilter { @@ -551,13 +553,13 @@ try Context 'When the system is not in the desired state, Ensure is set to Present and Login does not exist' { It 'Should Not Throw when Ensure parameter is set to Present' { - $mockExpectedForAddMemberMethod = 'MyRole' + $mockExpectedForAddMemberMethod = 'MyRole' $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLogin - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole - Ensure = 'Present' + Name = $mockSqlServerLogin + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole + Ensure = 'Present' } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -579,15 +581,15 @@ try $mockInvalidOperationForCreateMethod = $true $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLogin - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond - Ensure = 'Present' + Name = $mockSqlServerLogin + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond + Ensure = 'Present' } $throwInvalidOperation = ('Failed adding the login John as a user of the database AdventureWorks, on ' + ` - 'the instance localhost\MSSQLSERVER. InnerException: Exception calling "Create" ' + ` - 'with "0" argument(s): "Mock Create Method was called with invalid operation."') + 'the instance localhost\MSSQLSERVER. InnerException: Exception calling "Create" ' + ` + 'with "0" argument(s): "Mock Create Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -609,10 +611,10 @@ try $mockSqlServerLogin = $mockSqlServerLoginOne $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLogin - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond - Ensure = 'Present' + Name = $mockSqlServerLogin + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond + Ensure = 'Present' } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -634,16 +636,16 @@ try $mockInvalidOperationForAddMemberMethod = $true $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginOne - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRoleSecond - Ensure = 'Present' + Name = $mockSqlServerLoginOne + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRoleSecond + Ensure = 'Present' } $throwInvalidOperation = ('Failed adding the login CONTOSO\KingJulian to the role MySecondRole on ' + ` - 'the database AdventureWorks, on the instance localhost\MSSQLSERVER. ' + ` - 'InnerException: Exception calling "AddMember" with "1" argument(s): ' + ` - '"Mock AddMember Method was called with invalid operation."') + 'the database AdventureWorks, on the instance localhost\MSSQLSERVER. ' + ` + 'InnerException: Exception calling "AddMember" with "1" argument(s): ' + ` + '"Mock AddMember Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } @@ -663,10 +665,10 @@ try It 'Should not throw the correct error when Ensure parameter is set to Absent' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginTwo - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole - Ensure = 'Absent' + Name = $mockSqlServerLoginTwo + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole + Ensure = 'Absent' } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -689,16 +691,16 @@ try It 'Should not throw the correct error when Ensure parameter is set to Absent' { $testParameters = $mockDefaultParameters $testParameters += @{ - Name = $mockSqlServerLoginTwo - Database = $mockSqlDatabaseName - Role = $mockSqlDatabaseRole - Ensure = 'Absent' + Name = $mockSqlServerLoginTwo + Database = $mockSqlDatabaseName + Role = $mockSqlDatabaseRole + Ensure = 'Absent' } $throwInvalidOperation = ('Failed removing the login CONTOSO\SQLAdmin from the role MyRole on ' + ` - 'the database AdventureWorks, on the instance localhost\MSSQLSERVER. ' + ` - 'InnerException: Exception calling "DropMember" with "1" argument(s): ' + ` - '"Mock DropMember Method was called with invalid operation."') + 'the database AdventureWorks, on the instance localhost\MSSQLSERVER. ' + ` + 'InnerException: Exception calling "DropMember" with "1" argument(s): ' + ` + '"Mock DropMember Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } diff --git a/Tests/Unit/MSFT_xSQLServerRSConfig.Tests.ps1 b/Tests/Unit/MSFT_SqlRS.Tests.ps1 similarity index 91% rename from Tests/Unit/MSFT_xSQLServerRSConfig.Tests.ps1 rename to Tests/Unit/MSFT_SqlRS.Tests.ps1 index 31bd51852..61d7a6cf1 100644 --- a/Tests/Unit/MSFT_xSQLServerRSConfig.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlRS.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerRSConfig' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlRS' #region HEADER @@ -190,16 +190,16 @@ try $Class -eq 'Win32_OperatingSystem' } - Describe "xSQLServerRSConfig\Get-TargetResource" -Tag 'Get' { + Describe "SqlRS\Get-TargetResource" -Tag 'Get' { BeforeAll { $mockDynamic_SqlBuildVersion = '13.0.4001.0' Mock -CommandName Get-ItemProperty -MockWith $mockGetItemProperty -Verifiable $defaultParameters = @{ - InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + InstanceName = $mockNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName } } @@ -225,8 +225,8 @@ try It 'Should return the same values as passed as parameters' { $resultGetTargetResource = Get-TargetResource @defaultParameters $resultGetTargetResource.InstanceName | Should -Be $mockNamedInstanceName - $resultGetTargetResource.RSSQLServer | Should -Be $mockReportingServicesDatabaseServerName - $resultGetTargetResource.RSSQLInstanceName | Should -Be $mockReportingServicesDatabaseNamedInstanceName + $resultGetTargetResource.DatabaseServerName | Should -Be $mockReportingServicesDatabaseServerName + $resultGetTargetResource.DatabaseInstanceName | Should -Be $mockReportingServicesDatabaseNamedInstanceName $resultGetTargetResource | Should -BeOfType [System.Collections.Hashtable] } @@ -260,8 +260,8 @@ try It 'Should return the same values as passed as parameters' { $resultGetTargetResource = Get-TargetResource @testParameters $resultGetTargetResource.InstanceName | Should -Be $mockDefaultInstanceName - $resultGetTargetResource.RSSQLServer | Should -Be $mockReportingServicesDatabaseServerName - $resultGetTargetResource.RSSQLInstanceName | Should -Be $mockReportingServicesDatabaseDefaultInstanceName + $resultGetTargetResource.DatabaseServerName | Should -Be $mockReportingServicesDatabaseServerName + $resultGetTargetResource.DatabaseInstanceName | Should -Be $mockReportingServicesDatabaseDefaultInstanceName $resultGetTargetResource | Should -BeOfType [System.Collections.Hashtable] } @@ -308,7 +308,7 @@ try Assert-VerifiableMock } - Describe "xSQLServerRSConfig\Set-TargetResource" -Tag 'Set' { + Describe "SqlRS\Set-TargetResource" -Tag 'Set' { BeforeAll { Mock -CommandName Import-SQLPSModule -Verifiable Mock -CommandName Invoke-Sqlcmd -Verifiable @@ -327,9 +327,9 @@ try } $defaultParameters = @{ - InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + InstanceName = $mockNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName } } @@ -410,8 +410,8 @@ try $testParameters = @{ InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName ReportServerVirtualDirectory = 'ReportServer_NewName' ReportsVirtualDirectory = 'Reports_NewName' ReportServerReservedUrl = 'https://+:4443' @@ -465,9 +465,9 @@ try } -Verifiable $defaultParameters = @{ - InstanceName = $mockDefaultInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseDefaultInstanceName + InstanceName = $mockDefaultInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseDefaultInstanceName } } @@ -504,7 +504,7 @@ try Assert-VerifiableMock } - Describe "xSQLServerRSConfig\Test-TargetResource" -Tag 'Test' { + Describe "SqlRS\Test-TargetResource" -Tag 'Test' { Context 'When the system is not in the desired state' { Context 'When Reporting Services are not initialized' { BeforeAll { @@ -515,9 +515,9 @@ try } -Verifiable $testParameters = @{ - InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + InstanceName = $mockNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName } } @@ -539,8 +539,8 @@ try $testParameters = @{ InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName ReportsVirtualDirectory = $mockVirtualDirectoryReportsName ReportServerVirtualDirectory = 'ReportServer_NewName' } @@ -564,8 +564,8 @@ try $testParameters = @{ InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName ReportServerVirtualDirectory = $mockVirtualDirectoryReportServerName ReportsVirtualDirectory = 'Reports_NewName' } @@ -588,8 +588,8 @@ try $testParameters = @{ InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName ReportServerReservedUrl = 'https://+:443' } } @@ -610,10 +610,10 @@ try } -Verifiable $testParameters = @{ - InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName - ReportsReservedUrl = 'https://+:443' + InstanceName = $mockNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName + ReportsReservedUrl = 'https://+:443' } } @@ -633,9 +633,9 @@ try } -Verifiable $defaultParameters = @{ - InstanceName = $mockNamedInstanceName - RSSQLServer = $mockReportingServicesDatabaseServerName - RSSQLInstanceName = $mockReportingServicesDatabaseNamedInstanceName + InstanceName = $mockNamedInstanceName + DatabaseServerName = $mockReportingServicesDatabaseServerName + DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName } } diff --git a/Tests/Unit/MSFT_xSQLServerScript.Tests.ps1 b/Tests/Unit/MSFT_SqlScript.Tests.ps1 similarity index 97% rename from Tests/Unit/MSFT_xSQLServerScript.Tests.ps1 rename to Tests/Unit/MSFT_SqlScript.Tests.ps1 index 133e725ab..579c68c2b 100644 --- a/Tests/Unit/MSFT_xSQLServerScript.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScript.Tests.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Automated unit test for MSFT_xSQLServerScript DSC Resource + Automated unit test for MSFT_SqlScript DSC Resource #> # Suppression of this PSSA rule allowed in tests. @@ -20,8 +20,8 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xSQLServer' ` - -DSCResourceName 'MSFT_xSQLServerScript' ` + -DSCModuleName 'SqlServerDsc' ` + -DSCResourceName 'MSFT_SqlScript' ` -TestType Unit #endregion HEADER @@ -41,9 +41,9 @@ try { Invoke-TestSetup - InModuleScope 'MSFT_xSQLServerScript' { - $script:DSCModuleName = 'xSQLServer' - $resourceName = 'MSFT_xSQLServerScript' + InModuleScope 'MSFT_SqlScript' { + $script:DSCModuleName = 'SqlServerDsc' + $resourceName = 'MSFT_SqlScript' $testParameters = @{ ServerInstance = $env:COMPUTERNAME diff --git a/Tests/Unit/MSFT_xSQLServerConfiguration.Tests.ps1 b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 similarity index 87% rename from Tests/Unit/MSFT_xSQLServerConfiguration.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 index bf332cf84..caa62dd21 100644 --- a/Tests/Unit/MSFT_xSQLServerConfiguration.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 @@ -1,12 +1,12 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerConfiguration' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerConfiguration' # Unit Test Template Version: 1.1.0 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -16,46 +16,46 @@ $TestEnvironment = Initialize-TestEnvironment ` -TestType Unit $defaultState = @{ - SQLServer = 'CLU01' - SQLInstanceName = 'ClusteredInstance' - OptionName = 'user connections' - OptionValue = 0 + ServerName = 'CLU01' + InstanceName = 'ClusteredInstance' + OptionName = 'user connections' + OptionValue = 0 RestartService = $false RestartTimeout = 120 } $desiredState = @{ - SQLServer = 'CLU01' - SQLInstanceName = 'ClusteredInstance' - OptionName = 'user connections' - OptionValue = 500 + ServerName = 'CLU01' + InstanceName = 'ClusteredInstance' + OptionName = 'user connections' + OptionValue = 500 RestartService = $false RestartTimeout = 120 } $desiredStateRestart = @{ - SQLServer = 'CLU01' - SQLInstanceName = 'ClusteredInstance' - OptionName = 'user connections' - OptionValue = 5000 + ServerName = 'CLU01' + InstanceName = 'ClusteredInstance' + OptionName = 'user connections' + OptionValue = 5000 RestartService = $true RestartTimeout = 120 } $dynamicOption = @{ - SQLServer = 'CLU02' - SQLInstanceName = 'ClusteredInstance' - OptionName = 'show advanced options' - OptionValue = 0 + ServerName = 'CLU02' + InstanceName = 'ClusteredInstance' + OptionName = 'show advanced options' + OptionValue = 0 RestartService = $false RestartTimeout = 120 } $invalidOption = @{ - SQLServer = 'CLU01' - SQLInstanceName = 'MSSQLSERVER' - OptionName = 'Does Not Exist' - OptionValue = 1 + ServerName = 'CLU01' + InstanceName = 'MSSQLSERVER' + OptionName = 'Does Not Exist' + OptionValue = 1 RestartService = $false RestartTimeout = 120 } @@ -95,8 +95,8 @@ try $result = Get-TargetResource @desiredState It 'Should return the same values as passed' { - $result.SQLServer | Should -Be $desiredState.SQLServer - $result.SQLInstanceName | Should -Be $desiredState.SQLInstanceName + $result.ServerName | Should -Be $desiredState.ServerName + $result.InstanceName | Should -Be $desiredState.InstanceName $result.OptionName | Should -Be $desiredState.OptionName $result.OptionValue | Should -Not -Be $desiredState.OptionValue $result.RestartService | Should -Be $desiredState.RestartService @@ -132,8 +132,8 @@ try $result = Get-TargetResource @desiredState It 'Should return the same values as passed' { - $result.SQLServer | Should -Be $desiredState.SQLServer - $result.SQLInstanceName | Should -Be $desiredState.SQLInstanceName + $result.ServerName | Should -Be $desiredState.ServerName + $result.InstanceName | Should -Be $desiredState.InstanceName $result.OptionName | Should -Be $desiredState.OptionName $result.OptionValue | Should -Be $desiredState.OptionValue $result.RestartService | Should -Be $desiredState.RestartService @@ -216,7 +216,7 @@ try @{ DisplayName = 'user connections' ConfigValue = 0 - IsDynamic = $false + IsDynamic = $false } ) } @@ -235,7 +235,7 @@ try @{ DisplayName = 'show advanced options' ConfigValue = 1 - IsDynamic = $true + IsDynamic = $true } ) } diff --git a/Tests/Unit/MSFT_xSQLServerEndpoint.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 similarity index 97% rename from Tests/Unit/MSFT_xSQLServerEndpoint.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 index 1ea60283a..164bfccff 100644 --- a/Tests/Unit/MSFT_xSQLServerEndpoint.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerEndpoint' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerEndpoint' #region HEADER @@ -35,7 +35,7 @@ try Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockNodeName = 'localhost' + $mockServerName = 'localhost' $mockInstanceName = 'INSTANCE1' $mockPrincipal = 'COMPANY\SqlServiceAcct' $mockOtherPrincipal = 'COMPANY\OtherAcct' @@ -136,12 +136,12 @@ try } $defaultParameters = @{ - SQLInstanceName = $mockInstanceName - SQLServer = $mockNodeName + InstanceName = $mockInstanceName + ServerName = $mockServerName EndpointName = $mockEndpointName } - Describe 'MSFT_xSQLServerEndpoint\Get-TargetResource' -Tag 'Get' { + Describe 'MSFT_SqlServerEndpoint\Get-TargetResource' -Tag 'Get' { BeforeEach { $testParameters = $defaultParameters @@ -159,8 +159,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName } It 'Should not return any values in the properties for the endpoint' { @@ -187,8 +187,8 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName $result.EndpointName | Should -Be $testParameters.EndpointName $result.Port | Should -Be $mockEndpointListenerPort $result.IpAddress | Should -Be $mockEndpointListenerIpAddress @@ -225,7 +225,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpoint\Test-TargetResource' -Tag 'Test' { + Describe 'MSFT_SqlServerEndpoint\Test-TargetResource' -Tag 'Test' { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -335,7 +335,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpoint\Set-TargetResource' -Tag 'Set' { + Describe 'MSFT_SqlServerEndpoint\Set-TargetResource' -Tag 'Set' { BeforeEach { $testParameters = $defaultParameters.Clone() diff --git a/Tests/Unit/MSFT_xSQLServerEndpointPermission.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 similarity index 76% rename from Tests/Unit/MSFT_xSQLServerEndpointPermission.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 index bf6929a5c..784181137 100644 --- a/Tests/Unit/MSFT_xSQLServerEndpointPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpointPermission.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerEndpointPermission' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerEndpointPermission' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading mocked classes Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -49,49 +51,49 @@ try $mockConnectSql = { return New-Object Object | Add-Member -MemberType ScriptProperty -Name 'Endpoints' { - return @( - @{ - # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint - $mockDynamicEndpointName = New-Object Object | - Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockEndpointName -PassThru | - Add-Member -MemberType ScriptMethod -Name 'EnumObjectPermissions' { - param($permissionSet) - return @( - (New-Object Object | - Add-Member -MemberType NoteProperty Grantee $mockDynamicPrincipal -PassThru | - Add-Member -MemberType NoteProperty PermissionState 'Grant' -PassThru - ) - ) - } -PassThru | - Add-Member -MemberType ScriptMethod -Name 'Grant' { - param( - $permissionSet, - $mockPrincipal - ) - - $script:mockMethodGrantRan = $true - } -PassThru | - Add-Member -MemberType ScriptMethod -Name 'Revoke' { - param( - $permissionSet, - $mockPrincipal - ) - - $script:mockMethodRevokeRan = $true - } -PassThru -Force - } - ) - } -PassThru -Force + return @( + @{ + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + $mockDynamicEndpointName = New-Object Object | + Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockEndpointName -PassThru | + Add-Member -MemberType ScriptMethod -Name 'EnumObjectPermissions' { + param($permissionSet) + return @( + (New-Object Object | + Add-Member -MemberType NoteProperty Grantee $mockDynamicPrincipal -PassThru | + Add-Member -MemberType NoteProperty PermissionState 'Grant' -PassThru + ) + ) + } -PassThru | + Add-Member -MemberType ScriptMethod -Name 'Grant' { + param( + $permissionSet, + $mockPrincipal + ) + + $script:mockMethodGrantRan = $true + } -PassThru | + Add-Member -MemberType ScriptMethod -Name 'Revoke' { + param( + $permissionSet, + $mockPrincipal + ) + + $script:mockMethodRevokeRan = $true + } -PassThru -Force + } + ) + } -PassThru -Force } $defaultParameters = @{ InstanceName = $mockInstanceName - NodeName = $mockNodeName - Name = $mockEndpointName - Principal = $mockPrincipal + ServerName = $mockNodeName + Name = $mockEndpointName + Principal = $mockPrincipal } - Describe 'MSFT_xSQLServerEndpointPermission\Get-TargetResource' -Tag 'Get' { + Describe 'MSFT_SqlServerEndpointPermission\Get-TargetResource' -Tag 'Get' { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -108,7 +110,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.Principal | Should -Be $testParameters.Principal @@ -147,7 +149,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name $result.Principal | Should -Be $testParameters.Principal @@ -167,7 +169,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpointPermission\Test-TargetResource' -Tag 'Test' { + Describe 'MSFT_SqlServerEndpointPermission\Test-TargetResource' -Tag 'Test' { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -229,7 +231,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpointPermission\Set-TargetResource' -Tag 'Set' { + Describe 'MSFT_SqlServerEndpointPermission\Set-TargetResource' -Tag 'Set' { BeforeEach { $testParameters = $defaultParameters.Clone() diff --git a/Tests/Unit/MSFT_xSQLServerEndpointState.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 similarity index 88% rename from Tests/Unit/MSFT_xSQLServerEndpointState.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 index 56cb6e342..385aa7f62 100644 --- a/Tests/Unit/MSFT_xSQLServerEndpointState.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerEndpointState' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerEndpointState' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading stub cmdlets Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -49,26 +51,26 @@ try $mockConnectSql = { return New-Object Object | Add-Member -MemberType ScriptProperty -Name 'Endpoints' { - return @( - @{ - # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint - $mockDynamicEndpointName = New-Object Object | - Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru | - Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force - } - ) - } -PassThru -Force + return @( + @{ + # TypeName: Microsoft.SqlServer.Management.Smo.Endpoint + $mockDynamicEndpointName = New-Object Object | + Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru | + Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force + } + ) + } -PassThru -Force } $defaultParameters = @{ InstanceName = $mockInstanceName - NodeName = $mockNodeName - Name = $mockEndpointName + ServerName = $mockNodeName + Name = $mockEndpointName } #endregion Pester Test Initialization - Describe 'MSFT_xSQLServerEndpointState\Get-TargetResource' -Tag Get { + Describe 'MSFT_SqlServerEndpointState\Get-TargetResource' -Tag Get { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -88,7 +90,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -109,7 +111,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -144,7 +146,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -165,7 +167,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $testParameters.NodeName + $result.ServerName | Should -Be $testParameters.ServerName $result.InstanceName | Should -Be $testParameters.InstanceName $result.Name | Should -Be $testParameters.Name } @@ -180,7 +182,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpointState\Test-TargetResource' -Tag Test { + Describe 'MSFT_SqlServerEndpointState\Test-TargetResource' -Tag Test { BeforeEach { $testParameters = $defaultParameters.Clone() @@ -258,7 +260,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerEndpointState\Set-TargetResource' -Tag Set { + Describe 'MSFT_SqlServerEndpointState\Set-TargetResource' -Tag Set { BeforeEach { $testParameters = $defaultParameters.Clone() diff --git a/Tests/Unit/MSFT_xSQLServerLogin.Tests.ps1 b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 similarity index 89% rename from Tests/Unit/MSFT_xSQLServerLogin.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 index a7b335256..78c4867ea 100644 --- a/Tests/Unit/MSFT_xSQLServerLogin.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 @@ -2,17 +2,17 @@ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerLogin' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerLogin' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -24,12 +24,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -54,112 +56,112 @@ try $mockSqlLoginCredentialOtherPassword = New-Object System.Management.Automation.PSCredential( $mockSqlLoginUser, $mockSqlLoginOtherPassword ) $instanceParameters = @{ - SQLInstanceName = 'MSSQLSERVER' - SQLServer = 'Server1' + InstanceName = 'MSSQLSERVER' + ServerName = 'Server1' } $getTargetResource_UnknownSqlLogin = $instanceParameters.Clone() - $getTargetResource_UnknownSqlLogin.Add( 'Name','UnknownSqlLogin' ) + $getTargetResource_UnknownSqlLogin.Add( 'Name', 'UnknownSqlLogin' ) $getTargetResource_UnknownWindows = $instanceParameters.Clone() - $getTargetResource_UnknownWindows.Add( 'Name','Windows\UserOrGroup' ) + $getTargetResource_UnknownWindows.Add( 'Name', 'Windows\UserOrGroup' ) $getTargetResource_KnownSqlLogin = $instanceParameters.Clone() - $getTargetResource_KnownSqlLogin.Add( 'Name','SqlLogin1' ) + $getTargetResource_KnownSqlLogin.Add( 'Name', 'SqlLogin1' ) $getTargetResource_KnownWindowsUser = $instanceParameters.Clone() - $getTargetResource_KnownWindowsUser.Add( 'Name','Windows\User1' ) + $getTargetResource_KnownWindowsUser.Add( 'Name', 'Windows\User1' ) $getTargetResource_KnownWindowsGroup = $instanceParameters.Clone() - $getTargetResource_KnownWindowsGroup.Add( 'Name','Windows\Group1' ) + $getTargetResource_KnownWindowsGroup.Add( 'Name', 'Windows\Group1' ) $testTargetResource_WindowsUserAbsent = $instanceParameters.Clone() - $testTargetResource_WindowsUserAbsent.Add( 'Name','Windows\UserAbsent' ) - $testTargetResource_WindowsUserAbsent.Add( 'LoginType','WindowsUser' ) + $testTargetResource_WindowsUserAbsent.Add( 'Name', 'Windows\UserAbsent' ) + $testTargetResource_WindowsUserAbsent.Add( 'LoginType', 'WindowsUser' ) $testTargetResource_WindowsGroupAbsent = $instanceParameters.Clone() - $testTargetResource_WindowsGroupAbsent.Add( 'Name','Windows\GroupAbsent' ) - $testTargetResource_WindowsGroupAbsent.Add( 'LoginType','WindowsGroup' ) + $testTargetResource_WindowsGroupAbsent.Add( 'Name', 'Windows\GroupAbsent' ) + $testTargetResource_WindowsGroupAbsent.Add( 'LoginType', 'WindowsGroup' ) $testTargetResource_SqlLoginAbsent = $instanceParameters.Clone() - $testTargetResource_SqlLoginAbsent.Add( 'Name','SqlLoginAbsent' ) - $testTargetResource_SqlLoginAbsent.Add( 'LoginType','SqlLogin' ) + $testTargetResource_SqlLoginAbsent.Add( 'Name', 'SqlLoginAbsent' ) + $testTargetResource_SqlLoginAbsent.Add( 'LoginType', 'SqlLogin' ) $testTargetResource_WindowsUserPresent = $instanceParameters.Clone() - $testTargetResource_WindowsUserPresent.Add( 'Name','Windows\User1' ) - $testTargetResource_WindowsUserPresent.Add( 'LoginType','WindowsUser' ) + $testTargetResource_WindowsUserPresent.Add( 'Name', 'Windows\User1' ) + $testTargetResource_WindowsUserPresent.Add( 'LoginType', 'WindowsUser' ) $testTargetResource_WindowsGroupPresent = $instanceParameters.Clone() - $testTargetResource_WindowsGroupPresent.Add( 'Name','Windows\Group1' ) - $testTargetResource_WindowsGroupPresent.Add( 'LoginType','WindowsGroup' ) + $testTargetResource_WindowsGroupPresent.Add( 'Name', 'Windows\Group1' ) + $testTargetResource_WindowsGroupPresent.Add( 'LoginType', 'WindowsGroup' ) $testTargetResource_SqlLoginPresentWithDefaultValues = $instanceParameters.Clone() - $testTargetResource_SqlLoginPresentWithDefaultValues.Add( 'Name','SqlLogin1' ) - $testTargetResource_SqlLoginPresentWithDefaultValues.Add( 'LoginType','SqlLogin' ) + $testTargetResource_SqlLoginPresentWithDefaultValues.Add( 'Name', 'SqlLogin1' ) + $testTargetResource_SqlLoginPresentWithDefaultValues.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_CertificateAbsent = $instanceParameters.Clone() - $setTargetResource_CertificateAbsent.Add( 'Name','Certificate' ) - $setTargetResource_CertificateAbsent.Add( 'LoginType','Certificate' ) + $setTargetResource_CertificateAbsent.Add( 'Name', 'Certificate' ) + $setTargetResource_CertificateAbsent.Add( 'LoginType', 'Certificate' ) $setTargetResource_WindowsUserAbsent = $instanceParameters.Clone() - $setTargetResource_WindowsUserAbsent.Add( 'Name','Windows\UserAbsent' ) - $setTargetResource_WindowsUserAbsent.Add( 'LoginType','WindowsUser' ) + $setTargetResource_WindowsUserAbsent.Add( 'Name', 'Windows\UserAbsent' ) + $setTargetResource_WindowsUserAbsent.Add( 'LoginType', 'WindowsUser' ) $setTargetResource_WindowsGroupAbsent = $instanceParameters.Clone() - $setTargetResource_WindowsGroupAbsent.Add( 'Name','Windows\GroupAbsent' ) - $setTargetResource_WindowsGroupAbsent.Add( 'LoginType','WindowsGroup' ) + $setTargetResource_WindowsGroupAbsent.Add( 'Name', 'Windows\GroupAbsent' ) + $setTargetResource_WindowsGroupAbsent.Add( 'LoginType', 'WindowsGroup' ) $setTargetResource_SqlLoginAbsent = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsent.Add( 'Name','SqlLoginAbsent' ) - $setTargetResource_SqlLoginAbsent.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsent.Add( 'Name', 'SqlLoginAbsent' ) + $setTargetResource_SqlLoginAbsent.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_SqlLoginAbsentExisting = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsentExisting.Add( 'Name','Existing' ) - $setTargetResource_SqlLoginAbsentExisting.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsentExisting.Add( 'Name', 'Existing' ) + $setTargetResource_SqlLoginAbsentExisting.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_SqlLoginAbsentUnknown = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsentUnknown.Add( 'Name','Unknown' ) - $setTargetResource_SqlLoginAbsentUnknown.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsentUnknown.Add( 'Name', 'Unknown' ) + $setTargetResource_SqlLoginAbsentUnknown.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_WindowsUserPresent = $instanceParameters.Clone() - $setTargetResource_WindowsUserPresent.Add( 'Name','Windows\User1' ) - $setTargetResource_WindowsUserPresent.Add( 'LoginType','WindowsUser' ) + $setTargetResource_WindowsUserPresent.Add( 'Name', 'Windows\User1' ) + $setTargetResource_WindowsUserPresent.Add( 'LoginType', 'WindowsUser' ) $setTargetResource_CertificateAbsent = $instanceParameters.Clone() - $setTargetResource_CertificateAbsent.Add( 'Name','Certificate' ) - $setTargetResource_CertificateAbsent.Add( 'LoginType','Certificate' ) + $setTargetResource_CertificateAbsent.Add( 'Name', 'Certificate' ) + $setTargetResource_CertificateAbsent.Add( 'LoginType', 'Certificate' ) $setTargetResource_WindowsUserAbsent = $instanceParameters.Clone() - $setTargetResource_WindowsUserAbsent.Add( 'Name','Windows\UserAbsent' ) - $setTargetResource_WindowsUserAbsent.Add( 'LoginType','WindowsUser' ) + $setTargetResource_WindowsUserAbsent.Add( 'Name', 'Windows\UserAbsent' ) + $setTargetResource_WindowsUserAbsent.Add( 'LoginType', 'WindowsUser' ) $setTargetResource_WindowsGroupAbsent = $instanceParameters.Clone() - $setTargetResource_WindowsGroupAbsent.Add( 'Name','Windows\GroupAbsent' ) - $setTargetResource_WindowsGroupAbsent.Add( 'LoginType','WindowsGroup' ) + $setTargetResource_WindowsGroupAbsent.Add( 'Name', 'Windows\GroupAbsent' ) + $setTargetResource_WindowsGroupAbsent.Add( 'LoginType', 'WindowsGroup' ) $setTargetResource_SqlLoginAbsent = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsent.Add( 'Name','SqlLoginAbsent' ) - $setTargetResource_SqlLoginAbsent.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsent.Add( 'Name', 'SqlLoginAbsent' ) + $setTargetResource_SqlLoginAbsent.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_SqlLoginAbsentExisting = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsentExisting.Add( 'Name','Existing' ) - $setTargetResource_SqlLoginAbsentExisting.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsentExisting.Add( 'Name', 'Existing' ) + $setTargetResource_SqlLoginAbsentExisting.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_SqlLoginAbsentUnknown = $instanceParameters.Clone() - $setTargetResource_SqlLoginAbsentUnknown.Add( 'Name','Unknown' ) - $setTargetResource_SqlLoginAbsentUnknown.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginAbsentUnknown.Add( 'Name', 'Unknown' ) + $setTargetResource_SqlLoginAbsentUnknown.Add( 'LoginType', 'SqlLogin' ) $setTargetResource_WindowsUserPresent = $instanceParameters.Clone() - $setTargetResource_WindowsUserPresent.Add( 'Name','Windows\User1' ) - $setTargetResource_WindowsUserPresent.Add( 'LoginType','WindowsUser' ) + $setTargetResource_WindowsUserPresent.Add( 'Name', 'Windows\User1' ) + $setTargetResource_WindowsUserPresent.Add( 'LoginType', 'WindowsUser' ) $setTargetResource_WindowsGroupPresent = $instanceParameters.Clone() - $setTargetResource_WindowsGroupPresent.Add( 'Name','Windows\Group1' ) - $setTargetResource_WindowsGroupPresent.Add( 'LoginType','WindowsGroup' ) + $setTargetResource_WindowsGroupPresent.Add( 'Name', 'Windows\Group1' ) + $setTargetResource_WindowsGroupPresent.Add( 'LoginType', 'WindowsGroup' ) $setTargetResource_SqlLoginPresent = $instanceParameters.Clone() - $setTargetResource_SqlLoginPresent.Add( 'Name','SqlLogin1' ) - $setTargetResource_SqlLoginPresent.Add( 'LoginType','SqlLogin' ) + $setTargetResource_SqlLoginPresent.Add( 'Name', 'SqlLogin1' ) + $setTargetResource_SqlLoginPresent.Add( 'LoginType', 'SqlLogin' ) <# These are set when the mocked methods Enable() and Disabled() are called. @@ -206,7 +208,7 @@ try #endregion Pester Test Initialization - Describe 'MSFT_xSQLServerLogin\Get-TargetResource' { + Describe 'MSFT_SqlServerLogin\Get-TargetResource' { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Context 'When the login is Absent' { @@ -263,7 +265,7 @@ try It 'Should be return the correct values when a login is disabled' { $mockGetTargetResourceParameters = $instanceParameters.Clone() - $mockGetTargetResourceParameters.Add( 'Name','Windows\UserDisabled' ) + $mockGetTargetResourceParameters.Add( 'Name', 'Windows\UserDisabled' ) $result = Get-TargetResource @mockGetTargetResourceParameters $result.Ensure | Should -Be 'Present' @@ -278,13 +280,13 @@ try } } - Describe 'MSFT_xSQLServerLogin\Test-TargetResource' { + Describe 'MSFT_SqlServerLogin\Test-TargetResource' { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Context 'When the desired state is Absent' { It 'Should return $true when the specified Windows user is Absent' { $testTargetResource_WindowsUserAbsent_EnsureAbsent = $testTargetResource_WindowsUserAbsent.Clone() - $testTargetResource_WindowsUserAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_WindowsUserAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_WindowsUserAbsent_EnsureAbsent ) | Should -Be $true @@ -293,7 +295,7 @@ try It 'Should return $true when the specified Windows group is Absent' { $testTargetResource_WindowsGroupAbsent_EnsureAbsent = $testTargetResource_WindowsGroupAbsent.Clone() - $testTargetResource_WindowsGroupAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_WindowsGroupAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_WindowsGroupAbsent_EnsureAbsent ) | Should -Be $true @@ -302,7 +304,7 @@ try It 'Should return $true when the specified SQL Login is Absent' { $testTargetResource_SqlLoginAbsent_EnsureAbsent = $testTargetResource_SqlLoginAbsent.Clone() - $testTargetResource_SqlLoginAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_SqlLoginAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_SqlLoginAbsent_EnsureAbsent ) | Should -Be $true @@ -311,7 +313,7 @@ try It 'Should return $false when the specified Windows user is Present' { $testTargetResource_WindowsUserPresent_EnsureAbsent = $testTargetResource_WindowsUserPresent.Clone() - $testTargetResource_WindowsUserPresent_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_WindowsUserPresent_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_WindowsUserPresent_EnsureAbsent ) | Should -Be $false @@ -320,7 +322,7 @@ try It 'Should return $false when the specified Windows group is Present' { $testTargetResource_WindowsGroupPresent_EnsureAbsent = $testTargetResource_WindowsGroupPresent.Clone() - $testTargetResource_WindowsGroupPresent_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_WindowsGroupPresent_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_WindowsGroupPresent_EnsureAbsent ) | Should -Be $false @@ -329,7 +331,7 @@ try It 'Should return $false when the specified SQL Login is Present' { $testTargetResource_SqlLoginPresentWithDefaultValues_EnsureAbsent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithDefaultValues_EnsureAbsent.Add( 'Ensure','Absent' ) + $testTargetResource_SqlLoginPresentWithDefaultValues_EnsureAbsent.Add( 'Ensure', 'Absent' ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithDefaultValues_EnsureAbsent ) | Should -Be $false @@ -338,8 +340,8 @@ try It 'Should be return $false when a login should be disabled but are enabled' { $mockTestTargetResourceParameters = $instanceParameters.Clone() - $mockTestTargetResourceParameters.Add( 'Ensure','Present' ) - $mockTestTargetResourceParameters.Add( 'Name','Windows\User1' ) + $mockTestTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockTestTargetResourceParameters.Add( 'Name', 'Windows\User1' ) $mockTestTargetResourceParameters.Add( 'Disabled', $true ) $result = Test-TargetResource @mockTestTargetResourceParameters @@ -350,8 +352,8 @@ try It 'Should be return $false when a login should be enabled but are disabled' { $mockTestTargetResourceParameters = $instanceParameters.Clone() - $mockTestTargetResourceParameters.Add( 'Ensure','Present' ) - $mockTestTargetResourceParameters.Add( 'Name','Windows\UserDisabled' ) + $mockTestTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockTestTargetResourceParameters.Add( 'Name', 'Windows\UserDisabled' ) $mockTestTargetResourceParameters.Add( 'Disabled', $false ) $result = Test-TargetResource @mockTestTargetResourceParameters @@ -364,7 +366,7 @@ try Context 'When the desired state is Present' { It 'Should return $false when the specified Windows user is Absent' { $testTargetResource_WindowsUserAbsent_EnsurePresent = $testTargetResource_WindowsUserAbsent.Clone() - $testTargetResource_WindowsUserAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_WindowsUserAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_WindowsUserAbsent_EnsurePresent ) | Should -Be $false @@ -373,7 +375,7 @@ try It 'Should return $false when the specified Windows group is Absent' { $testTargetResource_WindowsGroupAbsent_EnsurePresent = $testTargetResource_WindowsGroupAbsent.Clone() - $testTargetResource_WindowsGroupAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_WindowsGroupAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_WindowsGroupAbsent_EnsurePresent ) | Should -Be $false @@ -382,7 +384,7 @@ try It 'Should return $false when the specified SQL Login is Absent' { $testTargetResource_SqlLoginAbsent_EnsurePresent = $testTargetResource_SqlLoginAbsent.Clone() - $testTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_SqlLoginAbsent_EnsurePresent ) | Should -Be $false @@ -391,7 +393,7 @@ try It 'Should return $true when the specified Windows user is Present' { $testTargetResource_WindowsUserPresent_EnsurePresent = $testTargetResource_WindowsUserPresent.Clone() - $testTargetResource_WindowsUserPresent_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_WindowsUserPresent_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_WindowsUserPresent_EnsurePresent ) | Should -Be $true @@ -400,7 +402,7 @@ try It 'Should return $true when the specified Windows group is Present' { $testTargetResource_WindowsGroupPresent_EnsurePresent = $testTargetResource_WindowsGroupPresent.Clone() - $testTargetResource_WindowsGroupPresent_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_WindowsGroupPresent_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_WindowsGroupPresent_EnsurePresent ) | Should -Be $true @@ -409,7 +411,7 @@ try It 'Should return $true when the specified SQL Login is Present using default parameter values' { $testTargetResource_SqlLoginPresentWithDefaultValues_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithDefaultValues_EnsurePresent.Add( 'Ensure','Present' ) + $testTargetResource_SqlLoginPresentWithDefaultValues_EnsurePresent.Add( 'Ensure', 'Present' ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithDefaultValues_EnsurePresent ) | Should -Be $true @@ -418,8 +420,8 @@ try It 'Should return $true when the specified SQL Login is Present and PasswordExpirationEnabled is $true' { $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent.Add( 'LoginPasswordExpirationEnabled',$true ) + $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent.Add( 'LoginPasswordExpirationEnabled', $true ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledTrue_EnsurePresent ) | Should -Be $true @@ -428,8 +430,8 @@ try It 'Should return $false when the specified SQL Login is Present and PasswordExpirationEnabled is $false' { $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent.Add( 'LoginPasswordExpirationEnabled',$false ) + $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent.Add( 'LoginPasswordExpirationEnabled', $false ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithPasswordExpirationEnabledFalse_EnsurePresent ) | Should -Be $false @@ -438,8 +440,8 @@ try It 'Should return $true when the specified SQL Login is Present and PasswordPolicyEnforced is $true' { $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent.Add( 'LoginPasswordPolicyEnforced',$true ) + $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent.Add( 'LoginPasswordPolicyEnforced', $true ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedTrue_EnsurePresent ) | Should -Be $true @@ -448,8 +450,8 @@ try It 'Should return $false when the specified SQL Login is Present and PasswordPolicyEnforced is $false' { $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent.Add( 'LoginPasswordPolicyEnforced',$false ) + $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent.Add( 'LoginPasswordPolicyEnforced', $false ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithPasswordPolicyEnforcedFalse_EnsurePresent ) | Should -Be $false @@ -458,8 +460,8 @@ try It 'Should return $true when the specified SQL Login is Present using default parameter values and the password is properly configured.' { $testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredential ) + $testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredential ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithDefaultValuesGoodPw_EnsurePresent ) | Should -Be $true @@ -470,8 +472,8 @@ try Mock -CommandName Connect-SQL -MockWith { throw } -Verifiable -ParameterFilter { $SetupCredential } $testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent = $testTargetResource_SqlLoginPresentWithDefaultValues.Clone() - $testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent.Add( 'Ensure','Present' ) - $testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredentialBadPassword ) + $testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent.Add( 'Ensure', 'Present' ) + $testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredentialBadPassword ) ( Test-TargetResource @testTargetResource_SqlLoginPresentWithDefaultValuesBadPw_EnsurePresent ) | Should -Be $false @@ -480,8 +482,8 @@ try It 'Should be return $true when a login is enabled' { $mockTestTargetResourceParameters = $instanceParameters.Clone() - $mockTestTargetResourceParameters.Add( 'Ensure','Present' ) - $mockTestTargetResourceParameters.Add( 'Name','Windows\User1' ) + $mockTestTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockTestTargetResourceParameters.Add( 'Name', 'Windows\User1' ) $mockTestTargetResourceParameters.Add( 'Disabled', $false ) $result = Test-TargetResource @mockTestTargetResourceParameters @@ -492,8 +494,8 @@ try It 'Should be return $true when a login is disabled' { $mockTestTargetResourceParameters = $instanceParameters.Clone() - $mockTestTargetResourceParameters.Add( 'Ensure','Present' ) - $mockTestTargetResourceParameters.Add( 'Name','Windows\UserDisabled' ) + $mockTestTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockTestTargetResourceParameters.Add( 'Name', 'Windows\UserDisabled' ) $mockTestTargetResourceParameters.Add( 'Disabled', $true ) $result = Test-TargetResource @mockTestTargetResourceParameters @@ -504,7 +506,7 @@ try } } - Describe 'MSFT_xSQLServerLogin\Set-TargetResource' { + Describe 'MSFT_SqlServerLogin\Set-TargetResource' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName Mock -CommandName Update-SQLServerLogin -MockWith {} -ModuleName $script:DSCResourceName Mock -CommandName New-SQLServerLogin -MockWith {} -ModuleName $script:DSCResourceName @@ -521,7 +523,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsUserPresent_EnsureAbsent = $setTargetResource_WindowsUserPresent.Clone() - $setTargetResource_WindowsUserPresent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_WindowsUserPresent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_WindowsUserPresent_EnsureAbsent @@ -536,8 +538,8 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $mockSetTargetResourceParameters = $instanceParameters.Clone() - $mockSetTargetResourceParameters.Add( 'Ensure','Present' ) - $mockSetTargetResourceParameters.Add( 'Name','Windows\UserDisabled' ) + $mockSetTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockSetTargetResourceParameters.Add( 'Name', 'Windows\UserDisabled' ) $mockSetTargetResourceParameters.Add( 'Disabled', $false ) Set-TargetResource @mockSetTargetResourceParameters @@ -555,8 +557,8 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $mockSetTargetResourceParameters = $instanceParameters.Clone() - $mockSetTargetResourceParameters.Add( 'Ensure','Present' ) - $mockSetTargetResourceParameters.Add( 'Name','Windows\User1' ) + $mockSetTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockSetTargetResourceParameters.Add( 'Name', 'Windows\User1' ) $mockSetTargetResourceParameters.Add( 'Disabled', $true ) Set-TargetResource @mockSetTargetResourceParameters @@ -574,7 +576,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsGroupPresent_EnsureAbsent = $setTargetResource_WindowsGroupPresent.Clone() - $setTargetResource_WindowsGroupPresent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_WindowsGroupPresent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_WindowsGroupPresent_EnsureAbsent @@ -589,7 +591,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginPresent_EnsureAbsent = $setTargetResource_SqlLoginPresent.Clone() - $setTargetResource_SqlLoginPresent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_SqlLoginPresent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_SqlLoginPresent_EnsureAbsent @@ -604,7 +606,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsUserAbsent_EnsureAbsent = $setTargetResource_WindowsUserAbsent.Clone() - $setTargetResource_WindowsUserAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_WindowsUserAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_WindowsUserAbsent_EnsureAbsent @@ -619,7 +621,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsGroupAbsent_EnsureAbsent = $setTargetResource_WindowsGroupAbsent.Clone() - $setTargetResource_WindowsGroupAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_WindowsGroupAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_WindowsGroupAbsent_EnsureAbsent @@ -634,7 +636,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginAbsent_EnsureAbsent = $setTargetResource_SqlLoginAbsent.Clone() - $setTargetResource_SqlLoginAbsent_EnsureAbsent.Add( 'Ensure','Absent' ) + $setTargetResource_SqlLoginAbsent_EnsureAbsent.Add( 'Ensure', 'Absent' ) Set-TargetResource @setTargetResource_SqlLoginAbsent_EnsureAbsent @@ -656,7 +658,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsUserAbsent_EnsurePresent = $setTargetResource_WindowsUserAbsent.Clone() - $setTargetResource_WindowsUserAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $setTargetResource_WindowsUserAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) Set-TargetResource @setTargetResource_WindowsUserAbsent_EnsurePresent @@ -686,8 +688,8 @@ try }-Verifiable $mockSetTargetResourceParameters = $instanceParameters.Clone() - $mockSetTargetResourceParameters.Add( 'Ensure','Present' ) - $mockSetTargetResourceParameters.Add( 'Name','Windows\UserAbsent' ) + $mockSetTargetResourceParameters.Add( 'Ensure', 'Present' ) + $mockSetTargetResourceParameters.Add( 'Name', 'Windows\UserAbsent' ) $mockSetTargetResourceParameters.Add( 'Disabled', $true ) Set-TargetResource @mockSetTargetResourceParameters @@ -704,7 +706,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsGroupAbsent_EnsurePresent = $setTargetResource_WindowsGroupAbsent.Clone() - $setTargetResource_WindowsGroupAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $setTargetResource_WindowsGroupAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) Set-TargetResource @setTargetResource_WindowsGroupAbsent_EnsurePresent @@ -719,8 +721,8 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginAbsent_EnsurePresent = $setTargetResource_SqlLoginAbsent.Clone() - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredential ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredential ) Set-TargetResource @setTargetResource_SqlLoginAbsent_EnsurePresent @@ -735,9 +737,9 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginAbsent_EnsurePresent = $setTargetResource_SqlLoginAbsent.Clone() - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredential ) - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginMustChangePassword',$false ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredential ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginMustChangePassword', $false ) Set-TargetResource @setTargetResource_SqlLoginAbsent_EnsurePresent @@ -752,7 +754,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_CertificateAbsent_EnsurePresent = $setTargetResource_CertificateAbsent.Clone() - $setTargetResource_CertificateAbsent_EnsurePresent.Add( 'Ensure','Present' ) + $setTargetResource_CertificateAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) { Set-TargetResource @setTargetResource_CertificateAbsent_EnsurePresent } | Should -Throw 'LoginTypeNotImplemented' @@ -767,7 +769,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginAbsent_EnsurePresent_NoCred = $setTargetResource_SqlLoginAbsent.Clone() - $setTargetResource_SqlLoginAbsent_EnsurePresent_NoCred.Add( 'Ensure','Present' ) + $setTargetResource_SqlLoginAbsent_EnsurePresent_NoCred.Add( 'Ensure', 'Present' ) { Set-TargetResource @setTargetResource_SqlLoginAbsent_EnsurePresent_NoCred } | Should -Throw 'LoginCredentialNotFound' @@ -782,7 +784,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsUserPresent_EnsurePresent = $setTargetResource_WindowsUserPresent.Clone() - $setTargetResource_WindowsUserPresent_EnsurePresent.Add( 'Ensure','Present' ) + $setTargetResource_WindowsUserPresent_EnsurePresent.Add( 'Ensure', 'Present' ) Set-TargetResource @setTargetResource_WindowsUserPresent_EnsurePresent @@ -797,7 +799,7 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_WindowsGroupPresent_EnsurePresent = $setTargetResource_WindowsGroupPresent.Clone() - $setTargetResource_WindowsGroupPresent_EnsurePresent.Add( 'Ensure','Present' ) + $setTargetResource_WindowsGroupPresent_EnsurePresent.Add( 'Ensure', 'Present' ) Set-TargetResource @setTargetResource_WindowsGroupPresent_EnsurePresent @@ -812,8 +814,8 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginPresent_EnsurePresent = $setTargetResource_SqlLoginPresent.Clone() - $setTargetResource_SqlLoginPresent_EnsurePresent.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginPresent_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredential ) + $setTargetResource_SqlLoginPresent_EnsurePresent.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginPresent_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredential ) Set-TargetResource @setTargetResource_SqlLoginPresent_EnsurePresent @@ -828,9 +830,9 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled = $setTargetResource_SqlLoginPresent.Clone() - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'LoginCredential',$mockSqlLoginCredential ) - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'LoginPasswordExpirationEnabled',$false ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'LoginCredential', $mockSqlLoginCredential ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled.Add( 'LoginPasswordExpirationEnabled', $false ) Set-TargetResource @setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordExpirationEnabled @@ -845,9 +847,9 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced = $setTargetResource_SqlLoginPresent.Clone() - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'LoginCredential',$mockSqlLoginCredential ) - $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'LoginPasswordPolicyEnforced',$false ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'LoginCredential', $mockSqlLoginCredential ) + $setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced.Add( 'LoginPasswordPolicyEnforced', $false ) Set-TargetResource @setTargetResource_SqlLoginPresent_EnsurePresent_LoginPasswordPolicyEnforced @@ -862,14 +864,14 @@ try $mockConnectSQL_LoginModeNormal = { return New-Object Object | Add-Member ScriptProperty Logins { - return @{ - 'Windows\User1' = ( New-Object Object | + return @{ + 'Windows\User1' = ( New-Object Object | Add-Member -MemberType NoteProperty -Name 'Name' -Value 'Windows\User1' -PassThru | Add-Member -MemberType NoteProperty -Name 'LoginType' -Value 'WindowsUser' -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value {} -PassThru | Add-Member -MemberType ScriptMethod -Name Drop -Value {} -PassThru -Force - ) - 'SqlLogin1' = ( New-Object Object | + ) + 'SqlLogin1' = ( New-Object Object | Add-Member -MemberType NoteProperty -Name 'Name' -Value 'SqlLogin1' -PassThru | Add-Member -MemberType NoteProperty -Name 'LoginType' -Value 'SqlLogin' -PassThru | Add-Member -MemberType NoteProperty -Name 'MustChangePassword' -Value $false -PassThru | @@ -877,23 +879,23 @@ try Add-Member -MemberType NoteProperty -Name 'PasswordPolicyEnforced' -Value $true -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value {} -PassThru | Add-Member -MemberType ScriptMethod -Name Drop -Value {} -PassThru -Force - ) - 'Windows\Group1' = ( New-Object Object | + ) + 'Windows\Group1' = ( New-Object Object | Add-Member -MemberType NoteProperty -Name 'Name' -Value 'Windows\Group1' -PassThru | Add-Member -MemberType NoteProperty -Name 'LoginType' -Value 'WindowsGroup' -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value {} -PassThru | Add-Member -MemberType ScriptMethod -Name Drop -Value {} -PassThru -Force - ) - } - } -PassThru | + ) + } + } -PassThru | Add-Member -MemberType NoteProperty -Name LoginMode -Value 'Normal' -PassThru -Force } Mock -CommandName Connect-SQL -MockWith $mockConnectSQL_LoginModeNormal -Verifiable $setTargetResource_SqlLoginAbsent_EnsurePresent = $setTargetResource_SqlLoginAbsent.Clone() - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure','Present' ) - $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential',$mockSqlLoginCredential ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'Ensure', 'Present' ) + $setTargetResource_SqlLoginAbsent_EnsurePresent.Add( 'LoginCredential', $mockSqlLoginCredential ) { Set-TargetResource @setTargetResource_SqlLoginAbsent_EnsurePresent } | Should -Throw 'IncorrectLoginMode' @@ -906,7 +908,7 @@ try } } - Describe 'MSFT_xSQLServerLogin\Update-SQLServerLogin' { + Describe 'MSFT_SqlServerLogin\Update-SQLServerLogin' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName Context 'When the Login is altered' { @@ -927,7 +929,7 @@ try } } - Describe 'MSFT_xSQLServerLogin\New-SQLServerLogin' { + Describe 'MSFT_SqlServerLogin\New-SQLServerLogin' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName Context 'When the Login is created' { @@ -1002,7 +1004,7 @@ try } } - Describe 'MSFT_xSQLServerLogin\Remove-SQLServerLogin' { + Describe 'MSFT_SqlServerLogin\Remove-SQLServerLogin' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName Context 'When the Login is dropped' { @@ -1023,7 +1025,7 @@ try } } - Describe 'MSFT_xSQLServerLogin\Set-SQLServerLoginPassword' { + Describe 'MSFT_SqlServerLogin\Set-SQLServerLoginPassword' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName Context 'When the password is set on an existing login' { diff --git a/Tests/Unit/MSFT_xSQLServerMaxDop.Tests.ps1 b/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 similarity index 81% rename from Tests/Unit/MSFT_xSQLServerMaxDop.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 index ca3092649..2f3400355 100644 --- a/Tests/Unit/MSFT_xSQLServerMaxDop.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerMaxDop.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerMaxDop' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerMaxDop' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -23,10 +23,12 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -36,19 +38,19 @@ try Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockSQLServerName = 'localhost' - $mockSQLServerInstanceName = 'MSSQLSERVER' - $mockMaxDegreeOfParallelism = 4 - $mockExpectedMaxDopForAlterMethod = 1 + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockMaxDegreeOfParallelism = 4 + $mockExpectedMaxDopForAlterMethod = 1 $mockInvalidOperationForAlterMethod = $false - $mockNumberOfLogicalProcessors = 4 - $mockNumberOfCores = 4 - $mockProcessOnlyOnActiveNode = $true + $mockNumberOfLogicalProcessors = 4 + $mockNumberOfCores = 4 + $mockProcessOnlyOnActiveNode = $true # Default parameters that are used for the It-blocks $mockDefaultParameters = @{ - SQLInstanceName = $mockSQLServerInstanceName - SQLServer = $mockSQLServerName + InstanceName = $mockInstanceName + ServerName = $mockServerName } #region Function mocks @@ -57,31 +59,31 @@ try return @( ( New-Object Object -TypeName Microsoft.SqlServer.Management.Smo.Server | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSQLServerInstanceName -PassThru -Force | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSQLServerName -PassThru -Force | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru -Force | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru -Force | Add-Member -MemberType ScriptProperty -Name Configuration -Value { - return @( ( New-Object Object | - Add-Member -MemberType ScriptProperty -Name MaxDegreeOfParallelism -Value { + return @( ( New-Object Object | + Add-Member -MemberType ScriptProperty -Name MaxDegreeOfParallelism -Value { return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name DisplayName -Value 'max degree of parallelism' -PassThru | - Add-Member -MemberType NoteProperty -Name Description -Value 'maximum degree of parallelism' -PassThru | - Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMaxDegreeOfParallelism -PassThru | - Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMaxDegreeOfParallelism -PassThru -Force - ) ) + Add-Member -MemberType NoteProperty -Name DisplayName -Value 'max degree of parallelism' -PassThru | + Add-Member -MemberType NoteProperty -Name Description -Value 'maximum degree of parallelism' -PassThru | + Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMaxDegreeOfParallelism -PassThru | + Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMaxDegreeOfParallelism -PassThru -Force + ) ) } -PassThru -Force ) ) - } -PassThru | + } -PassThru | Add-Member -MemberType ScriptMethod -Name Alter -Value { - if ( $this.Configuration.MaxDegreeOfParallelism.ConfigValue -ne $mockExpectedMaxDopForAlterMethod ) - { - throw "Called mocked Alter() method without setting the right MaxDegreeOfParallelism. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedMaxDopForAlterMethod, $this.Configuration.MaxDegreeOfParallelism.ConfigValue - } - if ($mockInvalidOperationForAlterMethod) - { - throw 'Mock Alter Method was called with invalid operation.' - } - } -PassThru -Force + if ( $this.Configuration.MaxDegreeOfParallelism.ConfigValue -ne $mockExpectedMaxDopForAlterMethod ) + { + throw "Called mocked Alter() method without setting the right MaxDegreeOfParallelism. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedMaxDopForAlterMethod, $this.Configuration.MaxDegreeOfParallelism.ConfigValue + } + if ($mockInvalidOperationForAlterMethod) + { + throw 'Mock Alter Method was called with invalid operation.' + } + } -PassThru -Force ) ) } @@ -98,7 +100,7 @@ try #endregion - Describe "MSFT_xSQLServerMaxDop\Get-TargetResource" -Tag 'Get'{ + Describe "MSFT_SqlServerMaxDop\Get-TargetResource" -Tag 'Get' { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable Mock -CommandName Test-ActiveNode -MockWith { return $mockProcessOnlyOnActiveNode } -Verifiable @@ -112,8 +114,8 @@ try } It 'Should return the same values as passed as parameters' { - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName } It 'Should call the mock function Connect-SQL' { @@ -128,7 +130,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerMaxDop\Test-TargetResource" -Tag 'Test'{ + Describe "MSFT_SqlServerMaxDop\Test-TargetResource" -Tag 'Test' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable @@ -148,9 +150,9 @@ try Context 'When the system is not in the desired state and DynamicAlloc is set to false' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 1 - DynamicAlloc = $false - Ensure = 'Present' + MaxDop = 1 + DynamicAlloc = $false + Ensure = 'Present' } It 'Should return the state as false when desired MaxDop is the wrong value' { @@ -172,8 +174,8 @@ try Context 'When the system is in the desired state and DynamicAlloc is set to false' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 6 - DynamicAlloc = $false + MaxDop = 6 + DynamicAlloc = $false } It 'Should return the state as true when desired MaxDop is the correct value' { @@ -311,7 +313,7 @@ try BeforeAll { $testParameters = $mockDefaultParameters $testParameters += @{ - Ensure = 'Absent' + Ensure = 'Absent' ProcessOnlyOnActiveNode = $true } @@ -349,8 +351,8 @@ try Context 'When the MaxDop parameter is not null and DynamicAlloc set to true' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 4 - DynamicAlloc = $true + MaxDop = 4 + DynamicAlloc = $true } It 'Should throw the correct error' { @@ -363,9 +365,9 @@ try } # This is regression test for issue #576 - Context 'When the system is in the desired state and SQLServer is not set' { + Context 'When the system is in the desired state and ServerName is not set' { $testParameters = $mockDefaultParameters - $testParameters.Remove('SQLServer') + $testParameters.Remove('ServerName') $testParameters += @{ Ensure = 'Absent' } @@ -378,7 +380,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerMaxDop\Set-TargetResource" -Tag 'Set'{ + Describe "MSFT_SqlServerMaxDop\Set-TargetResource" -Tag 'Set' { BeforeEach { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable @@ -394,9 +396,9 @@ try Context 'When the MaxDop parameter is not null and DynamicAlloc set to true' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 4 - DynamicAlloc = $true - Ensure = 'Present' + MaxDop = 4 + DynamicAlloc = $true + Ensure = 'Present' } It 'Should throw the correct error' { @@ -432,9 +434,9 @@ try Context 'When the desired MaxDop parameter is not set' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 1 - DynamicAlloc = $false - Ensure = 'Present' + MaxDop = 1 + DynamicAlloc = $false + Ensure = 'Present' } It 'Should Not Throw when MaxDop parameter is not null and DynamicAlloc set to false' { @@ -454,8 +456,8 @@ try Context 'When the system is not in the desired state and DynamicAlloc is set to true' { $testParameters = $mockDefaultParameters $testParameters += @{ - DynamicAlloc = $true - Ensure = 'Present' + DynamicAlloc = $true + Ensure = 'Present' } It 'Should Not Throw when MaxDop parameter is not null and DynamicAlloc set to false' { @@ -478,15 +480,15 @@ try Context 'When the desired MaxDop parameter is not set' { $testParameters = $mockDefaultParameters $testParameters += @{ - MaxDop = 1 - DynamicAlloc = $false - Ensure = 'Present' + MaxDop = 1 + DynamicAlloc = $false + Ensure = 'Present' } It 'Shoud throw the correct error when Alter() method was called with invalid operation' { $throwInvalidOperation = ('Unexpected result when trying to configure the max degree of parallelism ' + ` - 'server configuration option. InnerException: Exception calling "Alter" ' + ` - 'with "0" argument(s): "Mock Alter Method was called with invalid operation."') + 'server configuration option. InnerException: Exception calling "Alter" ' + ` + 'with "0" argument(s): "Mock Alter Method was called with invalid operation."') { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation } diff --git a/Tests/Unit/MSFT_xSQLServerMemory.Tests.ps1 b/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 similarity index 80% rename from Tests/Unit/MSFT_xSQLServerMemory.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 index e54c72156..af7b878df 100644 --- a/Tests/Unit/MSFT_xSQLServerMemory.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerMemory.Tests.ps1 @@ -1,778 +1,780 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerMemory' - -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force - -# Loading mocked classes -Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { -} - -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -# Begin Testing -try -{ - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { - $mockSQLServerName = 'localhost' - $mockSQLServerInstanceName = 'MSSQLSERVER' - $mockMinServerMemory = 2048 - $mockMaxServerMemory = 10300 - $mockPhysicalMemoryCapacity = 8589934592 - $mockExpectedMinMemoryForAlterMethod = 0 - $mockExpectedMaxMemoryForAlterMethod = 2147483647 - $mockTestActiveNode = $true - - # Default parameters that are used for the It-blocks - $mockDefaultParameters = @{ - SQLInstanceName = $mockSQLServerInstanceName - SQLServer = $mockSQLServerName - } - - #region Function mocks - - $mockConnectSQL = { - return @( - ( - # New-Object Object | - New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSQLServerInstanceName -PassThru -Force | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSQLServerName -PassThru -Force | - Add-Member -MemberType ScriptProperty -Name Configuration -Value { - return @( ( New-Object Object | - Add-Member -MemberType ScriptProperty -Name MinServerMemory -Value { - return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name DisplayName -Value 'min server memory (MB)' -PassThru | - Add-Member -MemberType NoteProperty -Name Description -Value 'Minimum size of server memory (MB)' -PassThru | - Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMinServerMemory -PassThru | - Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMinServerMemory -PassThru -Force - ) ) - } -PassThru | - Add-Member -MemberType ScriptProperty -Name MaxServerMemory -Value { - return @( ( New-Object Object | - Add-Member -MemberType NoteProperty -Name DisplayName -Value 'max server memory (MB)' -PassThru | - Add-Member -MemberType NoteProperty -Name Description -Value 'Maximum size of server memory (MB)' -PassThru | - Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMaxServerMemory -PassThru | - Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMaxServerMemory -PassThru -Force - ) ) - } -PassThru -Force - ) ) - } -PassThru -Force | - Add-Member -MemberType ScriptMethod -Name Alter -Value { - if ( $this.Configuration.MinServerMemory.ConfigValue -ne $mockExpectedMinMemoryForAlterMethod ) - { - throw "Called mocked Alter() method without setting the right minimum server memory. Expected '{0}'. But was '{1}'." -f $mockExpectedMinMemoryForAlterMethod, $this.Configuration.MinServerMemory.ConfigValue - } - if ( $this.Configuration.MaxServerMemory.ConfigValue -ne $mockExpectedMaxMemoryForAlterMethod ) - { - throw "Called mocked Alter() method without setting the right maximum server memory. Expected '{0}'. But was '{1}'." -f $mockExpectedMaxMemoryForAlterMethod, $this.Configuration.MaxServerMemory.ConfigValue - } - } -PassThru -Force - ) - ) - } - - #endregion - - Describe "MSFT_xSQLServerMemory\Get-TargetResource" -Tag 'Get'{ - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - Mock -CommandName Test-ActiveNode -MockWith { return $mockTestActiveNode } -Verifiable - - Context 'When the system is either in the desired state or not in the desired state' { - $testParameters = $mockDefaultParameters - - $result = Get-TargetResource @testParameters - - It 'Should return the current value for MinMemory' { - $result.MinMemory | Should -Be 2048 - } - - It 'Should return the current value for MaxMemory' { - $result.MaxMemory | Should -Be 10300 - } - - It 'Should return the same values as passed as parameters' { - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Test-ActiveNode' { - Assert-MockCalled Test-ActiveNode -Exactly -Times 1 -Scope Context - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerMemory\Test-TargetResource" -Tag 'Test'{ - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - throw 'Mocked function Get-CimInstance was called with the wrong set of parameter filters.' - } - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceMem = @() - - $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ - Name = 'Physical Memory' - Tag = 'Physical Memory 0' - Capacity = 8589934592 - } - - $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ - Name = 'Physical Memory' - Tag = 'Physical Memory 1' - Capacity = 8589934592 - } - - $mockGetCimInstanceMem - } -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceProc = [PSCustomObject]@{ - NumberOfCores = 2 - } - - $mockGetCimInstanceProc - } -ParameterFilter { $ClassName -eq 'Win32_Processor' } -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceOS = [PSCustomObject]@{ - OSArchitecture = '64-bit' - } - - $mockGetCimInstanceOS - } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable - - Mock -CommandName Test-ActiveNode -MockWith { return $mockTestActiveNode } -Verifiable - - Context 'When the system is not in the desired state and DynamicAlloc is set to false' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - MinMemory = 1024 - MaxMemory = 8192 - DynamicAlloc = $false - } - - It 'Should return the state as false when desired MinMemory and MaxMemory are not present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $false - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system is not in the desired state and DynamicAlloc is set to false' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - MaxMemory = 8192 - DynamicAlloc = $false - } - - It 'Should return the state as false when desired MaxMemory is not present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $false - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system is in the desired state and DynamicAlloc is set to false' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - MinMemory = 0 - MaxMemory = 10300 - DynamicAlloc = $false - } - - It 'Should return the state as true when desired MinMemory and MaxMemory are present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $true - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the MaxMemory parameter is not null and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - MaxMemory = 8192 - DynamicAlloc = $true - Ensure = 'Present' - } - - It 'Should throw the correct error' { - { Test-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must be null when DynamicAlloc is set to true.' - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the MaxMemory parameter is null and DynamicAlloc is set to false' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - DynamicAlloc = $false - Ensure = 'Present' - } - - It 'Should throw the correct error' { - {Test-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must not be null when DynamicAlloc is set to false.' - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system is not in the desired state and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - DynamicAlloc = $true - } - - It 'Should return the state as false when desired MinMemory and MaxMemory are not present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $false - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - Context 'When the system is not in the desired state, DynamicAlloc is set to true and ProcessOnlyOnActiveNode is set to true' { - AfterAll { - $mockTestActiveNode = $true - } - - BeforeAll { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - DynamicAlloc = $true - ProcessOnlyOnActiveNode = $true - } - - $mockTestActiveNode = $false - } - - It 'Should return the state as true' { - $result = Test-TargetResource @testParameters - $result | Should -Be $true - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - $mockMinServerMemory = 0 - $mockMaxServerMemory = 12083 - - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - Context 'When the system is in the desired state and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - DynamicAlloc = $true - } - - It 'Should return the state as true when desired MinMemory and MaxMemory are present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $true - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - $mockMinServerMemory = 1024 - $mockMaxServerMemory = 8192 - - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - Context 'When the system is not in the desired state and Ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - } - - It 'Should return the state as false when desired MinMemory and MaxMemory are not set to the default values' { - $result = Test-TargetResource @testParameters - $result | Should -Be $false - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - $mockMinServerMemory = 0 - $mockMaxServerMemory = 2147483647 - - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - Context 'When the system is in the desired state and Ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - } - - It 'Should return the state as true when desired MinMemory and MaxMemory are present' { - $result = Test-TargetResource @testParameters - $result | Should -Be $true - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - # This is regression test for issue #576 - Context 'When the system is in the desired state and SQLServer is not set' { - $testParameters = $mockDefaultParameters - $testParameters.Remove('SQLServer') - $testParameters += @{ - Ensure = 'Absent' - } - - It 'Should not throw an error' { - { Test-TargetResource @testParameters } | Should -Not -Throw - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerMemory\Set-TargetResource" -Tag 'Set' { - $mockMinServerMemory = 0 - $mockMaxServerMemory = 2147483647 - - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - throw 'Mocked function Get-CimInstance was called with the wrong set of parameter filters.' - } - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceMem = @() - - $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ - Name = 'Physical Memory' - Tag = 'Physical Memory 0' - Capacity = 17179869184 - } - - $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ - Name = 'Physical Memory' - Tag = 'Physical Memory 1' - Capacity = 17179869184 - } - - $mockGetCimInstanceMem - } -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceProc = [PSCustomObject]@{ - NumberOfCores = 6 - } - - $mockGetCimInstanceProc - } -ParameterFilter { $ClassName -eq 'Win32_Processor' } -Verifiable - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceOS = [PSCustomObject]@{ - OSArchitecture = 'IA64-bit' - } - - $mockGetCimInstanceOS - } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable - - Context 'When the MaxMemory parameter is not null and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - MaxMemory = 8192 - DynamicAlloc = $true - Ensure = 'Present' - } - - It 'Should throw the correct error' { - { Set-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must be null when DynamicAlloc is set to true.' - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the MaxMemory parameter is null and DynamicAlloc is set to false' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - DynamicAlloc = $false - Ensure = 'Present' - } - - It 'Should throw the correct error' { - { Set-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must not be null when DynamicAlloc is set to false.' - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system is not in the desired state and Ensure is set to Absent' { - $mockExpectedMinMemoryForAlterMethod = 0 - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - } - - It 'Should set the MinMemory and MaxMemory to the default values' { - { Set-TargetResource @testParameters } | Should -Not -Throw - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to false' { - $mockMinServerMemory = 1024 - $mockMaxServerMemory = 8192 - - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - - $mockExpectedMinMemoryForAlterMethod = 1024 - $mockExpectedMaxMemoryForAlterMethod = 8192 - $testParameters = $mockDefaultParameters - $testParameters += @{ - MaxMemory = 8192 - MinMemory = 1024 - DynamicAlloc = $false - Ensure = 'Present' - } - - It 'Should set the MinMemory and MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to false' { - { Set-TargetResource @testParameters } | Should -Not -Throw - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Context 'When the system (OS IA64-bit) is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - DynamicAlloc = $true - Ensure = 'Present' - MinMemory = 2048 - } - - It 'Should set the MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to true' { - { Set-TargetResource @testParameters } | Should -Not -Throw - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - Mock -CommandName Get-CimInstance -MockWith { - $mockGetCimInstanceOS = [PSCustomObject]@{ - OSArchitecture = '32-bit' - } - - $mockGetCimInstanceOS - } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable - - Context 'When the system (OS 32-bit) is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to true' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - DynamicAlloc = $true - Ensure = 'Present' - } - - It 'Should set the MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to true' { - { Set-TargetResource @testParameters } | Should -Not -Throw - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - Mock -CommandName Connect-SQL -MockWith { - $mockSqlServerObject = [PSCustomObject]@{ - InstanceName = $mockSQLServerInstanceName - ComputerNamePhysicalNetBIOS = $mockSQLServerName - Configuration = @{ - MinServerMemory = @{ - DisplayName = 'min server memory (MB)' - Description = 'Minimum size of server memory (MB)' - RunValue = 0 - ConfigValue = 0 - } - MaxServerMemory = @{ - DisplayName = 'max server memory (MB)' - Description = 'Maximum size of server memory (MB)' - RunValue = 10300 - ConfigValue = 10300 - } - } - } - - # Add the Alter method - $mockSqlServerObject | Add-Member -MemberType ScriptMethod -Name Alter -Value { - throw 'Mock Alter Method was called with invalid operation.' - } - - $mockSqlServerObject - } -Verifiable - - Context 'When the desired MinMemory and MaxMemory fails to be set' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - MaxMemory = 8192 - MinMemory = 1024 - DynamicAlloc = $false - Ensure = 'Present' - } - - It 'Should throw the correct error' { - { Set-TargetResource @testParameters } | Should -Throw ("Failed to alter the server configuration memory for $($env:COMPUTERNAME)" + "\" +` - "$mockSQLServerInstanceName. InnerException: Exception calling ""Alter"" with ""0"" argument(s): " + ` - """Mock Alter Method was called with invalid operation.""") - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should not call the mock function Get-CimInstance' { - Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context - } - } - - Mock -CommandName Get-CimInstance -MockWith { - throw - } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable - - Context 'When the Get-SqlDscDynamicMaxMemory fails to calculate the MaxMemory' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - DynamicAlloc = $true - Ensure = 'Present' - } - - It 'Should throw the correct error' { - { Set-TargetResource @testParameters } | Should -Throw 'Failed to calculate dynamically the maximum memory.' - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_PhysicalMemory' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_Processor' - } -Scope Context - } - - It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { - Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { - $ClassName -eq 'Win32_operatingsystem' - } -Scope Context - } - } - - Assert-VerifiableMock - } - } -} -finally -{ - Invoke-TestCleanup -} +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerMemory' + +#region HEADER + +# Unit Test Template Version: 1.2.0 +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +# Loading mocked classes +Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +function Invoke-TestSetup +{ +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} + +# Begin Testing +try +{ + Invoke-TestSetup + + InModuleScope $script:DSCResourceName { + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockMinServerMemory = 2048 + $mockMaxServerMemory = 10300 + $mockPhysicalMemoryCapacity = 8589934592 + $mockExpectedMinMemoryForAlterMethod = 0 + $mockExpectedMaxMemoryForAlterMethod = 2147483647 + $mockTestActiveNode = $true + + # Default parameters that are used for the It-blocks + $mockDefaultParameters = @{ + InstanceName = $mockInstanceName + ServerName = $mockServerName + } + + #region Function mocks + + $mockConnectSQL = { + return @( + ( + # New-Object Object | + New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru -Force | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru -Force | + Add-Member -MemberType ScriptProperty -Name Configuration -Value { + return @( ( New-Object Object | + Add-Member -MemberType ScriptProperty -Name MinServerMemory -Value { + return @( ( New-Object Object | + Add-Member -MemberType NoteProperty -Name DisplayName -Value 'min server memory (MB)' -PassThru | + Add-Member -MemberType NoteProperty -Name Description -Value 'Minimum size of server memory (MB)' -PassThru | + Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMinServerMemory -PassThru | + Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMinServerMemory -PassThru -Force + ) ) + } -PassThru | + Add-Member -MemberType ScriptProperty -Name MaxServerMemory -Value { + return @( ( New-Object Object | + Add-Member -MemberType NoteProperty -Name DisplayName -Value 'max server memory (MB)' -PassThru | + Add-Member -MemberType NoteProperty -Name Description -Value 'Maximum size of server memory (MB)' -PassThru | + Add-Member -MemberType NoteProperty -Name RunValue -Value $mockMaxServerMemory -PassThru | + Add-Member -MemberType NoteProperty -Name ConfigValue -Value $mockMaxServerMemory -PassThru -Force + ) ) + } -PassThru -Force + ) ) + } -PassThru -Force | + Add-Member -MemberType ScriptMethod -Name Alter -Value { + if ( $this.Configuration.MinServerMemory.ConfigValue -ne $mockExpectedMinMemoryForAlterMethod ) + { + throw "Called mocked Alter() method without setting the right minimum server memory. Expected '{0}'. But was '{1}'." -f $mockExpectedMinMemoryForAlterMethod, $this.Configuration.MinServerMemory.ConfigValue + } + if ( $this.Configuration.MaxServerMemory.ConfigValue -ne $mockExpectedMaxMemoryForAlterMethod ) + { + throw "Called mocked Alter() method without setting the right maximum server memory. Expected '{0}'. But was '{1}'." -f $mockExpectedMaxMemoryForAlterMethod, $this.Configuration.MaxServerMemory.ConfigValue + } + } -PassThru -Force + ) + ) + } + + #endregion + + Describe "MSFT_SqlServerMemory\Get-TargetResource" -Tag 'Get' { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + Mock -CommandName Test-ActiveNode -MockWith { return $mockTestActiveNode } -Verifiable + + Context 'When the system is either in the desired state or not in the desired state' { + $testParameters = $mockDefaultParameters + + $result = Get-TargetResource @testParameters + + It 'Should return the current value for MinMemory' { + $result.MinMemory | Should -Be 2048 + } + + It 'Should return the current value for MaxMemory' { + $result.MaxMemory | Should -Be 10300 + } + + It 'Should return the same values as passed as parameters' { + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Test-ActiveNode' { + Assert-MockCalled Test-ActiveNode -Exactly -Times 1 -Scope Context + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlServerMemory\Test-TargetResource" -Tag 'Test' { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + throw 'Mocked function Get-CimInstance was called with the wrong set of parameter filters.' + } + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceMem = @() + + $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ + Name = 'Physical Memory' + Tag = 'Physical Memory 0' + Capacity = 8589934592 + } + + $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ + Name = 'Physical Memory' + Tag = 'Physical Memory 1' + Capacity = 8589934592 + } + + $mockGetCimInstanceMem + } -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceProc = [PSCustomObject]@{ + NumberOfCores = 2 + } + + $mockGetCimInstanceProc + } -ParameterFilter { $ClassName -eq 'Win32_Processor' } -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceOS = [PSCustomObject]@{ + OSArchitecture = '64-bit' + } + + $mockGetCimInstanceOS + } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable + + Mock -CommandName Test-ActiveNode -MockWith { return $mockTestActiveNode } -Verifiable + + Context 'When the system is not in the desired state and DynamicAlloc is set to false' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + MinMemory = 1024 + MaxMemory = 8192 + DynamicAlloc = $false + } + + It 'Should return the state as false when desired MinMemory and MaxMemory are not present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $false + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system is not in the desired state and DynamicAlloc is set to false' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + MaxMemory = 8192 + DynamicAlloc = $false + } + + It 'Should return the state as false when desired MaxMemory is not present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $false + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system is in the desired state and DynamicAlloc is set to false' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + MinMemory = 0 + MaxMemory = 10300 + DynamicAlloc = $false + } + + It 'Should return the state as true when desired MinMemory and MaxMemory are present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $true + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the MaxMemory parameter is not null and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + MaxMemory = 8192 + DynamicAlloc = $true + Ensure = 'Present' + } + + It 'Should throw the correct error' { + { Test-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must be null when DynamicAlloc is set to true.' + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the MaxMemory parameter is null and DynamicAlloc is set to false' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + DynamicAlloc = $false + Ensure = 'Present' + } + + It 'Should throw the correct error' { + {Test-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must not be null when DynamicAlloc is set to false.' + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system is not in the desired state and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + DynamicAlloc = $true + } + + It 'Should return the state as false when desired MinMemory and MaxMemory are not present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $false + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + Context 'When the system is not in the desired state, DynamicAlloc is set to true and ProcessOnlyOnActiveNode is set to true' { + AfterAll { + $mockTestActiveNode = $true + } + + BeforeAll { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + DynamicAlloc = $true + ProcessOnlyOnActiveNode = $true + } + + $mockTestActiveNode = $false + } + + It 'Should return the state as true' { + $result = Test-TargetResource @testParameters + $result | Should -Be $true + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + $mockMinServerMemory = 0 + $mockMaxServerMemory = 12083 + + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + Context 'When the system is in the desired state and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + DynamicAlloc = $true + } + + It 'Should return the state as true when desired MinMemory and MaxMemory are present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $true + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + $mockMinServerMemory = 1024 + $mockMaxServerMemory = 8192 + + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + Context 'When the system is not in the desired state and Ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + It 'Should return the state as false when desired MinMemory and MaxMemory are not set to the default values' { + $result = Test-TargetResource @testParameters + $result | Should -Be $false + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + $mockMinServerMemory = 0 + $mockMaxServerMemory = 2147483647 + + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + Context 'When the system is in the desired state and Ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + It 'Should return the state as true when desired MinMemory and MaxMemory are present' { + $result = Test-TargetResource @testParameters + $result | Should -Be $true + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + # This is regression test for issue #576 + Context 'When the system is in the desired state and ServerName is not set' { + $testParameters = $mockDefaultParameters + $testParameters.Remove('ServerName') + $testParameters += @{ + Ensure = 'Absent' + } + + It 'Should not throw an error' { + { Test-TargetResource @testParameters } | Should -Not -Throw + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlServerMemory\Set-TargetResource" -Tag 'Set' { + $mockMinServerMemory = 0 + $mockMaxServerMemory = 2147483647 + + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + throw 'Mocked function Get-CimInstance was called with the wrong set of parameter filters.' + } + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceMem = @() + + $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ + Name = 'Physical Memory' + Tag = 'Physical Memory 0' + Capacity = 17179869184 + } + + $mockGetCimInstanceMem += New-Object -TypeName psobject -Property @{ + Name = 'Physical Memory' + Tag = 'Physical Memory 1' + Capacity = 17179869184 + } + + $mockGetCimInstanceMem + } -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceProc = [PSCustomObject]@{ + NumberOfCores = 6 + } + + $mockGetCimInstanceProc + } -ParameterFilter { $ClassName -eq 'Win32_Processor' } -Verifiable + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceOS = [PSCustomObject]@{ + OSArchitecture = 'IA64-bit' + } + + $mockGetCimInstanceOS + } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable + + Context 'When the MaxMemory parameter is not null and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + MaxMemory = 8192 + DynamicAlloc = $true + Ensure = 'Present' + } + + It 'Should throw the correct error' { + { Set-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must be null when DynamicAlloc is set to true.' + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the MaxMemory parameter is null and DynamicAlloc is set to false' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + DynamicAlloc = $false + Ensure = 'Present' + } + + It 'Should throw the correct error' { + { Set-TargetResource @testParameters } | Should -Throw 'The parameter MaxMemory must not be null when DynamicAlloc is set to false.' + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system is not in the desired state and Ensure is set to Absent' { + $mockExpectedMinMemoryForAlterMethod = 0 + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + } + + It 'Should set the MinMemory and MaxMemory to the default values' { + { Set-TargetResource @testParameters } | Should -Not -Throw + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to false' { + $mockMinServerMemory = 1024 + $mockMaxServerMemory = 8192 + + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + + $mockExpectedMinMemoryForAlterMethod = 1024 + $mockExpectedMaxMemoryForAlterMethod = 8192 + $testParameters = $mockDefaultParameters + $testParameters += @{ + MaxMemory = 8192 + MinMemory = 1024 + DynamicAlloc = $false + Ensure = 'Present' + } + + It 'Should set the MinMemory and MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to false' { + { Set-TargetResource @testParameters } | Should -Not -Throw + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Context 'When the system (OS IA64-bit) is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + DynamicAlloc = $true + Ensure = 'Present' + MinMemory = 2048 + } + + It 'Should set the MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to true' { + { Set-TargetResource @testParameters } | Should -Not -Throw + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + Mock -CommandName Get-CimInstance -MockWith { + $mockGetCimInstanceOS = [PSCustomObject]@{ + OSArchitecture = '32-bit' + } + + $mockGetCimInstanceOS + } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable + + Context 'When the system (OS 32-bit) is not in the desired state and Ensure is set to Present, and DynamicAlloc is set to true' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + DynamicAlloc = $true + Ensure = 'Present' + } + + It 'Should set the MaxMemory to the correct values when Ensure parameter is set to Present and DynamicAlloc is set to true' { + { Set-TargetResource @testParameters } | Should -Not -Throw + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + Mock -CommandName Connect-SQL -MockWith { + $mockSqlServerObject = [PSCustomObject]@{ + InstanceName = $mockInstanceName + ComputerNamePhysicalNetBIOS = $mockServerName + Configuration = @{ + MinServerMemory = @{ + DisplayName = 'min server memory (MB)' + Description = 'Minimum size of server memory (MB)' + RunValue = 0 + ConfigValue = 0 + } + MaxServerMemory = @{ + DisplayName = 'max server memory (MB)' + Description = 'Maximum size of server memory (MB)' + RunValue = 10300 + ConfigValue = 10300 + } + } + } + + # Add the Alter method + $mockSqlServerObject | Add-Member -MemberType ScriptMethod -Name Alter -Value { + throw 'Mock Alter Method was called with invalid operation.' + } + + $mockSqlServerObject + } -Verifiable + + Context 'When the desired MinMemory and MaxMemory fails to be set' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + MaxMemory = 8192 + MinMemory = 1024 + DynamicAlloc = $false + Ensure = 'Present' + } + + It 'Should throw the correct error' { + { Set-TargetResource @testParameters } | Should -Throw ("Failed to alter the server configuration memory for $($env:COMPUTERNAME)" + "\" + ` + "$mockInstanceName. InnerException: Exception calling ""Alter"" with ""0"" argument(s): " + ` + """Mock Alter Method was called with invalid operation.""") + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should not call the mock function Get-CimInstance' { + Assert-MockCalled Get-CimInstance -Exactly -Times 0 -Scope Context + } + } + + Mock -CommandName Get-CimInstance -MockWith { + throw + } -ParameterFilter { $ClassName -eq 'Win32_operatingsystem' } -Verifiable + + Context 'When the Get-SqlDscDynamicMaxMemory fails to calculate the MaxMemory' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + DynamicAlloc = $true + Ensure = 'Present' + } + + It 'Should throw the correct error' { + { Set-TargetResource @testParameters } | Should -Throw 'Failed to calculate dynamically the maximum memory.' + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_PhysicalMemory' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_Processor' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_Processor' + } -Scope Context + } + + It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_operatingsystem' { + Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter { + $ClassName -eq 'Win32_operatingsystem' + } -Scope Context + } + } + + Assert-VerifiableMock + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/Tests/Unit/MSFT_xSQLServerNetwork.Tests.ps1 b/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 similarity index 98% rename from Tests/Unit/MSFT_xSQLServerNetwork.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 index 4629075d7..6a73a71b6 100644 --- a/Tests/Unit/MSFT_xSQLServerNetwork.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerNetwork.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerNetwork' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerNetwork' #region HEADER @@ -99,7 +99,7 @@ try ProtocolName = $mockTcpProtocolName } - Describe "MSFT_xSQLServerNetwork\Get-TargetResource" -Tag 'Get'{ + Describe "MSFT_SqlServerNetwork\Get-TargetResource" -Tag 'Get'{ BeforeEach { $testParameters = $mockDefaultParameters.Clone() @@ -141,7 +141,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerNetwork\Test-TargetResource" -Tag 'Test'{ + Describe "MSFT_SqlServerNetwork\Test-TargetResource" -Tag 'Test'{ BeforeEach { $testParameters = $mockDefaultParameters.Clone() @@ -309,7 +309,7 @@ try Assert-VerifiableMock } - Describe "MSFT_xSQLServerNetwork\Set-TargetResource" -Tag 'Set'{ + Describe "MSFT_SqlServerNetwork\Set-TargetResource" -Tag 'Set'{ BeforeEach { $testParameters = $mockDefaultParameters.Clone() diff --git a/Tests/Unit/MSFT_xSQLServerPermission.Tests.ps1 b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 similarity index 87% rename from Tests/Unit/MSFT_xSQLServerPermission.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 index 217a58e10..43d4aab02 100644 --- a/Tests/Unit/MSFT_xSQLServerPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerPermission' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerPermission' #region HEADER # Unit Test Template Version: 1.2.0 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment ` #endregion HEADER -function Invoke-TestSetup { +function Invoke-TestSetup +{ # Loading mocked classes Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -35,28 +37,28 @@ try Invoke-TestSetup InModuleScope $script:DSCResourceName { - $mockNodeName = 'localhost' + $mockServerName = 'localhost' $mockInstanceName = 'DEFAULT' $mockPrincipal = 'COMPANY\SqlServiceAcct' $mockOtherPrincipal = 'COMPANY\OtherAccount' - $mockPermission = @('ConnectSql','AlterAnyAvailabilityGroup','ViewServerState') + $mockPermission = @('ConnectSql', 'AlterAnyAvailabilityGroup', 'ViewServerState') #endregion Pester Test Initialization $defaultParameters = @{ InstanceName = $mockInstanceName - NodeName = $mockNodeName - Principal = $mockPrincipal - Permission = $mockPermission + ServerName = $mockServerName + Principal = $mockPrincipal + Permission = $mockPermission } - Describe 'MSFT_xSQLServerPermission\Get-TargetResource' { + Describe 'MSFT_SqlServerPermission\Get-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() Mock -CommandName Connect-SQL -MockWith { $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server - $mockObjectSmoServer.Name = "$mockNodeName\$mockInstanceName" + $mockObjectSmoServer.Name = "$mockServerName\$mockInstanceName" $mockObjectSmoServer.DisplayName = $mockInstanceName $mockObjectSmoServer.InstanceName = $mockInstanceName $mockObjectSmoServer.IsHadrEnabled = $False @@ -77,7 +79,7 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $mockNodeName + $result.ServerName | Should -Be $mockServerName $result.InstanceName | Should -Be $mockInstanceName $result.Principal | Should -Be $mockPrincipal } @@ -97,7 +99,7 @@ try [Microsoft.SqlServer.Management.Smo.Globals]::GenerateMockData = $true BeforeEach { - $testParameters.Permission = @( 'AlterAnyAvailabilityGroup','ViewServerState','AlterAnyEndpoint') + $testParameters.Permission = @( 'AlterAnyAvailabilityGroup', 'ViewServerState', 'AlterAnyEndpoint') } It 'Should return the desired state as absent' { @@ -107,14 +109,14 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $mockNodeName + $result.ServerName | Should -Be $mockServerName $result.InstanceName | Should -Be $mockInstanceName $result.Principal | Should -Be $mockPrincipal } It 'Should not return any permissions' { $result = Get-TargetResource @testParameters - $result.Permission | Should -Be @('AlterAnyAvailabilityGroup','ConnectSql', 'ViewServerState') + $result.Permission | Should -Be @('AlterAnyAvailabilityGroup', 'ConnectSql', 'ViewServerState') } It 'Should call the mock function Connect-SQL' { @@ -144,17 +146,21 @@ try It 'Should return the same values as passed as parameters' { $result = Get-TargetResource @testParameters - $result.NodeName | Should -Be $mockNodeName + $result.ServerName | Should -Be $mockServerName $result.InstanceName | Should -Be $mockInstanceName $result.Principal | Should -Be $mockPrincipal } It 'Should return the permissions passed as parameter' { $result = Get-TargetResource @testParameters - foreach ($currentPermission in $mockPermission) { - if( $result.Permission -ccontains $currentPermission ) { + foreach ($currentPermission in $mockPermission) + { + if ( $result.Permission -ccontains $currentPermission ) + { $permissionState = $true - } else { + } + else + { $permissionState = $false break } @@ -172,13 +178,13 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerPermission\Test-TargetResource' { + Describe 'MSFT_SqlServerPermission\Test-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() Mock -CommandName Connect-SQL -MockWith { $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server - $mockObjectSmoServer.Name = "$mockNodeName\$mockInstanceName" + $mockObjectSmoServer.Name = "$mockServerName\$mockInstanceName" $mockObjectSmoServer.DisplayName = $mockInstanceName $mockObjectSmoServer.InstanceName = $mockInstanceName $mockObjectSmoServer.IsHadrEnabled = $False @@ -240,13 +246,13 @@ try Assert-VerifiableMock } - Describe 'MSFT_xSQLServerPermission\Set-TargetResource' { + Describe 'MSFT_SqlServerPermission\Set-TargetResource' { BeforeEach { $testParameters = $defaultParameters.Clone() Mock -CommandName Connect-SQL -MockWith { $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server - $mockObjectSmoServer.Name = "$mockNodeName\$mockInstanceName" + $mockObjectSmoServer.Name = "$mockServerName\$mockInstanceName" $mockObjectSmoServer.DisplayName = $mockInstanceName $mockObjectSmoServer.InstanceName = $mockInstanceName $mockObjectSmoServer.IsHadrEnabled = $False @@ -303,7 +309,7 @@ try It 'Should return the correct error message' { Mock -CommandName Connect-SQL -MockWith { $mockObjectSmoServer = New-Object Microsoft.SqlServer.Management.Smo.Server - $mockObjectSmoServer.Name = "$mockNodeName\$mockInstanceName" + $mockObjectSmoServer.Name = "$mockServerName\$mockInstanceName" $mockObjectSmoServer.DisplayName = $mockInstanceName $mockObjectSmoServer.InstanceName = $mockInstanceName $mockObjectSmoServer.IsHadrEnabled = $False diff --git a/Tests/Unit/MSFT_xSQLServerReplication.Tests.ps1 b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 similarity index 99% rename from Tests/Unit/MSFT_xSQLServerReplication.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 index 0f844c6c9..a67868933 100644 --- a/Tests/Unit/MSFT_xSQLServerReplication.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 @@ -1,8 +1,8 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] param () -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerReplication' +$script:DSCModuleName = 'SqlServerDSC' +$script:DSCResourceName = 'MSFT_SqlServerReplication' #region HEADER # Unit Test Template Version: 1.1.0 diff --git a/Tests/Unit/MSFT_xSQLServerRole.Tests.ps1 b/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 similarity index 72% rename from Tests/Unit/MSFT_xSQLServerRole.Tests.ps1 rename to Tests/Unit/MSFT_SqlServerRole.Tests.ps1 index 5b9fba14d..7085936b8 100644 --- a/Tests/Unit/MSFT_xSQLServerRole.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerRole.Tests.ps1 @@ -1,1008 +1,1010 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerRole' - -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { -} - -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -# Begin Testing -try -{ - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { - $mockSqlServerName = 'localhost' - $mockSqlServerInstanceName = 'MSSQLSERVER' - $mockSqlServerRole = 'AdminSqlforBI' - $mockSqlServerLoginOne = 'CONTOSO\John' - $mockSqlServerLoginTwo = 'CONTOSO\Kelly' - $mockSqlServerLoginTree = 'CONTOSO\Lucy' - $mockSqlServerLoginFour = 'CONTOSO\Steve' - $mockEnumMemberNames = @($mockSqlServerLoginOne,$mockSqlServerLoginTwo) - $mockSqlServerLoginType = 'WindowsUser' - $mockExpectedServerRoleToDrop = 'ServerRoleToDrop' - - # Default parameters that are used for the It-blocks - $mockDefaultParameters = @{ - SQLInstanceName = $mockSqlServerInstanceName - SQLServer = $mockSqlServerName - } - - #region Function mocks - - $mockConnectSQL = { - return @( - ( - New-Object Object | - Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockSqlServerInstanceName -PassThru | - Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockSqlServerName -PassThru | - Add-Member -MemberType ScriptProperty -Name Roles -Value { - return @{ - $mockSqlServerRole = ( New-Object Object | - Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerRole -PassThru | - Add-Member -MemberType ScriptMethod -Name EnumMemberNames -Value { - if ($mockInvalidOperationForEnumMethod) - { - throw 'Mock EnumMemberNames Method was called with invalid operation.' - } - else - { - $mockEnumMemberNames - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name Drop -Value { - if ($mockInvalidOperationForDropMethod) - { - throw 'Mock Drop Method was called with invalid operation.' - } - - if ( $this.Name -ne $mockExpectedServerRoleToDrop ) - { - throw "Called mocked drop() method without dropping the right server role. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedServerRoleToDrop, $this.Name - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name AddMember -Value { - if ($mockInvalidOperationForAddMemberMethod) - { - throw 'Mock AddMember Method was called with invalid operation.' - } - - if ( $mockSqlServerLoginToAdd -ne $mockExpectedMemberToAdd ) - { - throw "Called mocked AddMember() method without adding the right login. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedMemberToAdd, $mockSqlServerLoginToAdd - } - } -PassThru | - Add-Member -MemberType ScriptMethod -Name DropMember -Value { - if ($mockInvalidOperationForDropMemberMethod) - { - throw 'Mock DropMember Method was called with invalid operation.' - } - - if ( $mockSqlServerLoginToDrop -ne $mockExpectedMemberToDrop ) - { - throw "Called mocked DropMember() method without removing the right login. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedMemberToDrop, $mockSqlServerLoginToDrop - } - } -PassThru - ) - } - } -PassThru | - Add-Member -MemberType ScriptProperty -Name Logins -Value { - return @{ - $mockSqlServerLoginOne = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru - )) - $mockSqlServerLoginTwo = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru - )) - $mockSqlServerLoginTree = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru - )) - $mockSqlServerLoginFour = @(( - New-Object Object | - Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru - )) - } - } -PassThru -Force - ) - ) - } - - $mockNewObjectServerRole = { - return @( - ( - New-Object Object | - Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerRoleAdd -PassThru | - Add-Member -MemberType ScriptMethod -Name Create -Value { - if ($mockInvalidOperationForCreateMethod) - { - throw 'Mock Create Method was called with invalid operation.' - } - - if ( $this.Name -ne $mockExpectedServerRoleToCreate ) - { - throw "Called mocked Create() method without adding the right server role. Expected '{0}'. But was '{1}'." ` - -f $mockExpectedServerRoleToCreate, $this.Name - } - } -PassThru -Force - ) - ) - } - #endregion - - Describe "MSFT_xSQLServerRole\Get-TargetResource" -Tag 'Get'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When the system is in the desired state and ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = 'UnknownRoleName' - } - - It 'Should return the state as absent when the role does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - } - - It 'Should not return the state as absent when the role exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Not -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as not null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Not -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - # Regression test for issue #790 - It 'Should return the members as string array' { - $result = Get-TargetResource @testParameters - ($result.Members -is [String[]]) | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When passing values to parameters and throwing with EnumMemberNames method' { - It 'Should throw the correct error' { - $mockInvalidOperationForEnumMethod = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - } - - $throwInvalidOperation = ('Failed to enumerate members of the server role ' + ` - 'named AdminSqlforBI on localhost\MSSQLSERVER. InnerException: ' + ` - 'Exception calling "EnumMemberNames" with "0" argument(s): ' + ` - '"Mock EnumMemberNames Method was called with invalid operation."') - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is in the desired state, parameter Members is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - } - - It 'Should return the state as present when the members are correct' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Present' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as not null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Be $testParameters.Members - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - # Regression test for issue #790 - It 'Should return the members as string array' { - $result = Get-TargetResource @testParameters - ($result.Members -is [String[]]) | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state, parameter MembersToInclude is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTwo - } - - It 'Should return the state as present when the correct members exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Present' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as not null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Not -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - # Regression test for issue #790 - It 'Should return the members as string array' { - $result = Get-TargetResource @testParameters - ($result.Members -is [String[]]) | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - $result.MembersToInclude | Should -Be $testParameters.MembersToInclude - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state, parameter MembersToExclude is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTree - } - - It 'Should return the state as present when the members does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Present' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - $result.MembersToExclude | Should -Be $testParameters.MembersToExclude - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state, parameter MembersToInclude is assigned a value, parameter Members is assigned a value, and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToInclude = $mockSqlServerLoginTree - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - - } - - Context 'When the system is not in the desired state, parameter MembersToExclude is assigned a value, parameter Members is assigned a value, and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToExclude = $mockSqlServerLoginTree - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - } - - It 'Should call the mock function Connect-SQL' { - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context - } - } - - Context 'When the system is not in the desired state and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = 'UnknownRoleName' - } - - It 'Should return the state as absent when the role does not exist' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state, parameter Members is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - Members = @($mockSqlServerLoginOne,$mockSqlServerLoginTree) - } - - It 'Should return the state as absent when the members in the role are wrong' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as not null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Not -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - # Regression test for issue #790 - It 'Should return the members as string array' { - $result = Get-TargetResource @testParameters - ($result.Members -is [String[]]) | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state, parameter MembersToInclude is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTree - } - - It 'Should return the state as absent when the members in the role are missing' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the members as not null' { - $result = Get-TargetResource @testParameters - $result.Members | Should -Not -Be $null - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - # Regression test for issue #790 - It 'Should return the members as string array' { - $result = Get-TargetResource @testParameters - ($result.Members -is [String[]]) | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - $result.MembersToInclude | Should -Be $testParameters.MembersToInclude - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state, parameter MembersToExclude is assigned a value and ensure is set to Present' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTwo - } - - It 'Should return the state as absent when the members in the role are present' { - $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should return the same values as passed as parameters' { - $result = Get-TargetResource @testParameters - $result.SQLServer | Should -Be $testParameters.SQLServer - $result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName - $result.ServerRoleName | Should -Be $testParameters.ServerRoleName - $result.MembersToExclude | Should -Be $testParameters.MembersToExclude - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerRole\Test-TargetResource" -Tag 'Test'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - It 'Should return false when desired server role exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - ServerRoleName = $mockSqlServerRole - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Absent' { - It 'Should return true when desired server role does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - ServerRoleName = 'newServerRole' - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is in the desired state and ensure is set to Present' { - It 'Should return true when desired server role exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure parameter is set to Present' { - It 'Should return false when desired members are not in desired server role' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = @($mockSqlServerLoginTree,$mockSqlServerLoginFour) - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When both the parameters Members and MembersToInclude are assigned a value and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToInclude = $mockSqlServerLoginTree - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should return true when desired server role exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTwo - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should return false when desired server role does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTree - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When both the parameters Members and MembersToExclude are assigned a value and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToExclude = $mockSqlServerLoginTwo - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should return true when desired server role does not exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTree - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $true - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should return false when desired server role exist' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTwo - } - - $result = Test-TargetResource @testParameters - $result | Should -Be $false - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Assert-VerifiableMock - } - - Describe "MSFT_xSQLServerRole\Set-TargetResource" -Tag 'Set'{ - BeforeEach { - Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - Mock -CommandName New-Object -MockWith $mockNewObjectServerRole -ParameterFilter { - $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' - } - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - It 'Should not throw when calling the drop method' { - $mockSqlServerRole = 'ServerRoleToDrop' - $mockExpectedServerRoleToDrop = 'ServerRoleToDrop' - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - ServerRoleName = $mockSqlServerRole - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Absent' { - It 'Should throw the correct error when calling the drop method' { - $mockInvalidOperationForDropMethod = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Absent' - ServerRoleName = $mockSqlServerRole - } - - $throwInvalidOperation = ('Failed to drop the server role named AdminSqlforBI on ' + ` - 'localhost\MSSQLSERVER. InnerException: Exception calling ' + ` - '"Drop" with "0" argument(s): "Mock Drop Method ' + ` - 'was called with invalid operation."') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When the system is not in the desired state and ensure is set to Present' { - It 'Should not throw when calling the create method' { - $mockSqlServerRoleAdd = 'ServerRoleToAdd' - $mockExpectedServerRoleToCreate = 'ServerRoleToAdd' - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRoleAdd - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { - Assert-MockCalled New-Object -Exactly -Times 1 -ParameterFilter { - $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' - } -Scope Context - } - } - - Context 'When the system is not in the desired state and ensure is set to Present' { - It 'Should throw the correct error when calling the create method' { - $mockSqlServerRoleAdd = 'ServerRoleToAdd' - $mockExpectedServerRoleToCreate = 'ServerRoleToAdd' - $mockInvalidOperationForCreateMethod = $true - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRoleAdd - } - - $throwInvalidOperation = ('Failed to create the server role named ServerRoleToAdd on ' + ` - 'localhost\MSSQLSERVER. InnerException: Exception calling ' + ` - '"Create" with "0" argument(s): "Mock Create Method ' + ` - 'was called with invalid operation."') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - - It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { - Assert-MockCalled New-Object -Exactly -Times 1 -ParameterFilter { - $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' - } -Scope Context - } - } - - Context 'When both the parameters Members and MembersToInclude are assigned a value and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToInclude = $mockSqlServerLoginTree - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When both the parameters Members and MembersToExclude are assigned a value and ensure is set to Present' { - It 'Should throw the correct error' { - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = $mockEnumMemberNames - MembersToExclude = $mockSqlServerLoginTwo - } - - $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` - 'MembersToExclude must not be set, or be set ' + ` - 'to $null, when parameter Members are used.') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should not thrown when calling the AddMember method' { - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTree - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should throw the correct error when calling the AddMember method' { - $mockInvalidOperationForAddMemberMethod = $true - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToInclude = $mockSqlServerLoginTree - } - - $throwInvalidOperation = ('Failed to add member CONTOSO\Lucy to the server role named AdminSqlforBI ' + ` - 'on localhost\MSSQLSERVER. InnerException: Exception calling "AddMember" ' + ` - 'with "1" argument(s): "Mock AddMember Method was called with invalid operation."') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should throw the correct error when login does not exist' { - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToInclude = 'KingJulian' - } - - $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should not throw when calling the DropMember method' { - $mockExpectedMemberToAdd = $mockSqlServerLoginTwo - $mockSqlServerLoginToAdd = $mockSqlServerLoginTwo - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTwo - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should throw the correct error when calling the DropMember method' { - $mockInvalidOperationForDropMemberMethod = $true - $mockExpectedMemberToDrop = $mockSqlServerLoginTwo - $mockSqlServerLoginToDrop = $mockSqlServerLoginTwo - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToExclude = $mockSqlServerLoginTwo - } - - $throwInvalidOperation = ('Failed to drop member CONTOSO\Kelly to the server role named AdminSqlforBI ' + ` - 'on localhost\MSSQLSERVER. InnerException: Exception calling "DropMember" ' + ` - 'with "1" argument(s): "Mock DropMember Method was called with invalid operation."') - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { - It 'Should throw the correct error when login does not exist' { - $mockEnumMemberNames = @('KingJulian',$mockSqlServerLoginOne,$mockSqlServerLoginTwo) - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - MembersToExclude = 'KingJulian' - } - - $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When parameter Members is assigned a value and ensure is set to Present' { - It 'Should throw the correct error when login does not exist' { - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = @('KingJulian',$mockSqlServerLoginOne,$mockSqlServerLoginTree) - } - - $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") - - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Context 'When Members parameter is set and ensure parameter is set to Present' { - It 'Should not throw when calling both the AddMember and DropMember methods' { - $mockExpectedMemberToAdd = $mockSqlServerLoginTree - $mockSqlServerLoginToAdd = $mockSqlServerLoginTree - $mockExpectedMemberToDrop = $mockSqlServerLoginTwo - $mockSqlServerLoginToDrop = $mockSqlServerLoginTwo - $testParameters = $mockDefaultParameters - $testParameters += @{ - Ensure = 'Present' - ServerRoleName = $mockSqlServerRole - Members = @($mockSqlServerLoginOne,$mockSqlServerLoginTree) - } - - { Set-TargetResource @testParameters } | Should -Not -Throw - - Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It - } - } - - Assert-VerifiableMock - } - } -} -finally -{ - Invoke-TestCleanup -} - +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServerRole' + +#region HEADER + +# Unit Test Template Version: 1.2.0 +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +function Invoke-TestSetup +{ +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} + +# Begin Testing +try +{ + Invoke-TestSetup + + InModuleScope $script:DSCResourceName { + $mockServerName = 'localhost' + $mockInstanceName = 'MSSQLSERVER' + $mockSqlServerRole = 'AdminSqlforBI' + $mockSqlServerLoginOne = 'CONTOSO\John' + $mockSqlServerLoginTwo = 'CONTOSO\Kelly' + $mockSqlServerLoginTree = 'CONTOSO\Lucy' + $mockSqlServerLoginFour = 'CONTOSO\Steve' + $mockEnumMemberNames = @($mockSqlServerLoginOne, $mockSqlServerLoginTwo) + $mockSqlServerLoginType = 'WindowsUser' + $mockExpectedServerRoleToDrop = 'ServerRoleToDrop' + + # Default parameters that are used for the It-blocks + $mockDefaultParameters = @{ + InstanceName = $mockInstanceName + ServerName = $mockServerName + } + + #region Function mocks + + $mockConnectSQL = { + return @( + ( + New-Object Object | + Add-Member -MemberType NoteProperty -Name InstanceName -Value $mockInstanceName -PassThru | + Add-Member -MemberType NoteProperty -Name ComputerNamePhysicalNetBIOS -Value $mockServerName -PassThru | + Add-Member -MemberType ScriptProperty -Name Roles -Value { + return @{ + $mockSqlServerRole = ( New-Object Object | + Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerRole -PassThru | + Add-Member -MemberType ScriptMethod -Name EnumMemberNames -Value { + if ($mockInvalidOperationForEnumMethod) + { + throw 'Mock EnumMemberNames Method was called with invalid operation.' + } + else + { + $mockEnumMemberNames + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name Drop -Value { + if ($mockInvalidOperationForDropMethod) + { + throw 'Mock Drop Method was called with invalid operation.' + } + + if ( $this.Name -ne $mockExpectedServerRoleToDrop ) + { + throw "Called mocked drop() method without dropping the right server role. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedServerRoleToDrop, $this.Name + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name AddMember -Value { + if ($mockInvalidOperationForAddMemberMethod) + { + throw 'Mock AddMember Method was called with invalid operation.' + } + + if ( $mockSqlServerLoginToAdd -ne $mockExpectedMemberToAdd ) + { + throw "Called mocked AddMember() method without adding the right login. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedMemberToAdd, $mockSqlServerLoginToAdd + } + } -PassThru | + Add-Member -MemberType ScriptMethod -Name DropMember -Value { + if ($mockInvalidOperationForDropMemberMethod) + { + throw 'Mock DropMember Method was called with invalid operation.' + } + + if ( $mockSqlServerLoginToDrop -ne $mockExpectedMemberToDrop ) + { + throw "Called mocked DropMember() method without removing the right login. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedMemberToDrop, $mockSqlServerLoginToDrop + } + } -PassThru + ) + } + } -PassThru | + Add-Member -MemberType ScriptProperty -Name Logins -Value { + return @{ + $mockSqlServerLoginOne = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru + )) + $mockSqlServerLoginTwo = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru + )) + $mockSqlServerLoginTree = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru + )) + $mockSqlServerLoginFour = @(( + New-Object Object | + Add-Member -MemberType NoteProperty -Name LoginType -Value $mockSqlServerLoginType -PassThru + )) + } + } -PassThru -Force + ) + ) + } + + $mockNewObjectServerRole = { + return @( + ( + New-Object Object | + Add-Member -MemberType NoteProperty -Name Name -Value $mockSqlServerRoleAdd -PassThru | + Add-Member -MemberType ScriptMethod -Name Create -Value { + if ($mockInvalidOperationForCreateMethod) + { + throw 'Mock Create Method was called with invalid operation.' + } + + if ( $this.Name -ne $mockExpectedServerRoleToCreate ) + { + throw "Called mocked Create() method without adding the right server role. Expected '{0}'. But was '{1}'." ` + -f $mockExpectedServerRoleToCreate, $this.Name + } + } -PassThru -Force + ) + ) + } + #endregion + + Describe "MSFT_SqlServerRole\Get-TargetResource" -Tag 'Get' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When the system is in the desired state and ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = 'UnknownRoleName' + } + + It 'Should return the state as absent when the role does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + } + + It 'Should not return the state as absent when the role exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Not -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as not null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Not -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + # Regression test for issue #790 + It 'Should return the members as string array' { + $result = Get-TargetResource @testParameters + ($result.Members -is [String[]]) | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When passing values to parameters and throwing with EnumMemberNames method' { + It 'Should throw the correct error' { + $mockInvalidOperationForEnumMethod = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + } + + $throwInvalidOperation = ('Failed to enumerate members of the server role ' + ` + 'named AdminSqlforBI on localhost\MSSQLSERVER. InnerException: ' + ` + 'Exception calling "EnumMemberNames" with "0" argument(s): ' + ` + '"Mock EnumMemberNames Method was called with invalid operation."') + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is in the desired state, parameter Members is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + } + + It 'Should return the state as present when the members are correct' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Present' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as not null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Be $testParameters.Members + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + # Regression test for issue #790 + It 'Should return the members as string array' { + $result = Get-TargetResource @testParameters + ($result.Members -is [String[]]) | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state, parameter MembersToInclude is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTwo + } + + It 'Should return the state as present when the correct members exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Present' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as not null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Not -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + # Regression test for issue #790 + It 'Should return the members as string array' { + $result = Get-TargetResource @testParameters + ($result.Members -is [String[]]) | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + $result.MembersToInclude | Should -Be $testParameters.MembersToInclude + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state, parameter MembersToExclude is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTree + } + + It 'Should return the state as present when the members does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Present' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + $result.MembersToExclude | Should -Be $testParameters.MembersToExclude + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state, parameter MembersToInclude is assigned a value, parameter Members is assigned a value, and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToInclude = $mockSqlServerLoginTree + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + + } + + Context 'When the system is not in the desired state, parameter MembersToExclude is assigned a value, parameter Members is assigned a value, and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToExclude = $mockSqlServerLoginTree + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + } + + It 'Should call the mock function Connect-SQL' { + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context + } + } + + Context 'When the system is not in the desired state and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = 'UnknownRoleName' + } + + It 'Should return the state as absent when the role does not exist' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state, parameter Members is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + Members = @($mockSqlServerLoginOne, $mockSqlServerLoginTree) + } + + It 'Should return the state as absent when the members in the role are wrong' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as not null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Not -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + # Regression test for issue #790 + It 'Should return the members as string array' { + $result = Get-TargetResource @testParameters + ($result.Members -is [String[]]) | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state, parameter MembersToInclude is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTree + } + + It 'Should return the state as absent when the members in the role are missing' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the members as not null' { + $result = Get-TargetResource @testParameters + $result.Members | Should -Not -Be $null + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + # Regression test for issue #790 + It 'Should return the members as string array' { + $result = Get-TargetResource @testParameters + ($result.Members -is [String[]]) | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + $result.MembersToInclude | Should -Be $testParameters.MembersToInclude + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state, parameter MembersToExclude is assigned a value and ensure is set to Present' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTwo + } + + It 'Should return the state as absent when the members in the role are present' { + $result = Get-TargetResource @testParameters + $result.Ensure | Should -Be 'Absent' + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should return the same values as passed as parameters' { + $result = Get-TargetResource @testParameters + $result.ServerName | Should -Be $testParameters.ServerName + $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerRoleName | Should -Be $testParameters.ServerRoleName + $result.MembersToExclude | Should -Be $testParameters.MembersToExclude + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlServerRole\Test-TargetResource" -Tag 'Test' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + It 'Should return false when desired server role exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + ServerRoleName = $mockSqlServerRole + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Absent' { + It 'Should return true when desired server role does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + ServerRoleName = 'newServerRole' + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is in the desired state and ensure is set to Present' { + It 'Should return true when desired server role exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure parameter is set to Present' { + It 'Should return false when desired members are not in desired server role' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = @($mockSqlServerLoginTree, $mockSqlServerLoginFour) + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When both the parameters Members and MembersToInclude are assigned a value and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToInclude = $mockSqlServerLoginTree + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should return true when desired server role exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTwo + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should return false when desired server role does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTree + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When both the parameters Members and MembersToExclude are assigned a value and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToExclude = $mockSqlServerLoginTwo + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Test-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should return true when desired server role does not exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTree + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $true + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should return false when desired server role exist' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTwo + } + + $result = Test-TargetResource @testParameters + $result | Should -Be $false + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Assert-VerifiableMock + } + + Describe "MSFT_SqlServerRole\Set-TargetResource" -Tag 'Set' { + BeforeEach { + Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable + Mock -CommandName New-Object -MockWith $mockNewObjectServerRole -ParameterFilter { + $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' + } + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + It 'Should not throw when calling the drop method' { + $mockSqlServerRole = 'ServerRoleToDrop' + $mockExpectedServerRoleToDrop = 'ServerRoleToDrop' + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + ServerRoleName = $mockSqlServerRole + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Absent' { + It 'Should throw the correct error when calling the drop method' { + $mockInvalidOperationForDropMethod = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Absent' + ServerRoleName = $mockSqlServerRole + } + + $throwInvalidOperation = ('Failed to drop the server role named AdminSqlforBI on ' + ` + 'localhost\MSSQLSERVER. InnerException: Exception calling ' + ` + '"Drop" with "0" argument(s): "Mock Drop Method ' + ` + 'was called with invalid operation."') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When the system is not in the desired state and ensure is set to Present' { + It 'Should not throw when calling the create method' { + $mockSqlServerRoleAdd = 'ServerRoleToAdd' + $mockExpectedServerRoleToCreate = 'ServerRoleToAdd' + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRoleAdd + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { + Assert-MockCalled New-Object -Exactly -Times 1 -ParameterFilter { + $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' + } -Scope Context + } + } + + Context 'When the system is not in the desired state and ensure is set to Present' { + It 'Should throw the correct error when calling the create method' { + $mockSqlServerRoleAdd = 'ServerRoleToAdd' + $mockExpectedServerRoleToCreate = 'ServerRoleToAdd' + $mockInvalidOperationForCreateMethod = $true + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRoleAdd + } + + $throwInvalidOperation = ('Failed to create the server role named ServerRoleToAdd on ' + ` + 'localhost\MSSQLSERVER. InnerException: Exception calling ' + ` + '"Create" with "0" argument(s): "Mock Create Method ' + ` + 'was called with invalid operation."') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + + It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { + Assert-MockCalled New-Object -Exactly -Times 1 -ParameterFilter { + $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' + } -Scope Context + } + } + + Context 'When both the parameters Members and MembersToInclude are assigned a value and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToInclude = $mockSqlServerLoginTree + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When both the parameters Members and MembersToExclude are assigned a value and ensure is set to Present' { + It 'Should throw the correct error' { + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = $mockEnumMemberNames + MembersToExclude = $mockSqlServerLoginTwo + } + + $throwInvalidOperation = ('The parameter MembersToInclude and/or ' + ` + 'MembersToExclude must not be set, or be set ' + ` + 'to $null, when parameter Members are used.') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should not thrown when calling the AddMember method' { + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTree + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should throw the correct error when calling the AddMember method' { + $mockInvalidOperationForAddMemberMethod = $true + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToInclude = $mockSqlServerLoginTree + } + + $throwInvalidOperation = ('Failed to add member CONTOSO\Lucy to the server role named AdminSqlforBI ' + ` + 'on localhost\MSSQLSERVER. InnerException: Exception calling "AddMember" ' + ` + 'with "1" argument(s): "Mock AddMember Method was called with invalid operation."') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should throw the correct error when login does not exist' { + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToInclude = 'KingJulian' + } + + $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should not throw when calling the DropMember method' { + $mockExpectedMemberToAdd = $mockSqlServerLoginTwo + $mockSqlServerLoginToAdd = $mockSqlServerLoginTwo + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTwo + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should throw the correct error when calling the DropMember method' { + $mockInvalidOperationForDropMemberMethod = $true + $mockExpectedMemberToDrop = $mockSqlServerLoginTwo + $mockSqlServerLoginToDrop = $mockSqlServerLoginTwo + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToExclude = $mockSqlServerLoginTwo + } + + $throwInvalidOperation = ('Failed to drop member CONTOSO\Kelly to the server role named AdminSqlforBI ' + ` + 'on localhost\MSSQLSERVER. InnerException: Exception calling "DropMember" ' + ` + 'with "1" argument(s): "Mock DropMember Method was called with invalid operation."') + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + It 'Should throw the correct error when login does not exist' { + $mockEnumMemberNames = @('KingJulian', $mockSqlServerLoginOne, $mockSqlServerLoginTwo) + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + MembersToExclude = 'KingJulian' + } + + $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When parameter Members is assigned a value and ensure is set to Present' { + It 'Should throw the correct error when login does not exist' { + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = @('KingJulian', $mockSqlServerLoginOne, $mockSqlServerLoginTree) + } + + $throwInvalidOperation = ("Login 'KingJulian' does not exist on SQL server 'localhost\MSSQLSERVER'.") + + { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Context 'When Members parameter is set and ensure parameter is set to Present' { + It 'Should not throw when calling both the AddMember and DropMember methods' { + $mockExpectedMemberToAdd = $mockSqlServerLoginTree + $mockSqlServerLoginToAdd = $mockSqlServerLoginTree + $mockExpectedMemberToDrop = $mockSqlServerLoginTwo + $mockSqlServerLoginToDrop = $mockSqlServerLoginTwo + $testParameters = $mockDefaultParameters + $testParameters += @{ + Ensure = 'Present' + ServerRoleName = $mockSqlServerRole + Members = @($mockSqlServerLoginOne, $mockSqlServerLoginTree) + } + + { Set-TargetResource @testParameters } | Should -Not -Throw + + Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope It + } + } + + Assert-VerifiableMock + } + } +} +finally +{ + Invoke-TestCleanup +} + diff --git a/Tests/Unit/MSFT_xSQLServerServiceAccount.Tests.ps1 b/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 similarity index 83% rename from Tests/Unit/MSFT_xSQLServerServiceAccount.Tests.ps1 rename to Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 index 68a08fc16..c7f613014 100644 --- a/Tests/Unit/MSFT_xSQLServerServiceAccount.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1 @@ -1,14 +1,14 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerServiceAccount' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlServiceAccount' #region HEADER # Unit Test Template Version: 1.2.1 $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) } Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force @@ -26,7 +26,8 @@ function Invoke-TestSetup Add-Type -Path (Join-Path -Path $script:moduleRoot -ChildPath 'Tests\Unit\Stubs\SMO.cs') } -function Invoke-TestCleanup { +function Invoke-TestCleanup +{ Restore-TestEnvironment -TestEnvironment $TestEnvironment } @@ -50,9 +51,9 @@ try # Stores the result of SetServiceAccount calls $testServiceAccountUpdated = @{ - Processed = $false + Processed = $false NewUserAccount = [System.String]::Empty - NewPassword = [System.String]::Emtpy + NewPassword = [System.String]::Emtpy } # Script block for changing the service account in mocks @@ -88,26 +89,26 @@ try # Splat for creating the SetServiceAccount method $mockAddMemberParameters_SetServiceAccount = @{ - Name = 'SetServiceAccount' + Name = 'SetServiceAccount' MemberType = 'ScriptMethod' - Value = $mockSetServiceAccount + Value = $mockSetServiceAccount } $mockAddMemberParameters_SetServiceAccount_Exception = @{ - Name = 'SetServiceAccount' + Name = 'SetServiceAccount' MemberType = 'ScriptMethod' - Value = $mockSetServiceAccount_Exception + Value = $mockSetServiceAccount_Exception } # Used to mock ManagedComputer object for a default instance $mockNewObject_ManagedComputer_DefaultInstance = { $managedComputerObject = New-Object -TypeName PSObject -Property @{ - Name = $mockSqlServer + Name = $mockSqlServer Services = @( New-Object -TypeName PSObject -Property @{ - Name = $mockDefaultInstanceName + Name = $mockDefaultInstanceName ServiceAccount = $mockDefaultServiceAccountName - Type = 'SqlServer' + Type = 'SqlServer' } ) } @@ -122,12 +123,12 @@ try # Creates a new ManagedComputer object for a default instance with a local service account $mockNewObject_ManagedComputer_DefaultInstance_LocalServiceAccount = { $managedComputerObject = New-Object -TypeName PSObject -Property @{ - Name = $mockSqlServer + Name = $mockSqlServer Services = @( New-Object -TypeName PSObject -Property @{ - Name = $mockDefaultInstanceName - ServiceAccount = ($mockLocalServiceAccountName -replace $mockSqlServer,'.') - Type = 'SqlServer' + Name = $mockDefaultInstanceName + ServiceAccount = ($mockLocalServiceAccountName -replace $mockSqlServer, '.') + Type = 'SqlServer' } ) } @@ -145,12 +146,12 @@ try #> $mockNewObject_ManagedComputer_DefaultInstance_SetServiceAccountException = { $managedComputerObject = New-Object -TypeName PSObject -Property @{ - Name = $mockSqlServer + Name = $mockSqlServer Services = @( New-Object -TypeName PSObject -Property @{ - Name = $mockDefaultInstanceName + Name = $mockDefaultInstanceName ServiceAccount = $mockDefaultServiceAccountName - Type = 'SqlServer' + Type = 'SqlServer' } ) } @@ -165,12 +166,12 @@ try # Used to mock a ManagedComputer object for a named instance $mockNewObject_ManagedComputer_NamedInstance = { $managedComputerObject = New-Object -TypeName PSObject -Property @{ - Name = $mockSqlServer + Name = $mockSqlServer Services = @( New-Object -TypeName PSObject -Property @{ - Name = ('MSSQL${0}' -f $mockNamedInstance) + Name = ('MSSQL${0}' -f $mockNamedInstance) ServiceAccount = $mockDesiredServiceAccountName - Type = 'SqlServer' + Type = 'SqlServer' } ) } @@ -185,12 +186,12 @@ try # Used to mock a ManagedComputer object that fails to change the service account $mockNewObject_ManagedComputer_NamedInstance_SetServiceAccountException = { $managedComputerObject = New-Object -TypeName PSObject -Property @{ - Name = $mockSqlServer + Name = $mockSqlServer Services = @( New-Object -TypeName PSObject -Property @{ - Name = ('MSSQL${0}' -f $mockNamedInstance) + Name = ('MSSQL${0}' -f $mockNamedInstance) ServiceAccount = $mockDesiredServiceAccountName - Type = 'SqlServer' + Type = 'SqlServer' } ) } @@ -209,60 +210,60 @@ try # Splat to simplify creation of Mock for New-Object with a default instance $mockNewObjectParameters_DefaultInstance = @{ - CommandName = 'New-Object' - MockWith = $mockNewObject_ManagedComputer_DefaultInstance + CommandName = 'New-Object' + MockWith = $mockNewObject_ManagedComputer_DefaultInstance ParameterFilter = $mockNewObject_ParameterFilter - Verifiable = $true + Verifiable = $true } # Splat to simplify creation of Mock for New-Object with a named instance $mockNewObjectParameters_NamedInstance = @{ - CommandName = 'New-Object' - MockWith = $mockNewObject_ManagedComputer_NamedInstance + CommandName = 'New-Object' + MockWith = $mockNewObject_ManagedComputer_NamedInstance ParameterFilter = $mockNewObject_ParameterFilter - Verifiable = $true + Verifiable = $true } - Describe 'MSFT_xSQLServerServiceAccount\ConvertTo-ManagedServiceType' -Tag 'Helper' { + Describe 'MSFT_SqlServerServiceAccount\ConvertTo-ManagedServiceType' -Tag 'Helper' { Context 'Translating service types' { $testCases = @( @{ - ServiceType = 'DatabaseEngine' + ServiceType = 'DatabaseEngine' ExpectedType = 'SqlServer' } @{ - ServiceType = 'SQLServerAgent' + ServiceType = 'SQLServerAgent' ExpectedType = 'SqlAgent' } @{ - ServiceType = 'Search' + ServiceType = 'Search' ExpectedType = 'Search' } @{ - ServiceType = 'IntegrationServices' + ServiceType = 'IntegrationServices' ExpectedType = 'SqlServerIntegrationService' } @{ - ServiceType = 'AnalysisServices' + ServiceType = 'AnalysisServices' ExpectedType = 'AnalysisServer' } @{ - ServiceType = 'ReportingServices' + ServiceType = 'ReportingServices' ExpectedType = 'ReportServer' } @{ - ServiceType = 'SQLServerBrowser' + ServiceType = 'SQLServerBrowser' ExpectedType = 'SqlBrowser' } @{ - ServiceType = 'NotificationServices' + ServiceType = 'NotificationServices' ExpectedType = 'NotificationServer' } ) @@ -286,13 +287,13 @@ try } } - Describe 'MSFT_xSQLServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { + Describe 'MSFT_SqlServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { Mock -CommandName Import-SQLPSModule -Verifiable $defaultGetServiceObjectParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = '' - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = '' + ServiceType = $mockServiceType } Context 'When getting the service information for a default instance' { @@ -300,7 +301,7 @@ try It 'Should have the correct Type for the service' { $getServiceObjectParameters = $defaultGetServiceObjectParameters.Clone() - $getServiceObjectParameters.SQLInstanceName = $mockDefaultInstanceName + $getServiceObjectParameters.InstanceName = $mockDefaultInstanceName $serviceObject = Get-ServiceObject @getServiceObjectParameters $serviceObject.Type | Should -Be 'SqlServer' @@ -316,7 +317,7 @@ try It 'Should have the correct Type for the service' { $getServiceObjectParameters = $defaultGetServiceObjectParameters.Clone() - $getServiceObjectParameters.SQLInstanceName = $mockNamedInstance + $getServiceObjectParameters.InstanceName = $mockNamedInstance $serviceObject = Get-ServiceObject @getServiceObjectParameters $serviceObject.Type | Should -Be 'SqlServer' @@ -328,16 +329,16 @@ try } } - Describe 'MSFT_xSQLServerServiceAccount\Get-TargetResource' -Tag 'Get' { + Describe 'MSFT_SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { Mock -CommandName Import-SQLPSModule -Verifiable Context 'When getting the service information for a default instance' { Mock @mockNewObjectParameters_DefaultInstance $defaultGetTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockDefaultServiceAccountCredential } @@ -346,8 +347,8 @@ try $testServiceInformation = Get-TargetResource @defaultGetTargetResourceParameters # Validate the hashtable returned - $testServiceInformation.SQLServer | Should -Be $mockSqlServer - $testServiceInformation.SQLInstanceName | Should -Be $mockDefaultInstanceName + $testServiceInformation.ServerName | Should -Be $mockSqlServer + $testServiceInformation.InstanceName | Should -Be $mockDefaultInstanceName $testServiceInformation.ServiceType | Should -Be 'SqlServer' $testServiceInformation.ServiceAccount | Should -Be $mockDefaultServiceAccountName @@ -374,9 +375,9 @@ try # Splat the function parameters $defaultGetTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockNamedInstance - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockNamedInstance + ServiceType = $mockServiceType ServiceAccount = $mockServiceAccountCredential } @@ -385,8 +386,8 @@ try $testServiceInformation = Get-TargetResource @defaultGetTargetResourceParameters # Validate the hashtable returned - $testServiceInformation.SQLServer | Should -Be $mockSqlServer - $testServiceInformation.SQLInstanceName | Should -Be $mockNamedInstance + $testServiceInformation.ServerName | Should -Be $mockSqlServer + $testServiceInformation.InstanceName | Should -Be $mockNamedInstance $testServiceInformation.ServiceType | Should -Be 'SqlServer' $testServiceInformation.ServiceAccount | Should -Be $mockDesiredServiceAccountName @@ -415,9 +416,9 @@ try Mock @mockNewObjectParameters $defaultGetTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockLocalServiceAccountCredential } @@ -433,7 +434,7 @@ try } } - Describe 'MSFT_xSQLServerServiceAccount\Test-TargetResource' -Tag 'Test' { + Describe 'MSFT_SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { Mock -CommandName Import-SQLPSModule -Verifiable Context 'When the system is not in the desired state for a default instance' { @@ -441,9 +442,9 @@ try It 'Should return false' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockServiceAccountCredential } @@ -460,9 +461,9 @@ try It 'Should return true' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockDefaultServiceAccountCredential } @@ -479,11 +480,11 @@ try It 'Should return False when Force is specified' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockServiceAccountCredential - Force = $true + Force = $true } Test-TargetResource @testTargetResourceParameters | Should -Be $false @@ -498,9 +499,9 @@ try It 'Should return false' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockNamedInstance - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockNamedInstance + ServiceType = $mockServiceType ServiceAccount = $mockDefaultServiceAccountCredential } @@ -517,9 +518,9 @@ try It 'Should return true' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockNamedInstance - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockNamedInstance + ServiceType = $mockServiceType ServiceAccount = $mockServiceAccountCredential } @@ -536,11 +537,11 @@ try It 'Should return false' { $testTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockNamedInstance - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockNamedInstance + ServiceType = $mockServiceType ServiceAccount = $mockServiceAccountCredential - Force = $true + Force = $true } # Validate the return value @@ -552,15 +553,15 @@ try } } - Describe 'MSFT_xSQLServerServiceAccount\Set-TargetResource' -Tag 'Set' { + Describe 'MSFT_SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { Mock -CommandName Import-SQLPSModule -Verifiable Context 'When changing the service account for the default instance' { BeforeAll { $defaultSetTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockDefaultInstanceName - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockDefaultInstanceName + ServiceType = $mockServiceType ServiceAccount = $mockDefaultServiceAccountCredential } @@ -596,7 +597,7 @@ try $setTargetResourceParameters.ServiceType = 'SQLServerAgent' # Get the localized error message - $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.SQLServer, $setTargetResourceParameters.SQLInstanceName + $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName # Attempt to update the service account { Set-TargetResource @setTargetResourceParameters } | Should -Throw $mockCorrectErrorMessage @@ -628,7 +629,7 @@ try $setTargetResourceParameters = $defaultSetTargetResourceParameters.Clone() # Get the localized error message - $mockCorrectErrorMessage = $script:localizedData.SetServiceAccountFailed -f $setTargetResourceParameters.SQLServer, $setTargetResourceParameters.SQLInstanceName, '' + $mockCorrectErrorMessage = $script:localizedData.SetServiceAccountFailed -f $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName, '' # Attempt to update the service account { Set-TargetResource @setTargetResourceParameters } | Should -Throw $mockCorrectErrorMessage @@ -642,9 +643,9 @@ try Context 'When changing the service account for the default instance' { BeforeAll { $defaultSetTargetResourceParameters = @{ - SQLServer = $mockSqlServer - SQLInstanceName = $mockNamedInstance - ServiceType = $mockServiceType + ServerName = $mockSqlServer + InstanceName = $mockNamedInstance + ServiceType = $mockServiceType ServiceAccount = $mockDefaultServiceAccountCredential } @@ -680,7 +681,7 @@ try $setTargetResourceParameters.ServiceType = 'SQLServerAgent' # Get the expected localized error message - $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.SQLServer, $setTargetResourceParameters.SQLInstanceName + $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName # Attempt to update the service account { Set-TargetResource @setTargetResourceParameters } | Should -Throw $mockCorrectErrorMessage @@ -712,7 +713,7 @@ try $setTargetResourceParameters = $defaultSetTargetResourceParameters.Clone() # Get the expected localized error message - $mockCorrectErrorMessage = $script:localizedData.SetServiceAccountFailed -f $setTargetResourceParameters.SQLServer, $setTargetResourceParameters.SQLInstanceName, '' + $mockCorrectErrorMessage = $script:localizedData.SetServiceAccountFailed -f $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName, '' # Attempt to update the service information { Set-TargetResource @setTargetResourceParameters } | Should -Throw $mockCorrectErrorMessage diff --git a/Tests/Unit/MSFT_xSQLServerSetup.Tests.ps1 b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 similarity index 99% rename from Tests/Unit/MSFT_xSQLServerSetup.Tests.ps1 rename to Tests/Unit/MSFT_SqlSetup.Tests.ps1 index 26d9096c8..a21083628 100644 --- a/Tests/Unit/MSFT_xSQLServerSetup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 @@ -2,8 +2,8 @@ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerSetup' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlSetup' #region HEADER @@ -935,7 +935,7 @@ try Features = 'SQLEngine' } - Describe "xSQLServerSetup\Get-TargetResource" -Tag 'Get' { + Describe "SqlSetup\Get-TargetResource" -Tag 'Get' { #region Setting up TestDrive:\ # Local path to TestDrive:\ @@ -2262,7 +2262,7 @@ try Assert-VerifiableMock } - Describe "xSQLServerSetup\Test-TargetResource" -Tag 'Test' { + Describe "SqlSetup\Test-TargetResource" -Tag 'Test' { #region Setting up TestDrive:\ # Local path to TestDrive:\ @@ -2884,7 +2884,7 @@ try Assert-VerifiableMock } - Describe "xSQLServerSetup\Set-TargetResource" -Tag 'Set' { + Describe "SqlSetup\Set-TargetResource" -Tag 'Set' { #region Setting up TestDrive:\ # Local path to TestDrive:\ diff --git a/Tests/Unit/MSFT_xWaitForAvailabilityGroup.Tests.ps1 b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 similarity index 96% rename from Tests/Unit/MSFT_xWaitForAvailabilityGroup.Tests.ps1 rename to Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 index 42a9d2beb..226dd6a65 100644 --- a/Tests/Unit/MSFT_xWaitForAvailabilityGroup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWaitForAG.Tests.ps1 @@ -1,5 +1,5 @@ -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xWaitForAvailabilityGroup' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlWaitForAG' #region HEADER @@ -78,7 +78,7 @@ try RetryCount = $mockRetryCount } - Describe 'MSFT_xWaitForAvailabilityGroup\Get-TargetResource' -Tag 'Get' { + Describe 'MSFT_SqlWaitForAG\Get-TargetResource' -Tag 'Get' { BeforeEach { $testParameters = $mockDefaultParameters.Clone() @@ -142,7 +142,7 @@ try } - Describe 'MSFT_xWaitForAvailabilityGroup\Test-TargetResource' -Tag 'Test'{ + Describe 'MSFT_SqlWaitForAG\Test-TargetResource' -Tag 'Test'{ BeforeEach { $testParameters = $mockDefaultParameters.Clone() @@ -191,7 +191,7 @@ try Assert-VerifiableMock } - Describe 'MSFT_xWaitForAvailabilityGroup\Set-TargetResource' -Tag 'Set'{ + Describe 'MSFT_SqlWaitForAG\Set-TargetResource' -Tag 'Set'{ BeforeEach { $testParameters = $mockDefaultParameters.Clone() diff --git a/Tests/Unit/MSFT_xSQLServerFirewall.Tests.ps1 b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 similarity index 99% rename from Tests/Unit/MSFT_xSQLServerFirewall.Tests.ps1 rename to Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 index 9eefeee7b..d92e485d8 100644 --- a/Tests/Unit/MSFT_xSQLServerFirewall.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlWindowsFirewall.Tests.ps1 @@ -2,8 +2,8 @@ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param() -$script:DSCModuleName = 'xSQLServer' -$script:DSCResourceName = 'MSFT_xSQLServerFirewall' +$script:DSCModuleName = 'SqlServerDsc' +$script:DSCResourceName = 'MSFT_SqlWindowsFirewall' #region HEADER @@ -405,7 +405,7 @@ try SourceCredential = $mockSourceCredential } - Describe "xSQLServerFirewall\Get-TargetResource" -Tag 'Get' { + Describe "SqlWindowsFirewall\Get-TargetResource" -Tag 'Get' { # Local path to TestDrive:\ $mockSourcePath = $TestDrive.FullName @@ -951,7 +951,7 @@ try } } - Describe "xSQLServerFirewall\Set-TargetResource" -Tag 'Set' { + Describe "SqlWindowsFirewall\Set-TargetResource" -Tag 'Set' { # Local path to TestDrive:\ $mockSourcePath = $TestDrive.FullName @@ -1192,7 +1192,7 @@ try } } - Describe "xSQLServerFirewall\Test-TargetResource" -Tag 'Test' { + Describe "SqlWindowsFirewall\Test-TargetResource" -Tag 'Test' { # Local path to TestDrive:\ $mockSourcePath = $TestDrive.FullName diff --git a/Tests/Unit/xSQLServerHelper.Tests.ps1 b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 similarity index 99% rename from Tests/Unit/xSQLServerHelper.Tests.ps1 rename to Tests/Unit/SqlServerDSCHelper.Tests.ps1 index e8fb6d30b..8f2cdd52c 100644 --- a/Tests/Unit/xSQLServerHelper.Tests.ps1 +++ b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 @@ -4,7 +4,7 @@ param () # Unit Test Template Version: 1.1.0 -$script:moduleName = 'xSQLServerHelper' +$script:moduleName = 'SqlServerDscHelper' [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` @@ -14,7 +14,7 @@ if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCR } Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -Import-Module (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath 'xSQLServerHelper.psm1') -Scope Global -Force +Import-Module (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent | Split-Path -Parent) -ChildPath 'SqlServerDscHelper.psm1') -Scope Global -Force # Loading mocked classes Add-Type -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SMO.cs ) @@ -786,7 +786,7 @@ InModuleScope $script:moduleName { Assert-VerifiableMock } - $mockApplicationDomainName = 'xSQLServerHelperTests' + $mockApplicationDomainName = 'SqlServerDscHelperTests' $mockApplicationDomainObject = [System.AppDomain]::CreateDomain($mockApplicationDomainName) <# @@ -836,7 +836,7 @@ InModuleScope $script:moduleName { } -Verifiable Mock -CommandName Register-SqlSmo -MockWith { - [System.AppDomain]::CreateDomain('xSQLServerHelper') + [System.AppDomain]::CreateDomain('SqlServerDscHelper') } -ParameterFilter { $SQLInstanceName -eq $mockInstanceName } -Verifiable diff --git a/Tests/Unit/Stubs/SMO.cs b/Tests/Unit/Stubs/SMO.cs index 00e4789d1..9155fc29e 100644 --- a/Tests/Unit/Stubs/SMO.cs +++ b/Tests/Unit/Stubs/SMO.cs @@ -14,7 +14,7 @@ namespace Microsoft.SqlServer.Management.Smo // TypeName: Microsoft.SqlServer.Management.Smo.LoginCreateOptions // Used by: - // MSFT_xSQLServerLogin.Tests.ps1 + // MSFT_SqlServerLogin.Tests.ps1 public enum LoginCreateOptions { None = 0, @@ -25,7 +25,7 @@ public enum LoginCreateOptions // TypeName: Microsoft.SqlServer.Management.Smo.LoginType // BaseType: Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase // Used by: - // MSFT_xSQLServerLogin + // MSFT_SqlServerLogin public enum LoginType { AsymmetricKey = 4, @@ -60,7 +60,7 @@ public enum AvailabilityReplicaAvailabilityMode // TypeName: Microsoft.SqlServer.Management.Smo.EndpointType // Used by: - // xSQLServerEndpoint + // SqlServerEndpoint public enum EndpointType { DatabaseMirroring, @@ -71,7 +71,7 @@ public enum EndpointType // TypeName: Microsoft.SqlServer.Management.Smo.ProtocolType // Used by: - // xSQLServerEndpoint + // SqlServerEndpoint public enum ProtocolType { Http, @@ -83,7 +83,7 @@ public enum ProtocolType // TypeName: Microsoft.SqlServer.Management.Smo.ServerMirroringRole // Used by: - // xSQLServerEndpoint + // SqlServerEndpoint public enum ServerMirroringRole { All, @@ -94,7 +94,7 @@ public enum ServerMirroringRole // TypeName: Microsoft.SqlServer.Management.Smo.EndpointEncryption // Used by: - // xSQLServerEndpoint + // SqlServerEndpoint public enum EndpointEncryption { Disabled, @@ -104,7 +104,7 @@ public enum EndpointEncryption // TypeName: Microsoft.SqlServer.Management.Smo.EndpointEncryptionAlgorithm // Used by: - // xSQLServerEndpoint + // SqlServerEndpoint public enum EndpointEncryptionAlgorithm { Aes, @@ -127,7 +127,7 @@ public class Globals // Typename: Microsoft.SqlServer.Management.Smo.ObjectPermissionSet // BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase // Used by: - // xSQLServerEndpointPermission.Tests.ps1 + // SqlServerEndpointPermission.Tests.ps1 public class ObjectPermissionSet { public ObjectPermissionSet(){} @@ -144,7 +144,7 @@ public ObjectPermissionSet( // TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionSet // BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase // Used by: - // xSQLServerPermission.Tests.ps1 + // SqlServerPermission.Tests.ps1 public class ServerPermissionSet { public ServerPermissionSet(){} @@ -170,7 +170,7 @@ public ServerPermissionSet( // TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionInfo // BaseType: Microsoft.SqlServer.Management.Smo.PermissionInfo // Used by: - // xSQLServerPermission.Tests.ps1 + // SqlServerPermission.Tests.ps1 public class ServerPermissionInfo { public ServerPermissionInfo() @@ -192,7 +192,7 @@ public ServerPermissionInfo( // TypeName: Microsoft.SqlServer.Management.Smo.DatabasePermissionSet // BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase // Used by: - // xSQLServerDatabasePermission.Tests.ps1 + // SqlDatabasePermission.Tests.ps1 public class DatabasePermissionSet { public DatabasePermissionSet(){} @@ -210,7 +210,7 @@ public DatabasePermissionSet( bool connect, bool update ) // TypeName: Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo // BaseType: Microsoft.SqlServer.Management.Smo.PermissionInfo // Used by: - // xSQLServerDatabasePermission.Tests.ps1 + // SqlDatabasePermission.Tests.ps1 public class DatabasePermissionInfo { public DatabasePermissionInfo() @@ -231,8 +231,8 @@ public DatabasePermissionInfo( Microsoft.SqlServer.Management.Smo.DatabasePermis // TypeName: Microsoft.SqlServer.Management.Smo.Server // BaseType: Microsoft.SqlServer.Management.Smo.SqlSmoObject // Used by: - // xSQLServerPermission - // MSFT_xSQLServerLogin + // SqlServerPermission + // MSFT_SqlServerLogin public class Server { public string MockGranteeName; @@ -340,7 +340,7 @@ public void Revoke( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permi // TypeName: Microsoft.SqlServer.Management.Smo.Login // BaseType: Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase // Used by: - // MSFT_xSQLServerLogin + // MSFT_SqlServerLogin public class Login { private bool _mockPasswordPassed = false; @@ -524,7 +524,7 @@ public void Drop() // TypeName: Microsoft.SqlServer.Management.Smo.ServerRole // BaseType: Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase // Used by: - // MSFT_xSQLServerRole + // MSFT_SqlServerRole public class ServerRole { public ServerRole( Server server, string name ) { @@ -542,9 +542,9 @@ public ServerRole( Object server, string name ) { // TypeName: Microsoft.SqlServer.Management.Smo.Database // BaseType: Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase // Used by: - // MSFT_xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership - // MSFT_xSQLServerDatabase - // MSFT_xSQLServerDatabasePermission + // MSFT_SqlAGDatabase + // MSFT_SqlDatabase + // MSFT_SqlDatabasePermission public class Database { public bool AutoClose = false; @@ -630,7 +630,7 @@ public void Deny( Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permi // TypeName: Microsoft.SqlServer.Management.Smo.User // BaseType: Microsoft.SqlServer.Management.Smo.ScriptNameObjectBase // Used by: - // xSQLServerDatabaseRole.Tests.ps1 + // SqlDatabaseRole.Tests.ps1 public class User { public User( Server server, string name ) @@ -697,7 +697,7 @@ public FailedOperationException (string message, SmoException inner) : base (mes // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroup // BaseType: Microsoft.SqlServer.Management.Smo.NamedSmoObject // Used by: - // xSQLServerAlwaysOnAvailabilityGroup + // SqlAG public class AvailabilityGroup { public AvailabilityGroup() @@ -748,7 +748,7 @@ public AvailabilityGroup Clone() // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityReplica // BaseType: Microsoft.SqlServer.Management.Smo.NamedSmoObject // Used by: - // xSQLServerAlwaysOnAvailabilityGroup + // SqlAG public class AvailabilityReplica { public AvailabilityReplica() @@ -782,7 +782,7 @@ public void Create() // TypeName: Microsoft.SqlServer.Management.Common.ServerConnection // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class ConnectionContext { public string TrueLogin; @@ -793,7 +793,7 @@ public void Create() // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityDatabase // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class AvailabilityDatabase { public string Name; @@ -803,7 +803,7 @@ public void Create() {} // TypeName: Microsoft.SqlServer.Management.Smo.DatabaseCollection // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class DatabaseCollection : Collection { public Database this[string name] @@ -825,7 +825,7 @@ public Database this[string name] // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityReplicaCollection // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class AvailabilityReplicaCollection : Collection { public AvailabilityReplica this[string name] @@ -847,7 +847,7 @@ public AvailabilityReplica this[string name] // TypeName: Microsoft.SqlServer.Management.Smo.DatabaseEncryptionKey // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class DatabaseEncryptionKey { public string EncryptorName; @@ -856,7 +856,7 @@ public class DatabaseEncryptionKey // TypeName: Microsoft.SqlServer.Management.Smo.Certificate // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class Certificate { public byte[] Thumbprint; @@ -864,7 +864,7 @@ public class Certificate // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityDatabaseCollection // Used by: - // xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership + // SqlAGDatabase public class AvailabilityDatabaseCollection : Collection { public AvailabilityDatabase this[string name] @@ -886,7 +886,7 @@ public AvailabilityDatabase this[string name] // TypeName: Microsoft.SqlServer.Management.Smo.AvailabilityGroupCollection // Used by: - // xSQLServerAlwaysOnAvailabilityGroup + // SqlAG public class AvailabilityGroupCollection : Collection { public AvailabilityGroup this[string name] @@ -908,7 +908,7 @@ public AvailabilityGroup this[string name] // TypeName: Microsoft.SqlServer.Management.Smo.Endpoint // Used by: - // xSQLServerAlwaysOnAvailabilityGroup + // SqlAG public class Endpoint { public string Name; @@ -918,7 +918,7 @@ public class Endpoint // TypeName: Microsoft.SqlServer.Management.Smo.EndpointCollection // Used by: - // xSQLServerAlwaysOnAvailabilityGroup + // SqlAG public class EndpointCollection : Collection { public Endpoint this[string name] @@ -947,7 +947,7 @@ namespace Microsoft.SqlServer.Management.Smo.Wmi // TypeName: Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType // Used by: - // MSFT_xSQLServerServiceAccount.Tests.ps1 + // MSFT_SqlServiceAccount.Tests.ps1 public enum ManagedServiceType { SqlServer = 1, diff --git a/Tests/Unit/Stubs/Write-ModuleStubFile.ps1 b/Tests/Unit/Stubs/Write-ModuleStubFile.ps1 index 2c4eee0c3..f62c2d74c 100644 --- a/Tests/Unit/Stubs/Write-ModuleStubFile.ps1 +++ b/Tests/Unit/Stubs/Write-ModuleStubFile.ps1 @@ -1,29 +1,29 @@ <# .SYNOPSIS - Generates a file contaning function stubs of all cmdlets from the module given as a parameter. + Generates a file contaning function stubs of all cmdlets from the module given as a parameter. .PARAMETER ModuleName The name of the module to load and generate stubs from. This module must exist on the computer where this function is ran. .PARAMETER Path - Path to where to write the stubs file. The filename will be generated from the module name. + Path to where to write the stubs file. The filename will be generated from the module name. .EXAMPLE - Write-ModuleStubFile -ModuleName 'SQLServer' -Path 'C:\Source' + Write-ModuleStubFile -ModuleName 'SqlServer' -Path 'C:\Source' #> function Write-ModuleStubFile { param ( - [Parameter( Mandatory )] + [Parameter( Mandatory )] [System.String] $ModuleName, - [Parameter( Mandatory )] + [Parameter( Mandatory )] [System.String] $Path ) Import-Module $ModuleName -DisableNameChecking -Force - - ( ( get-command -Module $ModuleName -CommandType 'Cmdlet' ) | ForEach-Object -Begin { + + ( ( get-command -Module $ModuleName -CommandType 'Cmdlet' ) | ForEach-Object -Begin { "# Suppressing this rule because these functions are from an external module" "# and are only being used as stubs", "[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUserNameAndPassWordParams', '')]" @@ -34,7 +34,7 @@ function Write-ModuleStubFile { $command = $_ $endOfDefinition = $false $metadata = New-Object -TypeName System.Management.Automation.CommandMetaData -ArgumentList $command - $definition = [System.Management.Automation.ProxyCommand]::Create($metadata) + $definition = [System.Management.Automation.ProxyCommand]::Create($metadata) foreach ($line in $definition -split "`n") { $line = $line -replace '\[Microsoft.SqlServer.*.\]', '[object]' @@ -45,7 +45,7 @@ function Write-ModuleStubFile { $line = $line.Remove( $line.Length - 2 ) $endOfDefinition = $true } - + if( $line.Trim() -ne '' ) { $signature += " $line" } else { @@ -58,7 +58,7 @@ function Write-ModuleStubFile { break } } - + "function $($command.Name) {" "$signature" "" diff --git a/appveyor.yml b/appveyor.yml index bbd5098b9..d890750f8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ #---------------------------------# # environment configuration # #---------------------------------# -version: 6.0.{build}.0 +version: 9.0.{build}.0 image: Visual Studio 2017 install: - git clone https://github.com/PowerShell/DscResource.Tests diff --git a/en-US/xSQLServerHelper.strings.psd1 b/en-US/SqlServerDscHelper.strings.psd1 similarity index 98% rename from en-US/xSQLServerHelper.strings.psd1 rename to en-US/SqlServerDscHelper.strings.psd1 index 58c7a27af..2f940d248 100644 --- a/en-US/xSQLServerHelper.strings.psd1 +++ b/en-US/SqlServerDscHelper.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for helper module xSQLServerHelper. +# Localized resources for helper module SqlServerDscHelper. ConvertFrom-StringData @' ConnectedToDatabaseEngineInstance = Connected to SQL instance '{0}'. @@ -17,7 +17,7 @@ ConvertFrom-StringData @' PropertiesDoesNotMatch = Found an array for property {0} in the current values, but this array does not match the desired state. Details of the changes are below. PropertyThatDoesNotMatch = {0} - {1} ValueOfTypeDoesNotMatch = {0} value for property {1} does not match. Current state is '{2}' and desired state is '{3}'. - UnableToCompareProperty = Unable to compare property {0} as the type {1} is not handled by the Test-SQLDscParameterState cmdlet. + UnableToCompareProperty = Unable to compare property {0} as the type {1} is not handled by the Test-SQLDSCParameterState cmdlet. PreferredModuleFound = Preferred module SqlServer found. PreferredModuleNotFound = Information: PowerShell module SqlServer not found, trying to use older SQLPS module. ImportingPowerShellModule = Importing PowerShell module {0}. @@ -46,7 +46,7 @@ ConvertFrom-StringData @' # - NOTE! # - Below strings are used by helper functions New-TerminatingError and New-WarningMessage. - # - These strings were merged from old xSQLServer.strings.psd1. These will be moved to it's individual + # - These strings were merged from old SqlServerDsc.strings.psd1. These will be moved to it's individual # - resource when that resources get moved over to the new localization. # - NOTE! diff --git a/sv-SE/xSQLServerHelper.strings.psd1 b/sv-SE/SqlServerDscHelper.strings.psd1 similarity index 98% rename from sv-SE/xSQLServerHelper.strings.psd1 rename to sv-SE/SqlServerDscHelper.strings.psd1 index 78ac75278..947a96889 100644 --- a/sv-SE/xSQLServerHelper.strings.psd1 +++ b/sv-SE/SqlServerDscHelper.strings.psd1 @@ -1,4 +1,4 @@ -# Swedish localized resources for helper module xSQLServerHelper. +# Swedish localized resources for helper module SqlServerDscHelper. ConvertFrom-StringData @' ConnectedToDatabaseEngineInstance = Ansluten till SQL instans '{0}'. @@ -41,7 +41,7 @@ ConvertFrom-StringData @' # - NOTE! # - Below strings are used by helper functions New-TerminatingError and New-WarningMessage. - # - These strings were merged from old xSQLServer.strings.psd1. These will be moved to it's individual + # - These strings were merged from old SqlServerDsc.strings.psd1. These will be moved to it's individual # - resource when that resources get moved over to the new localization. # - NOTE! diff --git a/xSQLServer.psd1 b/xSQLServer.psd1 deleted file mode 100644 index 53c0f0e7a..000000000 --- a/xSQLServer.psd1 +++ /dev/null @@ -1,128 +0,0 @@ -@{ -# Version number of this module. -ModuleVersion = '9.0.0.0' - -# ID used to uniquely identify this module -GUID = '74e9ddb5-4cbc-4fa2-a222-2bcfb533fd66' - -# Author of this module -Author = 'Microsoft Corporation' - -# Company or vendor of this module -CompanyName = 'Microsoft Corporation' - -# Copyright statement for this module -Copyright = '(c) 2017 Microsoft Corporation. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Module with DSC Resources for deployment and configuration of Microsoft SQL Server.' - -# Minimum version of the Windows PowerShell engine required by this module -PowerShellVersion = '5.0' - -# Minimum version of the common language runtime (CLR) required by this module -CLRVersion = '4.0' - -# Functions to export from this module -FunctionsToExport = '*' - -# Cmdlets to export from this module -CmdletsToExport = '*' - -RequiredAssemblies = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/PowerShell/xSQLServer/blob/master/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/PowerShell/xSQLServer' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - ReleaseNotes = '- Changes to xSQLServer - - Updated Pester syntax to v4 - - Fixes broken links to issues in the CHANGELOG.md. -- Changes to xSQLServerDatabase - - Added parameter to specify collation for a database to be different from server - collation ([issue 767](https://github.com/PowerShell/xSQLServer/issues/767)). - - Fixed unit tests for Get-TargetResource to ensure correctly testing return - values ([issue 849](https://github.com/PowerShell/xSQLServer/issues/849)) -- Changes to xSQLServerAlwaysOnAvailabilityGroup - - Refactored the unit tests to allow them to be more user friendly and to test - additional SQLServer variations. - - Each test will utilize the Import-SQLModuleStub to ensure the correct - module is loaded ([issue 784](https://github.com/PowerShell/xSQLServer/issues/784)). - - Fixed an issue when setting the SQLServer parameter to a Fully Qualified - Domain Name (FQDN) ([issue 468](https://github.com/PowerShell/xSQLServer/issues/468)). - - Fixed the logic so that if a parameter is not supplied to the resource, the - resource will not attempt to apply the defaults on subsequent checks - ([issue 517](https://github.com/PowerShell/xSQLServer/issues/517)). - - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, - the resource will only determine if a change is needed if the target node - is the active host of the SQL Server instance ([issue 868](https://github.com/PowerShell/xSQLServer/issues/868)). -- Changes to xSQLServerAlwaysOnAvailabilityGroupDatabaseMembership - - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, - the resource will only determine if a change is needed if the target node - is the active host of the SQL Server instance ([issue 869](https://github.com/PowerShell/xSQLServer/issues/869)). -- Changes to xSQLServerAlwaysOnAvailabilityGroupReplica - - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, - the resource will only determine if a change is needed if the target node is - the active host of the SQL Server instance ([issue 870](https://github.com/PowerShell/xSQLServer/issues/870)). -- Added the CommonTestHelper.psm1 to store common testing functions. - - Added the Import-SQLModuleStub function to ensure the correct version of the - module stubs are loaded ([issue 784](https://github.com/PowerShell/xSQLServer/issues/784)). -- Changes to xSQLServerMemory - - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, - the resource will only determine if a change is needed if the target node - is the active host of the SQL Server instance ([issue 867](https://github.com/PowerShell/xSQLServer/issues/867)). -- Changes to xSQLServerNetwork - - BREAKING CHANGE: Renamed parameter TcpDynamicPorts to TcpDynamicPort and - changed type to Boolean ([issue 534](https://github.com/PowerShell/xSQLServer/issues/534)). - - Resolved issue when switching from dynamic to static port. - configuration ([issue 534](https://github.com/PowerShell/xSQLServer/issues/534)). - - Added localization (en-US) for all strings in resource and unit tests - ([issue 618](https://github.com/PowerShell/xSQLServer/issues/618)). - - Updated examples to reflect new parameters. -- Changes to xSQLServerRSConfig - - Added examples -- Added resource - - xSQLServerDatabaseDefaultLocation - ([issue 656](https://github.com/PowerShell/xSQLServer/issues/656)) -- Changes to xSQLServerEndpointPermission - - Fixed a problem when running the tests locally in a PowerShell console it - would ask for parameters ([issue 897](https://github.com/PowerShell/xSQLServer/issues/897)). -- Changes to xSQLServerAvailabilityGroupListener - - Fixed a problem when running the tests locally in a PowerShell console it - would ask for parameters ([issue 897](https://github.com/PowerShell/xSQLServer/issues/897)). -- Changes to xSQLServerMaxDop - - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, - the resource will only determine if a change is needed if the target node - is the active host of the SQL Server instance ([issue 882](https://github.com/PowerShell/xSQLServer/issues/882)). - -' - - } # End of PSData hashtable - -} # End of PrivateData hashtable -} - - - - - - - - - - -