diff --git a/CHANGELOG.md b/CHANGELOG.md index 926a6694b..92e71f81e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,66 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) ### Changed -- BREAKING CHANGE: Database changed to DatabaseName for consistency with other modules. - ([issue #1484](https://github.com/dsccommunity/SqlServerDsc/issues/1484)). - - SqlDatabaseOwner - - SqlDatabasePermission - - SqlDatabaseRole - +- SqlAlwaysOnService + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlDatabase + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlDatabaseDefaultLocation + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlDatabaseOwner + - BREAKING CHANGE: Database changed to DatabaseName for consistency with + other modules ([issue #1484](https://github.com/dsccommunity/SqlServerDsc/issues/1484)). +- SqlDatabasePermission + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. + - BREAKING CHANGE: Database changed to DatabaseName for consistency with + other modules ([issue #1484](https://github.com/dsccommunity/SqlServerDsc/issues/1484)). +- SqlDatabaseRecoveryModel + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlDatabaseRole + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. + - BREAKING CHANGE: Database changed to DatabaseName for consistency with + other modules ([issue #1484](https://github.com/dsccommunity/SqlServerDsc/issues/1484)). +- SqlDatabaseUser + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlServerConfiguration + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlServerDatabaseMail + - Normalize parameter descriptive text for default values. +- SqlServerEndpoint + - Normalize parameter descriptive text for default values. +- SqlServerEndpointPermission + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlServerLogin + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlServerRole + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. +- SqlServiceAccount + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory and + defaults to `$env:COMPUTERNAME` ([issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). + - Normalize parameter descriptive text for default values. + ### Fixed - SqlServerDsc @@ -47,6 +101,38 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - README.md - Changed to point to CONTRIBUTING.md on master branch to avoid "404 Page not found" ([issue #1508](https://github.com/dsccommunity/SqlServerDsc/issues/1508)). +- SqlAlias + - BREAKING CHANGE: The parameter `ServerName` is now non-mandatory to + prevent ping-pong behavior ([issue #1502](https://github.com/dsccommunity/SqlServerDsc/issues/1502)). + The `ServerName` is not returned as an empty string when the protocol is + Named Pipes. +- SqlRs + - Fix typo in the schema parameter `SuppressRestart` description + and in the parameter description in the `README.md`. +- SqlSetup + - Update integration tests to correctly detect sysadmins because of changes + to the build worker. +- SqlAgentAlert + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlAgentFailsafe + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlAgentOperator + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlServerDatabaseMail + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlServerEndpoint + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlServerEndpointState + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). +- SqlServerPermission + - The parameter `ServerName` now throws when passing an empty string or + null value (part of [issue #319](https://github.com/dsccommunity/SqlServerDsc/issues/319)). ## [13.5.0] - 2020-04-12 diff --git a/README.md b/README.md index f8b7b09d1..3874099ce 100644 --- a/README.md +++ b/README.md @@ -509,7 +509,7 @@ No description. #### Parameters * **`[String]` Name** _(Key)_: The name of Alias (e.g. svr01\inst01). -* **`[String]` ServerName** _(Key)_: The SQL Server you are aliasing (the NetBIOS +* **`[String]` ServerName** _(Write)_: 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 }. @@ -547,11 +547,12 @@ Enables or disabled SQL Server Always On high availability and disaster recovery #### Parameters -* **`[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 }. +* **`[String]` ServerName** _(Write)_: The hostname of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[SInt32]` RestartTimeout** _(Write)_: The length of time, in seconds, to wait for the service to restart. Default is 120 seconds. @@ -582,11 +583,12 @@ and [Delete a Database](https://docs.microsoft.com/en-us/sql/relational-database #### Parameters -* **`[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]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[String]` Collation** _(Write)_: The name of the SQL collation to use - for the new database. Defaults to server collation. + for the new database. Default value is server collation. * **`[String]` Ensure** _(Write)_: When set to 'Present', the database will be created. When set to 'Absent', the database will be dropped. { *Present* | Absent }. @@ -613,12 +615,13 @@ more information about database default locations, please read the article #### Parameters -* **`[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 } * **`[String]` Path** _(Required)_: The path to the default directory to be configured. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[Boolean]` RestartService** _(Write)_: If set to $true then SQL Server and dependent services will be restarted if a change to the configuration is made. The default value is $false. @@ -683,10 +686,8 @@ will also get their permission revoked. #### Parameters -* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured. - Default values is '$env:COMPUTERNAME'. * **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured. - Default value is 'MSSQLSERVER'. + Default value is `'MSSQLSERVER'`. * **`[String]` DatabaseName** _(Key)_: The name of the database. * **`[String]` Name** _(Key)_: The name of the user that should be granted or denied the permission. @@ -695,6 +696,8 @@ will also get their permission revoked. * **`[String[]]` Permissions** _(Required)_: The permissions to be granted or denied for the user in the database. Valid permissions can be found in the article [SQL Server Permissions](https://msdn.microsoft.com/en-us/library/ms191291.aspx#Anchor_3). +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default values is `$env:COMPUTERNAME`. * **`[String]` Ensure** _(Write)_: If the permission should be granted (Present) or revoked (Absent). { Present | Absent }. @@ -725,10 +728,11 @@ Read more about recovery model in this article #### Parameters * **`[String]` Name** _(Key)_: The SQL database name. -* **`[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 }. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. #### Examples @@ -751,11 +755,12 @@ manages members in both built-in and user created database roles. #### Parameters -* **`[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]` DatabaseName** _(Key)_: The name of the database in which the role should be configured. * **`[String]` Name** _(Key)_: The name of the database role to be added or removed. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[String[]]` Members** _(Write)_: The members the database role should have. This parameter will replace all the current database role members with the specified members. Can only be used when parameter Ensure is set to 'Present'. @@ -807,12 +812,12 @@ SQL login. * **`[String]` Name** _(Key)_: Specifies the name of the database user to be added or removed. -* **`[String]` ServerName** _(Key)_: Specifies the host name of the SQL - Server on which the instance exist. * **`[String]` InstanceName** _(Key)_: Specifies the SQL instance in which the database exist. * **`[String]` DatabaseName** _(Key)_: Specifies the name of the database in which to configure the user. +* **`[String]` ServerName** _(Write)_: Specifies the host name of the SQL + Server on which the instance exist. Default value is `$env:COMPUTERNAME`. * **`[String]` LoginName** _(Write)_: Specifies the name of the SQL login to associate with the database user. This must be specified if parameter UserType is set to 'Login'. @@ -824,15 +829,15 @@ SQL login. if parameter UserType is set to 'Certificate'. * **`[String]` UserType** _(Write)_: Specifies the type of the database user. Valid values are 'Login', 'NoLogin', 'Certificate', or 'AsymmetricKey'. - Defaults to 'NoLogin'. { Login | *NoLogin* | Certificate | AsymmetricKey }. + Default value is 'NoLogin'. { Login | *NoLogin* | Certificate | AsymmetricKey }. * **`[String]` Ensure** _(Write)_: Specifies if the database user should be present or absent. If 'Present' then the database user will be added to the database and, if needed, the login mapping will be updated. If 'Absent' then the database user will be removed from the database. - Defaults to 'Present'. { *Present* | Absent }. + Default value is 'Present'. { *Present* | Absent }. * **`[Boolean]` Force** _(Write)_: Specifies if the resource is allowed to re-create the database user if either the user type, the asymmetric - key, or the certificate changes. Defaults to $false not allowing + key, or the certificate changes. Default value is $false not allowing database users to be re-created. #### Read-Only Properties from Get-TargetResource @@ -896,7 +901,7 @@ Initializes and configures SQL Reporting Services server. Services does not use SSL. * **`[Boolean]` SuppressRestart** _(Write)_: Reporting Services need to be restarted after initialization or settings change. If this parameter is set to $true, - Reporting Services will not be restarted, even after initialisation. + Reporting Services will not be restarted, even after initialization. #### Read-Only Properties from Get-TargetResource @@ -1199,13 +1204,14 @@ on a SQL Server instance. #### Parameters -* **`[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. +* **`[String]` ServerName** _(Write)_: The hostname of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[Boolean]` RestartService** _(Write)_: Determines whether the instance should be restarted after updating the configuration option. * **`[UInt32]` RestartTimeout** _(Write)_: The length of time, in seconds, to wait @@ -1237,7 +1243,7 @@ Resource to manage SQL Server Database Mail. * **`[String]` AccountName** _(Key)_: The name of the Database Mail account. * **`[String]` ServerName** _(Write)_: The hostname of the SQL Server to be configured. - Defaults to $env:COMPUTERNAME. + Default value is `$env:COMPUTERNAME`. * **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. * **`[String]` Ensure** _(Write)_: Specifies the desired state of the Database Mail. When set to 'Present', the Database Mail will be created. When set to 'Absent', @@ -1301,7 +1307,7 @@ the resource [**SqlServerEndpointPermission**](#sqlserverendpointpermission). 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. + on. Default value is '0.0.0.0' which means listen on any valid IP address. * **`[String]` Owner** _(Write)_: The owner of the endpoint. Default is the login used for the creation. @@ -1327,11 +1333,12 @@ This resource is used to give connect permission to an endpoint for a user (logi #### 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]` Principal** _(Key)_: The login to which permission will be set. +* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[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 }. @@ -1392,9 +1399,10 @@ No description. #### Parameters -* **`[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]` InstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` ServerName** _(Write)_:The hostname of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[String]` Ensure** _(Write)_: The specified login is Present or Absent. { *Present* | Absent }. * **`[PSCredential]` LoginCredential** _(Write)_: If LoginType is 'SqlLogin' then @@ -1701,8 +1709,9 @@ server roles, please read the below articles. #### Parameters * **`[String]` ServerRoleName** _(Key)_: The name of of SQL role to add or remove. -* **`[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]` ServerName** _(Write)_: The host name of the SQL Server to be configured. + Default value is `$env:COMPUTERNAME`. * **`[String]` Ensure** _(Write)_: An enumerated value that describes if the server role is added (Present) or dropped (Absent). Default value is 'Present'. { *Present* | Absent }. @@ -1762,7 +1771,7 @@ In that case, the 'SYSTEM' service account can be used. connection error is displayed. Use the "SYSTEM" account instead, in that case. * **`[String]` Ensure** _(Write)_: If Encryption should be Enabled (Present) - or Disabled (Absent). { *Present* | Absent }. Defaults to Present. + or Disabled (Absent). { *Present* | Absent }. Default value is Present. * **`[Boolean]` ForceEncryption** _(Write)_: If all connections to the SQL instance should be encrypted. If this parameter is not assigned a value, the default is, set to *True*, that all connections must be encrypted. @@ -1793,13 +1802,14 @@ Manage the service account for SQL Server services. #### Parameters * **`[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 } * **`[PSCredential]` ServiceAccount** (Required): The service account that should be used when running the service. +* **`[String]` InstanceName** (Write): The name of the SQL instance to be configured. + Default value is `$env:COMPUTERNAME`. * **`[Boolean]` RestartService** (Write): Determines whether the service is automatically restarted when a change to the configuration was needed. * **`[Boolean]` Force** (Write): Forces the service account to be updated. @@ -1918,7 +1928,7 @@ with different sizes and growths. #### Parameters -* **`[String]` Action** _(Write)_: The action to be performed. Defaults to 'Install'. +* **`[String]` Action** _(Write)_: The action to be performed. Default value is 'Install'. *Note: AddNode is not currently functional.* { _Install_ | InstallFailoverCluster | AddNode | PrepareFailoverCluster | CompleteFailoverCluster } diff --git a/source/DSCResources/MSFT_SqlAgentAlert/MSFT_SqlAgentAlert.psm1 b/source/DSCResources/MSFT_SqlAgentAlert/MSFT_SqlAgentAlert.psm1 index d2ab6b90c..e9759c15a 100644 --- a/source/DSCResources/MSFT_SqlAgentAlert/MSFT_SqlAgentAlert.psm1 +++ b/source/DSCResources/MSFT_SqlAgentAlert/MSFT_SqlAgentAlert.psm1 @@ -32,6 +32,7 @@ function Get-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -127,6 +128,7 @@ function Set-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -313,6 +315,7 @@ function Test-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlAgentFailsafe/MSFT_SqlAgentFailsafe.psm1 b/source/DSCResources/MSFT_SqlAgentFailsafe/MSFT_SqlAgentFailsafe.psm1 index 7e1bcc8e6..4f87a1cfb 100644 --- a/source/DSCResources/MSFT_SqlAgentFailsafe/MSFT_SqlAgentFailsafe.psm1 +++ b/source/DSCResources/MSFT_SqlAgentFailsafe/MSFT_SqlAgentFailsafe.psm1 @@ -31,6 +31,7 @@ function Get-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -122,6 +123,7 @@ function Set-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -243,6 +245,7 @@ function Test-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlAgentOperator/MSFT_SqlAgentOperator.psm1 b/source/DSCResources/MSFT_SqlAgentOperator/MSFT_SqlAgentOperator.psm1 index ccef3f7d4..870aabf3c 100644 --- a/source/DSCResources/MSFT_SqlAgentOperator/MSFT_SqlAgentOperator.psm1 +++ b/source/DSCResources/MSFT_SqlAgentOperator/MSFT_SqlAgentOperator.psm1 @@ -33,6 +33,7 @@ function Get-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -123,6 +124,7 @@ function Set-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -263,6 +265,7 @@ function Test-TargetResource $Name, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 b/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 index 29950137f..d211cd9c2 100644 --- a/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 +++ b/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.psm1 @@ -15,18 +15,13 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ServerName + $Name ) $returnValue = @{ Name = [System.String] $Name Protocol = [System.String] '' - ServerName = [System.String] $ServerName + ServerName = [System.String] $null TcpPort = [System.UInt16] 0 UseDynamicTcpPort = [System.Boolean] $false PipeName = [System.String] '' @@ -114,7 +109,7 @@ function Set-TargetResource [System.String] $Protocol = 'TCP', - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $ServerName, @@ -219,7 +214,7 @@ function Test-TargetResource [System.String] $Protocol = 'TCP', - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $ServerName, @@ -246,7 +241,6 @@ function Test-TargetResource $parameters = @{ Name = $PSBoundParameters.Name - ServerName = $PSBoundParameters.ServerName } $currentValues = Get-TargetResource @parameters diff --git a/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof b/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof index 2878dc822..d23de2f90 100644 --- a/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof +++ b/source/DSCResources/MSFT_SqlAlias/MSFT_SqlAlias.schema.mof @@ -3,9 +3,9 @@ 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; - [Key, Description("The SQL Server you are aliasing (the NetBIOS name or FQDN).")] String ServerName; + [Write, Description("The SQL Server you are aliasing (the NetBIOS name or FQDN).")] String ServerName; [Write, Description("The TCP port SQL is listening on. Only used when protocol is set to 'TCP'. Default value is port 1433.")] UInt16 TcpPort; [Write, Description("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'.")] Boolean UseDynamicTcpPort; - [Read, Description("Named Pipes path from the Get-TargetResource method.")] String PipeName; [Write, Description("Determines whether the alias should be added or removed. Default value is 'Present'"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Read, Description("Named Pipes path from the Get-TargetResource method.")] String PipeName; }; diff --git a/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 b/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 index a9dae13d6..3848883e9 100644 --- a/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 +++ b/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 @@ -19,7 +19,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlAlwaysOnService *** Not used in this function *** .PARAMETER ServerName - The hostname of the SQL Server to be configured. + The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -35,9 +35,10 @@ function Get-TargetResource [System.String] $Ensure, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -75,7 +76,7 @@ function Get-TargetResource disabled ('Absent'). .PARAMETER ServerName - The hostname of the SQL Server to be configured. + The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -93,9 +94,10 @@ function Set-TargetResource [System.String] $Ensure, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -171,7 +173,7 @@ function Set-TargetResource disabled ('Absent'). .PARAMETER ServerName - The hostname of the SQL Server to be configured. + The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -192,9 +194,10 @@ function Test-TargetResource [System.String] $Ensure, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] diff --git a/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof b/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof index 337f1427d..9fd1334f8 100644 --- a/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof +++ b/source/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.schema.mof @@ -1,9 +1,9 @@ [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; + [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; + [Write, Description("The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [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/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 b/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 index 5ef05bb5c..eb6a3a292 100644 --- a/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 +++ b/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.psm1 @@ -29,22 +29,22 @@ $script:supportedCompatibilityLevels = @{ The name of database to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation The name of the SQL collation to use for the new database. - Defaults to server collation. + Default value is server collation. .PARAMETER CompatibilityLevel The version of the SQL compatibility level to use for the new database. - Defaults to server version. + Default value is server version. .PARAMETER RecoveryModel The recovery model to be used for the new database. - Defaults to Full. + Default value is Full. #> function Get-TargetResource @@ -64,10 +64,10 @@ function Get-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -146,22 +146,22 @@ function Get-TargetResource The name of database to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation The name of the SQL collation to use for the new database. - Defaults to server collation. + Default value is server collation. .PARAMETER CompatibilityLevel The version of the SQL compatibility level to use for the new database. - Defaults to server version. + Default value is server version. .PARAMETER RecoveryModel The recovery model to be used for the new database. - Defaults to Full. + Default value is Full. #> function Set-TargetResource { @@ -179,10 +179,10 @@ function Set-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -325,22 +325,22 @@ function Set-TargetResource The name of database to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. .PARAMETER Collation The name of the SQL collation to use for the new database. - Defaults to server collation. + Default value is server collation. .PARAMETER CompatibilityLevel The version of the SQL compatibility level to use for the new database. - Defaults to server version. + Default value is server version. .PARAMETER RecoveryModel The recovery model to be used for the new database. - Defaults to Full. + Default value is Full. #> function Test-TargetResource { @@ -359,10 +359,10 @@ function Test-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof b/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof index 608812f9d..37050ccfa 100644 --- a/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabase/MSFT_SqlDatabase.schema.mof @@ -2,10 +2,10 @@ 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 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; - [Write, Description("The version of the SQL Database Compatibility Level to use for the specified database. Defaults to server version."), ValueMap{"Version80","Version90","Version100","Version110","Version120","Version130","Version140","Version150"}, Values{"Version80","Version90","Version100","Version110","Version120","Version130","Version140","Version150"}] String CompatibilityLevel; - [Write, Description("The recovery model for the specified database. Defaults to Full."), ValueMap{"Simple","Full","BulkLogged"}, Values{"Simple","Full","BulkLogged"}] String RecoveryModel; + [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; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; + [Write, Description("The name of the SQL collation to use for the new database. Default value is server collation.")] String Collation; + [Write, Description("The version of the SQL Database Compatibility Level to use for the specified database. Default value is server version."), ValueMap{"Version80","Version90","Version100","Version110","Version120","Version130","Version140","Version150"}, Values{"Version80","Version90","Version100","Version110","Version120","Version130","Version140","Version150"}] String CompatibilityLevel; + [Write, Description("The recovery model for the specified database. Default value is Full."), ValueMap{"Simple","Full","BulkLogged"}, Values{"Simple","Full","BulkLogged"}] String RecoveryModel; }; diff --git a/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 b/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 index 75b743675..fd90759c4 100644 --- a/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 +++ b/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 @@ -11,7 +11,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseDefault Returns the current path to the the desired default location for the Data, Log, or Backup files. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -29,10 +29,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -91,7 +91,7 @@ function Get-TargetResource This function sets the current path for the default SQL Instance location for the Data, Log, or Backups files. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -115,10 +115,10 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -213,7 +213,7 @@ function Set-TargetResource This function tests the current path to the default database location for the Data, Log, or Backups files. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -237,10 +237,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof b/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof index f49a2d941..84cb76132 100644 --- a/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.schema.mof @@ -1,10 +1,10 @@ [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 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("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [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; [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/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 b/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 index 2621e31da..d14250966 100644 --- a/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 +++ b/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.psm1 @@ -8,25 +8,25 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabasePermiss <# .SYNOPSIS - Returns the current permissions for the user in the database + Returns the current permissions for the user in the database. .PARAMETER DatabaseName This is the SQL database .PARAMETER Name - This is the name of the SQL login for the permission set + This is the name of the SQL login for the permission set. .PARAMETER PermissionState - This is the state of permission set. Valid values are 'Grant' or 'Deny' + This is the state of permission set. Valid values are 'Grant' or 'Deny'. .PARAMETER Permissions - This is a list that represents a SQL Server set of database permissions + This is a list that represents a SQL Server set of database permissions. .PARAMETER ServerName - This is the SQL Server for the database + This is the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is the SQL instance for the database + This is the SQL instance for the database. #> function Get-TargetResource { @@ -54,10 +54,11 @@ function Get-TargetResource [System.String[]] $Permissions, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, + [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -146,25 +147,25 @@ function Get-TargetResource Sets the permissions for the user in the database. .PARAMETER Ensure - This is The Ensure if the permission should be granted (Present) or revoked (Absent) + This is The Ensure if the permission should be granted (Present) or revoked (Absent). .PARAMETER DatabaseName This is the SQL database .PARAMETER Name - This is the name of the SQL login for the permission set + This is the name of the SQL login for the permission set. .PARAMETER PermissionState - This is the state of permission set. Valid values are 'Grant' or 'Deny' + This is the state of permission set. Valid values are 'Grant' or 'Deny'. .PARAMETER Permissions - This is a list that represents a SQL Server set of database permissions + This is a list that represents a SQL Server set of database permissions. .PARAMETER ServerName - This is the SQL Server for the database + This is the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is the SQL instance for the database + This is the SQL instance for the database. #> function Set-TargetResource { @@ -196,7 +197,7 @@ function Set-TargetResource [System.String[]] $Permissions, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -317,28 +318,28 @@ function Set-TargetResource <# .SYNOPSIS - Tests if the permissions is set for the user in the database + Tests if the permissions is set for the user in the database. .PARAMETER Ensure - This is The Ensure if the permission should be granted (Present) or revoked (Absent) + This is The Ensure if the permission should be granted (Present) or revoked (Absent). .PARAMETER DatabaseName This is the SQL database .PARAMETER Name - This is the name of the SQL login for the permission set + This is the name of the SQL login for the permission set. .PARAMETER PermissionState - This is the state of permission set. Valid values are 'Grant' or 'Deny' + This is the state of permission set. Valid values are 'Grant' or 'Deny'. .PARAMETER Permissions - This is a list that represents a SQL Server set of database permissions + This is a list that represents a SQL Server set of database permissions. .PARAMETER ServerName - This is the SQL Server for the database + This is the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is the SQL instance for the database + This is the SQL instance for the database. #> function Test-TargetResource { @@ -371,7 +372,7 @@ function Test-TargetResource [System.String[]] $Permissions, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -388,7 +389,7 @@ function Test-TargetResource $getTargetResourceParameters = @{ InstanceName = $PSBoundParameters.InstanceName - ServerName = $PSBoundParameters.ServerName + ServerName = $ServerName DatabaseName = $PSBoundParameters.DatabaseName Name = $PSBoundParameters.Name PermissionState = $PSBoundParameters.PermissionState diff --git a/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof b/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof index 23c8fc4b7..e9d57bf10 100644 --- a/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabasePermission/MSFT_SqlDatabasePermission.schema.mof @@ -1,11 +1,11 @@ [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 DatabaseName; [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 ServerName; [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; + [Required, Description("The set of permissions for the SQL database.")] String Permissions[]; + [Write, Description("If the values should be present or absent. Valid values are 'Present' or 'Absent'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; }; diff --git a/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 b/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 index f649b1ba4..953a3a364 100644 --- a/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 +++ b/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 @@ -8,19 +8,19 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseRecover <# .SYNOPSIS - This function gets all Key properties defined in the resource schema file + This function gets all Key properties defined in the resource schema file. .PARAMETER Name - This is the SQL database + This is the SQL database. .PARAMETER RecoveryModel - This is the RecoveryModel of the SQL database + This is the RecoveryModel of the SQL database. .PARAMETER ServerName - This is a the SQL Server for the database + This is a the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is a the SQL instance for the database + This is a the SQL instance for the database. #> function Get-TargetResource { @@ -34,10 +34,10 @@ function Get-TargetResource [System.String] $RecoveryModel, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -83,19 +83,19 @@ function Get-TargetResource <# .SYNOPSIS - This function gets all Key properties defined in the resource schema file + This function gets all Key properties defined in the resource schema file. .PARAMETER Name - This is the SQL database + This is the SQL database. .PARAMETER RecoveryModel - This is the RecoveryModel of the SQL database + This is the RecoveryModel of the SQL database. .PARAMETER ServerName - This is a the SQL Server for the database + This is a the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is a the SQL instance for the database + This is a the SQL instance for the database. #> function Set-TargetResource { @@ -108,10 +108,10 @@ function Set-TargetResource [System.String] $RecoveryModel, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -154,19 +154,19 @@ function Set-TargetResource <# .SYNOPSIS - This function gets all Key properties defined in the resource schema file + This function gets all Key properties defined in the resource schema file. .PARAMETER Name - This is the SQL database + This is the SQL database. .PARAMETER RecoveryModel - This is the RecoveryModel of the SQL database + This is the RecoveryModel of the SQL database. .PARAMETER ServerName - This is a the SQL Server for the database + This is a the SQL Server for the database. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - This is a the SQL instance for the database + This is a the SQL instance for the database. #> function Test-TargetResource { @@ -180,10 +180,10 @@ function Test-TargetResource [System.String] $RecoveryModel, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof b/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof index 8e5225522..d39fa1440 100644 --- a/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.schema.mof @@ -2,7 +2,7 @@ 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 ServerName; [Key, Description("The name of the SQL instance to be configured.")] String InstanceName; + [Required, Description("The recovery model to use for the database."), ValueMap{"Full","Simple","BulkLogged"}, Values{"Full","Simple","BulkLogged"}] String RecoveryModel; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; }; diff --git a/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 b/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 index bc98c47d3..1d1e2ca05 100644 --- a/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 +++ b/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.psm1 @@ -11,7 +11,8 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseRole' Returns the current state of the database role along with its membership. .PARAMETER ServerName - Specifies the host name of the SQL Server to be configured. + Specifies the host name of the SQL Server to be configured. Default value is + $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the name of the SQL instance to be configured. @@ -38,10 +39,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -172,7 +173,8 @@ function Get-TargetResource 'Absent' the role is removed from the database. .PARAMETER ServerName - Specifies the host name of the SQL Server to be configured. + Specifies the host name of the SQL Server to be configured. Default value is + $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the name of the SQL instance to be configured. @@ -202,10 +204,10 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -379,7 +381,8 @@ function Set-TargetResource Tests the current state of the database role along with its membership. .PARAMETER ServerName - Specifies the host name of the SQL Server to be configured. + Specifies the host name of the SQL Server to be configured. Default value is + $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the name of the SQL instance to be configured. @@ -409,10 +412,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -452,7 +455,7 @@ function Test-TargetResource ) $getTargetResourceParameters = @{ - ServerName = $PSBoundParameters.ServerName + ServerName = $ServerName InstanceName = $PSBoundParameters.InstanceName DatabaseName = $PSBoundParameters.DatabaseName Name = $PSBoundParameters.Name diff --git a/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof b/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof index 1a9a6ddd4..94677e896 100644 --- a/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabaseRole/MSFT_SqlDatabaseRole.schema.mof @@ -1,10 +1,10 @@ [ClassVersion("1.0.0.0"), FriendlyName("SqlDatabaseRole")] class MSFT_SqlDatabaseRole : OMI_BaseResource { - [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 name of the database in which the role should be configured.")] String DatabaseName; [Key, Description("The name of the database role to be added or removed.")] String Name; + [Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("The members the database role should have. This parameter will replace all the current database role members with the specified members. Can only be used when parameter Ensure is set to 'Present'.")] String Members[]; [Write, Description("The members the database role should include. This parameter will only add members to a database role. Can only be used when parameter Ensure is set to 'Present'. Can not be used at the same time as parameter Members.")] String MembersToInclude[]; [Write, Description("The members the database role should exclude. This parameter will only remove members from a database role. Can only be used when parameter Ensure is set to 'Present'. Can not be used at the same time as parameter Members.")] String MembersToExclude[]; diff --git a/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 b/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 index 18632f490..03bf77279 100644 --- a/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 +++ b/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 @@ -15,6 +15,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseUser' .PARAMETER ServerName Specifies the host name of the SQL Server on which the instance exist. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the SQL instance in which the database exist. @@ -32,9 +33,10 @@ function Get-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -111,6 +113,7 @@ function Get-TargetResource .PARAMETER ServerName Specifies the host name of the SQL Server on which the instance exist. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the SQL instance in which the database exist. @@ -132,13 +135,13 @@ function Get-TargetResource .PARAMETER UserType Specifies the type of the database user. Valid values are 'Login', - 'NoLogin', 'Certificate', or 'AsymmetricKey'. Defaults to 'NoLogin'. + 'NoLogin', 'Certificate', or 'AsymmetricKey'. Default value is 'NoLogin'. .PARAMETER Ensure Specifies if the database user should be present or absent. If 'Present' then the user will be added to the database and, if needed, the login mapping will be updated. If 'Absent' then the user will be removed from - the database. Defaults to 'Present'. + the database. Default value is 'Present'. #> function Set-TargetResource { @@ -149,9 +152,10 @@ function Set-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -408,6 +412,7 @@ function Set-TargetResource .PARAMETER ServerName Specifies the host name of the SQL Server on which the instance exist. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Specifies the SQL instance in which the database exist. @@ -429,13 +434,13 @@ function Set-TargetResource .PARAMETER UserType Specifies the type of the database user. Valid values are 'Login', - 'NoLogin', 'Certificate', or 'AsymmetricKey'. Defaults to 'NoLogin'. + 'NoLogin', 'Certificate', or 'AsymmetricKey'. Default value is 'NoLogin'. .PARAMETER Ensure Specifies if the database user should be present or absent. If 'Present' then the user will be added to the database and, if needed, the login mapping will be updated. If 'Absent' then the user will be removed from - the database. Defaults to 'Present'. + the database. Default value is 'Present'. #> function Test-TargetResource { @@ -447,9 +452,10 @@ function Test-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -628,7 +634,7 @@ function ConvertTo-UserType user. .PARAMETER UserType - Specifies the type of the database user. Defaults to 'NoLogin'. + Specifies the type of the database user. Default value is 'NoLogin'. .PARAMETER RemainingArguments Not used. diff --git a/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.schema.mof b/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.schema.mof index 25b415d8f..9eb524b1c 100644 --- a/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.schema.mof +++ b/source/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.schema.mof @@ -2,15 +2,15 @@ class MSFT_SqlDatabaseUser : OMI_BaseResource { [Key, Description("Specifies the name of the database user to be added or removed.")] String Name; - [Key, Description("Specifies the host name of the SQL Server on which the instance exist.")] String ServerName; [Key, Description("Specifies the SQL instance in which the database exist.")] String InstanceName; [Key, Description("Specifies the name of the database in which to configure the database user.")] String DatabaseName; + [Write, Description("Specifies the host name of the SQL Server on which the instance exist. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("Specifies the name of the SQL login to associate with the database user. This must be specified if parameter UserType is set to 'Login'.")] String LoginName; [Write, Description("Specifies the name of the asymmetric key to associate with the database user. This must be specified if parameter UserType is set to 'AsymmetricKey'.")] String AsymmetricKeyName; [Write, Description("Specifies the name of the certificate to associate with the database user. This must be specified if parameter UserType is set to 'Certificate'.")] String CertificateName; - [Write, Description("Specifies the type of the database user. Valid values are 'Login', 'NoLogin', 'Certificate', or 'AsymmetricKey'. Defaults to 'NoLogin'."), ValueMap{"Login", "NoLogin", "Certificate", "AsymmetricKey"}, Values{"Login", "NoLogin", "Certificate", "AsymmetricKey"}] String UserType; - [Write, Description("Specifies if the database user should be present or absent. If 'Present' then the database user will be added to the database and, if needed, the login mapping will be updated. If 'Absent' then the database user will be removed from the database. Defaults to 'Present'."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; - [Write, Description("Specifies if it is allowed to re-create the database user if either the user type, the asymmetric key, or the certificate changes. Defaults to $false not allowing database users to be re-created.")] Boolean Force; + [Write, Description("Specifies the type of the database user. Valid values are 'Login', 'NoLogin', 'Certificate', or 'AsymmetricKey'. Default value is 'NoLogin'."), ValueMap{"Login", "NoLogin", "Certificate", "AsymmetricKey"}, Values{"Login", "NoLogin", "Certificate", "AsymmetricKey"}] String UserType; + [Write, Description("Specifies if the database user should be present or absent. If 'Present' then the database user will be added to the database and, if needed, the login mapping will be updated. If 'Absent' then the database user will be removed from the database. Default value is 'Present'."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; + [Write, Description("Specifies if it is allowed to re-create the database user if either the user type, the asymmetric key, or the certificate changes. Default value is $false not allowing database users to be re-created.")] Boolean Force; [Read, Description("Returns the authentication type of the SQL login connected to the database user. This will return either 'Windows', 'Instance' or 'None'. The value 'Windows' means the SQL login is using Windows Authentication, 'Instance' means that the SQL login is using SQL authentication, and 'None' means that the database user have no SQL login connected to it.")] String AuthenticationType; [Read, Description("Returns the login type of the SQL login connected to the database user. If no SQL login is connected to the database user this returns $null.")] String LoginType; }; diff --git a/source/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof b/source/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof index 74aaf20ab..812fae98f 100644 --- a/source/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof +++ b/source/DSCResources/MSFT_SqlRS/MSFT_SqlRS.schema.mof @@ -9,6 +9,6 @@ class MSFT_SqlRS : OMI_BaseResource [Write, Description("Report Server URL reservations. Optional. If not specified, 'http://+:80' URL reservation will be used.")] String ReportServerReservedUrl[]; [Write, Description("Report Manager/Report Web App URL reservations. Optional. If not specified, 'http://+:80' URL reservation will be used.")] String ReportsReservedUrl[]; [Write, Description("If connections to the Reporting Services must use SSL. If this parameter is not assigned a value, the default is that Reporting Services does not use SSL.")] Boolean UseSsl; - [Write, Description("Reporting Services need to be restarted after initialization or settings change. If this parameter is set to $true, Reporting Services will not be restarted, even after initialisation.")] Boolean SuppressRestart; + [Write, Description("Reporting Services need to be restarted after initialization or settings change. If this parameter is set to $true, Reporting Services will not be restarted, even after initialization.")] Boolean SuppressRestart; [Read, Description("Is the Reporting Services instance initialized.")] Boolean IsInitialized; }; diff --git a/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 b/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 index 69680bb79..87e7e377d 100644 --- a/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 +++ b/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 @@ -8,19 +8,19 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerConfigura <# .SYNOPSIS - Gets the current value of a SQL configuration option + Gets the current value of a SQL configuration option. .PARAMETER ServerName - Hostname of the SQL Server to be configured + Hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - Name of the SQL instance to be configured. Default is 'MSSQLSERVER' + Name of the SQL instance to be configured. Default is 'MSSQLSERVER'. .PARAMETER OptionName - The name of the SQL configuration option to be checked + The name of the SQL configuration option to be checked. .PARAMETER OptionValue - The desired value of the SQL configuration option + The desired value of the SQL configuration option. .PARAMETER RestartService *** Not used in this function *** @@ -38,9 +38,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -91,23 +92,23 @@ function Get-TargetResource <# .SYNOPSIS - Sets the value of a SQL configuration option + Sets the value of a SQL configuration option. .PARAMETER ServerName - Hostname of the SQL Server to be configured + Hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - Name of the SQL instance to be configured. Default is 'MSSQLSERVER' + Name of the SQL instance to be configured. Default is 'MSSQLSERVER'. .PARAMETER OptionName - The name of the SQL configuration option to be set + The name of the SQL configuration option to be set. .PARAMETER OptionValue - The desired value of the SQL configuration option + The desired value of the SQL configuration option. .PARAMETER RestartService Determines whether the instance should be restarted after updating the - configuration option + configuration option. .PARAMETER RestartTimeout The length of time, in seconds, to wait for the service to restart. Default @@ -118,9 +119,10 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -186,24 +188,24 @@ function Set-TargetResource <# .SYNOPSIS - Determines whether a SQL configuration option value is properly set + Determines whether a SQL configuration option value is properly set. .PARAMETER ServerName - Hostname of the SQL Server to be configured + Hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName - Name of the SQL instance to be configured. Default is 'MSSQLSERVER' + Name of the SQL instance to be configured. Default is 'MSSQLSERVER'. .PARAMETER OptionName - The name of the SQL configuration option to be tested + The name of the SQL configuration option to be tested. .PARAMETER OptionValue - The desired value of the SQL configuration option + The desired value of the SQL configuration option. .PARAMETER RestartService *** Not used in this function *** Determines whether the instance should be restarted after updating the - configuration option + configuration option. .PARAMETER RestartTimeout *** Not used in this function *** @@ -216,9 +218,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] diff --git a/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof b/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof index d02ee2903..a1df39b4d 100644 --- a/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof +++ b/source/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.schema.mof @@ -1,10 +1,10 @@ [ClassVersion("1.0.0.0"), FriendlyName("SqlServerConfiguration")] class MSFT_SqlServerConfiguration : OMI_BaseResource { - [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("The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("Determines whether the instance should be restarted after updating the configuration option.")] Boolean RestartService; [Write, Description("The length of time, in seconds, to wait for the service to restart. Default is 120 seconds.")] UInt32 RestartTimeout; }; diff --git a/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.psm1 b/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.psm1 index d276f06d7..527f331ff 100644 --- a/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.psm1 +++ b/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.psm1 @@ -12,7 +12,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerDatabaseM .PARAMETER ServerName The hostname of the SQL Server to be configured. - Defaults to $env:COMPUTERNAME. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -37,6 +37,7 @@ function Get-TargetResource param ( [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -188,7 +189,7 @@ function Get-TargetResource .PARAMETER ServerName The hostname of the SQL Server to be configured. - Defaults to $env:COMPUTERNAME. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -240,6 +241,7 @@ function Set-TargetResource $Ensure = 'Present', [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -589,7 +591,7 @@ function Set-TargetResource .PARAMETER ServerName The hostname of the SQL Server to be configured. - Defaults to $env:COMPUTERNAME. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -645,6 +647,7 @@ function Test-TargetResource $AccountName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.schema.mof b/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.schema.mof index a1e76a114..f20532c81 100644 --- a/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.schema.mof +++ b/source/DSCResources/MSFT_SqlServerDatabaseMail/MSFT_SqlServerDatabaseMail.schema.mof @@ -7,7 +7,7 @@ class MSFT_SqlServerDatabaseMail : OMI_BaseResource [Required, Description("The fully qualified domain name of the mail server name to which e-mail are sent.")] String MailServerName; [Required, Description("The name of the Database Mail profile.")] String ProfileName; [Write, Description("Specifies the desired state of the Database Mail. When set to 'Present', the Database Mail will be created. When set to 'Absent', the Database Mail will be removed. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("The hostname of the SQL Server to be configured. Defaults to $env:COMPUTERNAME.")] String ServerName; + [Write, Description("The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("The display name of the originating email address. Default value is the same value assigned to the EmailAddress parameter.")] String DisplayName; [Write, Description("The e-mail address to which the receiver of e-mails will reply to. Default value is the same e-mail address assigned to parameter EmailAddress.")] String ReplyToAddress; [Write, Description("The description for the Database Mail profile and account.")] String Description; diff --git a/source/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 b/source/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 index eb6d9fece..750fbe4a9 100644 --- a/source/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 +++ b/source/DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1 @@ -30,6 +30,7 @@ function Get-TargetResource $EndpointName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -112,7 +113,8 @@ function Get-TargetResource The name of the SQL instance to be configured. .PARAMETER IpAddress - The network IP address the endpoint is listening on. Defaults to '0.0.0.0' which means listen on any valid IP address. + The network IP address the endpoint is listening on. Default value is '0.0.0.0' + which means listen on any valid IP address. .PARAMETER Owner The owner of the endpoint. Default is the login used for the creation. @@ -136,6 +138,7 @@ function Set-TargetResource $Port = 5022, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -271,7 +274,8 @@ function Set-TargetResource The name of the SQL instance to be configured. .PARAMETER IpAddress - The network IP address the endpoint is listening on. Defaults to '0.0.0.0' which means listen on any valid IP address. + The network IP address the endpoint is listening on. Default value is '0.0.0.0' + which means listen on any valid IP address. .PARAMETER Owner The owner of the endpoint. Default is the login used for the creation. @@ -296,6 +300,7 @@ function Test-TargetResource $Port = 5022, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 b/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 index d8e28026d..a4191317d 100644 --- a/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 +++ b/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.psm1 @@ -14,7 +14,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerEndpointP The name of the SQL instance to be configured. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER Name The name of the endpoint. @@ -32,9 +32,10 @@ function Get-TargetResource [System.String] $InstanceName, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -105,7 +106,7 @@ function Get-TargetResource The name of the SQL instance to be configured. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER Ensure If the permission should be present or absent. Default value is 'Present'. @@ -128,9 +129,10 @@ function Set-TargetResource [System.String] $InstanceName, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -213,7 +215,7 @@ function Set-TargetResource The name of the SQL instance to be configured. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER Ensure If the permission should be present or absent. Default value is 'Present'. @@ -237,9 +239,10 @@ function Test-TargetResource [System.String] $InstanceName, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateSet('Present', 'Absent')] diff --git a/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof b/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof index c7b02df36..4ef270d53 100644 --- a/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof +++ b/source/DSCResources/MSFT_SqlServerEndpointPermission/MSFT_SqlServerEndpointPermission.schema.mof @@ -3,10 +3,10 @@ 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 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; + [Required, Description("The name of the endpoint.")] String Name; + [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; [Write, Description("The permission to set for the login. Valid value for permission are only CONNECT."), ValueMap{"CONNECT"}, Values{"CONNECT"}] String Permission; }; diff --git a/source/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 b/source/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 index cdcfcbb68..ef956a7ce 100644 --- a/source/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 +++ b/source/DSCResources/MSFT_SqlServerEndpointState/MSFT_SqlServerEndpointState.psm1 @@ -30,6 +30,7 @@ function Get-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -101,6 +102,7 @@ function Set-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -185,6 +187,7 @@ function Test-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 b/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 index ee7f91a6e..982dbacd4 100644 --- a/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 +++ b/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.psm1 @@ -14,7 +14,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerLogin' The name of the login to retrieve. .PARAMETER ServerName - Hostname of the SQL Server to retrieve the login from. + Hostname of the SQL Server to retrieve the login from. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance to retrieve the login from. @@ -29,9 +29,10 @@ function Get-TargetResource [System.String] $Name, - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -95,7 +96,7 @@ function Get-TargetResource The type of login to create. Default is 'WindowsUser' .PARAMETER ServerName - Hostname of the SQL Server to create the login on. + Hostname of the SQL Server to create the login on. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance to create the login on. @@ -145,9 +146,10 @@ function Set-TargetResource [System.String] $LoginType = 'WindowsUser', - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -347,7 +349,7 @@ function Set-TargetResource The type of login. Default is 'WindowsUser' .PARAMETER ServerName - Hostname of the SQL Server. + Hostname of the SQL Server to create the login on. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance. @@ -397,9 +399,10 @@ function Test-TargetResource [System.String] $LoginType = 'WindowsUser', - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] diff --git a/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof b/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof index bc336633a..0f7b6662a 100644 --- a/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof +++ b/source/DSCResources/MSFT_SqlServerLogin/MSFT_SqlServerLogin.schema.mof @@ -1,13 +1,13 @@ [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; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; + [Write, Description("The specified login is Present or Absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [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 ServerName; - [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; + [Write, Description("The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName; [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/source/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 b/source/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 index 3dfd083fd..550bd3f42 100644 --- a/source/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 +++ b/source/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 @@ -33,6 +33,7 @@ function Get-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -126,6 +127,7 @@ function Set-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, @@ -222,6 +224,7 @@ function Test-TargetResource $InstanceName, [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] $ServerName = $env:COMPUTERNAME, diff --git a/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 b/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 index 3c6f27a78..ff96ab052 100644 --- a/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 +++ b/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.psm1 @@ -23,7 +23,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerRole' The name of server role to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -51,10 +51,10 @@ function Get-TargetResource [System.String] $ServerRoleName, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -178,7 +178,7 @@ function Get-TargetResource The name of server role to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -210,10 +210,10 @@ function Set-TargetResource [System.String] $ServerRoleName, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -371,7 +371,7 @@ function Set-TargetResource The name of server role to be created or dropped. .PARAMETER ServerName - The host name of the SQL Server to be configured. + The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName The name of the SQL instance to be configured. @@ -404,10 +404,10 @@ function Test-TargetResource [System.String] $ServerRoleName, - [Parameter(Mandatory = $true)] + [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof b/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof index 4ed3b2286..3d2b41c65 100644 --- a/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof +++ b/source/DSCResources/MSFT_SqlServerRole/MSFT_SqlServerRole.schema.mof @@ -2,8 +2,8 @@ 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 ServerName; [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("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/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 b/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 index d56d23f23..43ee450e7 100644 --- a/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 +++ b/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 @@ -11,7 +11,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServiceAccount' Gets the service account for the specified instance. .PARAMETER ServerName - Host name of the SQL Server to manage. + Host name of the SQL Server to manage. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance. @@ -29,7 +29,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServiceAccount' Version number of IntegrationServices. .EXAMPLE - Get-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account + Get-TargetResource -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account Get-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType IntegrationServices -ServiceAccount $account -VersionNumber 130 #> function Get-TargetResource @@ -38,9 +38,10 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -94,7 +95,7 @@ function Get-TargetResource Tests whether the specified instance's service account is correctly configured. .PARAMETER ServerName - Host name of the SQL Server to manage. + Host name of the SQL Server to manage. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance. @@ -117,7 +118,7 @@ function Get-TargetResource Version number of IntegrationServices .EXAMPLE - Test-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account + Test-TargetResource -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account Test-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType IntegrationServices -ServiceAccount $account -VersionNumber 130 #> @@ -127,9 +128,10 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] @@ -175,7 +177,7 @@ function Test-TargetResource Sets the SQL Server service account to the desired state. .PARAMETER ServerName - Host name of the SQL Server to manage. + Host name of the SQL Server to manage. Default value is $env:COMPUTERNAME. .PARAMETER InstanceName Name of the SQL instance. @@ -205,9 +207,10 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] + [Parameter()] + [ValidateNotNullOrEmpty()] [System.String] - $ServerName, + $ServerName = $env:COMPUTERNAME, [Parameter(Mandatory = $true)] [System.String] diff --git a/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof b/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof index 4a9c4788c..12cff9e6b 100644 --- a/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof +++ b/source/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.schema.mof @@ -1,10 +1,10 @@ [ClassVersion("1.0.0.0"), FriendlyName("SqlServiceAccount")] class MSFT_SqlServiceAccount : OMI_BaseResource { - [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("Host name of the SQL Server to manage. Default value is $env:COMPUTERNAME.")] String ServerName; [Write, Description("Determines whether the service is automatically restarted when a change to the configuration was needed.")] Boolean RestartService; [Write, Description("Forces the service account to be updated. Useful for password changes.")] Boolean Force; [Read, Description("Returns the service account username for the service.")] String ServiceAccountName; diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 6a7906722..77a04bb2b 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -920,11 +920,11 @@ function Start-SqlSetupProcess .PARAMETER ServerName String containing the host name of the SQL Server to connect to. - Defaults to $env:COMPUTERNAME. + Default value is $env:COMPUTERNAME. .PARAMETER InstanceName String containing the SQL Server Database Engine instance to connect to. - Defaults to 'MSSQLSERVER'. + Default value is 'MSSQLSERVER'. .PARAMETER SetupCredential The credentials to use to impersonate a user when connecting to the @@ -934,7 +934,7 @@ function Start-SqlSetupProcess .PARAMETER LoginType Specifies which type of logon credential should be used. The valid types - are 'WindowsUser' or 'SqlLogin'. Defaults to 'WindowsUser' + are 'WindowsUser' or 'SqlLogin'. Default value is 'WindowsUser' If set to 'WindowsUser' then the it will impersonate using the Windows login specified in the parameter SetupCredential. If set to 'WindowsUser' then the it will impersonate using the native SQL @@ -1519,7 +1519,7 @@ function Restart-SqlService .PARAMETER WaitTime Number of seconds to wait between service stop and service start. - Defaults to 0 seconds. + Default value is 0 seconds. #> function Restart-ReportingServicesService { diff --git a/tests/TestHelpers/CommonTestHelper.psm1 b/tests/TestHelpers/CommonTestHelper.psm1 index 4272738aa..ca12c62cb 100644 --- a/tests/TestHelpers/CommonTestHelper.psm1 +++ b/tests/TestHelpers/CommonTestHelper.psm1 @@ -298,7 +298,7 @@ function New-SQLSelfSignedCertificate in the parameter Type. .PARAMETER Name - Name of the test script that is called. Defaults to the name of the + Name of the test script that is called. Default value is the name of the calling script. .PARAMETER Type diff --git a/tests/Unit/MSFT_SqlAlias.Tests.ps1 b/tests/Unit/MSFT_SqlAlias.Tests.ps1 index 65d7b2ed7..4b899941d 100644 --- a/tests/Unit/MSFT_SqlAlias.Tests.ps1 +++ b/tests/Unit/MSFT_SqlAlias.Tests.ps1 @@ -77,773 +77,840 @@ try } Describe 'SqlAlias\Get-TargetResource' { - # Mocking for protocol TCP - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' - } - } -Verifiable + Context 'When node is 64-bit using TCP' { + BeforeAll { + # Mocking for protocol TCP + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentTcpPort } -MockWith { - return @{ - 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentTcpPort } -MockWith { + return @{ + 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentTcpPort } -MockWith { - return @{ - 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentTcpPort } -MockWith { + return @{ + 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentServerNameTcp } -MockWith { - return @{ - 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentServerNameTcp } -MockWith { + return @{ + 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentServerNameTcp } -MockWith { - return @{ - 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentServerNameTcp } -MockWith { + return @{ + 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' + } + } -Verifiable + + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $unknownName } -MockWith { + return $null + } -Verifiable + + # Mocking 64-bit OS + Mock -CommandName Get-CimInstance -MockWith { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force + } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable } - } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $unknownName } -MockWith { - return $null - } -Verifiable + Context 'When the system is in the desired present state' { + $testParameters = @{ + Name = $name + } - # Mocking 64-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + $result = Get-TargetResource @testParameters - Context 'When the system is in the desired present state for 64-bit OS using TCP' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - $result = Get-TargetResource @testParameters + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + } + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It "Should return $tcpPort as the port number used" { + $result.TcpPort | Should -Be $tcpPort + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It "Should return $tcpPort as the port number used" { - $result.TcpPort | Should -Be $tcpPort - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is in the desired absent state' { + $testParameters = @{ + Name = $unknownName + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + $result = Get-TargetResource @testParameters - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + It 'Should return the state as absent' { + $result.Ensure | Should -Be 'Absent' + } - Context 'When the system is in the desired absent state for 64-bit OS' { - $testParameters = @{ - Name = $unknownName - ServerName = $unknownServerName - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - $result = Get-TargetResource @testParameters + It 'Should not return any protocol' { + $result.Protocol | Should -Be '' + } - It 'Should return the state as absent' { - $result.Ensure | Should -Be 'Absent' - } + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } - It 'Should not return any protocol' { - $result.Protocol | Should -Be '' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is not in the desired state because TcpPort is different when desired protocol is TCP' { + $testParameters = @{ + Name = $nameDifferentTcpPort + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + $result = Get-TargetResource @testParameters - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Context 'When the system is not in the desired state because TcpPort is different when desired protocol is TCP' { - $testParameters = @{ - Name = $nameDifferentTcpPort - ServerName = $serverNameTcp - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + } - $result = Get-TargetResource @testParameters + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It "Should return $differentTcpPort as the port number used" { + $result.TcpPort | Should -Be $differentTcpPort + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It "Should return $differentTcpPort as the port number used" { - $result.TcpPort | Should -Be $differentTcpPort - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is not in the desired state because ServerName is different when desired protocol is TCP' { + $testParameters = @{ + Name = $nameDifferentServerNameTcp + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + $result = Get-TargetResource @testParameters - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Context 'When the system is not in the desired state because ServerName is different when desired protocol is TCP' { - $testParameters = @{ - Name = $nameDifferentServerNameTcp - ServerName = $serverNameTcp - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + } - $result = Get-TargetResource @testParameters + It 'Should return different server name than the one passed as parameter' { + $result.ServerName | Should -Be $differentServerNameTcp + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - } + It "Should return $tcpPort as the port number used" { + $result.TcpPort | Should -Be $tcpPort + } - It 'Should return different server name than the one passed as parameter' { - $result.ServerName | Should -Be $differentServerNameTcp - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It "Should return $tcpPort as the port number used" { - $result.TcpPort | Should -Be $tcpPort - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is not in the desired present state using UseDynamicTcpPort' { + $testParameters = @{ + Name = $name + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + # Testing protocol TCP "With Dynamically determine port" + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - Context 'When the system is not in the desired present state for 64-bit OS using UseDynamicTcpPort' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + # Mocking 64-bit OS + Mock -CommandName Get-CimInstance -MockWith { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force + } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + + $result = Get-TargetResource @testParameters - # Testing protocol TCP "With Dynamically determine port" - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' } - } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp } - } -Verifiable - # Mocking 64-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - $result = Get-TargetResource @testParameters + It 'Should return the UseDynamicTcpPort parameter as false' { + $result.UseDynamicTcpPort | Should -Be $false + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It "Should not return any pipe name" { + $result.PipeName | Should -Be '' + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should not return any TCP Port' { + $result.TcpPort | Should -Be 1433 + } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It 'Should return the UseDynamicTcpPort parameter as false' { - $result.UseDynamicTcpPort | Should -Be $false - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It "Should not return any pipe name" { - $result.PipeName | Should -Be '' + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should not return any TCP Port' { - $result.TcpPort | Should -Be 1433 - } + Context 'When the system is in the desired present state using UseDynamicTcpPort' { + $testParameters = @{ + Name = $name + } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + # Testing protocol TCP "With Dynamically determine port" + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + } + } -Verifiable - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + } + } -Verifiable - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + $result = Get-TargetResource @testParameters - # Mocking 32-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '32-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Context 'When the system is in the desired present state for 32-bit OS using TCP' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + } - $result = Get-TargetResource @testParameters + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It 'Should return the UseDynamicTcpPort parameter as true' { + $result.UseDynamicTcpPort | Should -Be $true + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - $result.Protocol | Should -Be $defaultParameters.Protocol - $result.TcpPort | Should -Be $defaultParameters.TcpPort - } + It "Should not return any pipe name" { + $result.PipeName | Should -Be '' + } - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' - } + It 'Should not return any TCP Port' { + $result.TcpPort | Should -Be 0 + } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 0 -Scope Context + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } } - Context 'When the system is in the desired present state for 32-bit OS using UseDynamicTcpPort' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + Context 'When node is 32-bit using TCP' { + BeforeAll { + # Mocking for protocol TCP + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - # Testing protocol TCP "With Dynamically determine port" - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentTcpPort } -MockWith { + return @{ + 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' + } + } -Verifiable - $result = Get-TargetResource @testParameters + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentTcpPort } -MockWith { + return @{ + 'DifferentTcpPort' = 'DBMSSOCN,sqlnode.company.local,1500' + } + } -Verifiable - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentServerNameTcp } -MockWith { + return @{ + 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' + } + } -Verifiable - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentServerNameTcp } -MockWith { + return @{ + 'DifferentServerNameTcp' = 'DBMSSOCN,unknownserver.company.local,1433' + } + } -Verifiable - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $unknownName } -MockWith { + return $null + } -Verifiable - It 'Should return the UseDynamicTcpPort parameter as false' { - $result.UseDynamicTcpPort | Should -Be $false + # Mocking 32-bit OS + Mock -CommandName Get-CimInstance -MockWith { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '32-bit' -PassThru -Force + } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable } - It "Should not return any pipe name" { - $result.PipeName | Should -Be '' - } + Context 'When the system is in the desired present state' { + $testParameters = @{ + Name = $name + } - It 'Should not return any TCP Port' { - $result.TcpPort | Should -Be 1433 - } + $result = Get-TargetResource @testParameters - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + $result.Protocol | Should -Be $defaultParameters.Protocol + $result.TcpPort | Should -Be $defaultParameters.TcpPort + } - It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 0 -Scope Context - } - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } - Context 'When the system is in the desired absent state for 32-bit OS' { - $testParameters = @{ - Name = $unknownName - ServerName = $unknownServerName - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - $result = Get-TargetResource @testParameters + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + } - It 'Should return the state as absent' { - $result.Ensure | Should -Be 'Absent' + It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 0 -Scope Context + } } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + Context 'When the system is in the desired present state using UseDynamicTcpPort' { + $testParameters = @{ + Name = $name + } - It 'Should not return any protocol' { - $result.Protocol | Should -Be '' - } + # Testing protocol TCP "With Dynamically determine port" + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local,1433' + } + } -Verifiable - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' - } + $result = Get-TargetResource @testParameters - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + } - It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 0 -Scope Context - } - } + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - # Testing protocol NP (Named Pipes) - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' - } - } -Verifiable + It 'Should return the UseDynamicTcpPort parameter as false' { + $result.UseDynamicTcpPort | Should -Be $false + } - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' - } - } -Verifiable + It "Should not return any pipe name" { + $result.PipeName | Should -Be '' + } - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentPipeName } -MockWith { - return @{ - 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' - } - } -Verifiable + It 'Should not return any TCP Port' { + $result.TcpPort | Should -Be 1433 + } - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentPipeName } -MockWith { - return @{ - 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' - } - } -Verifiable + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { - return @{ - 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\firstserver\PIPE\sql\query' - } - } -Verifiable + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + } - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { - return @{ - 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\secondserver\PIPE\sql\query' + It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 0 -Scope Context + } } - } -Verifiable - # Mocking 64-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + Context 'When the system is in the desired absent state' { + $testParameters = @{ + Name = $unknownName + } - Context 'When the system is in the desired present state for 64-bit OS using Named Pipes' { - $testParameters = @{ - Name = $name - ServerName = $serverNameNamedPipes - } + $result = Get-TargetResource @testParameters - $result = Get-TargetResource @testParameters + It 'Should return the state as absent' { + $result.Ensure | Should -Be 'Absent' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should not return any protocol' { + $result.Protocol | Should -Be '' + } - It 'Should return NP as the protocol used' { - $result.Protocol | Should -Be 'NP' - } + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 + } - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } + + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It 'Should return the correct pipe name based on the passed ServerName parameter' { - $result.PipeName | Should -Be "\\$serverNameNamedPipes\PIPE\sql\query" + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + } + + It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 0 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is in the desired present state using UseDynamicTcpPort' { + $testParameters = @{ + Name = $name + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + # Testing protocol TCP "With Dynamically determine port" + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + } + } -Verifiable - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + } + } -Verifiable - Context 'When the system is not in the desired state because ServerName is different when desired protocol is Named Pipes' { - $testParameters = @{ - Name = $nameDifferentPipeName - ServerName = $serverNameNamedPipes - } + $result = Get-TargetResource @testParameters - $result = Get-TargetResource @testParameters + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -Be $serverNameTcp + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should return TCP as the protocol used' { + $result.Protocol | Should -Be 'TCP' + } - It 'Should return NP as the protocol used' { - $result.Protocol | Should -Be 'NP' - } + It 'Should return the UseDynamicTcpPort parameter as true' { + $result.UseDynamicTcpPort | Should -Be $true + } - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + It "Should not return any pipe name" { + $result.PipeName | Should -Be '' + } - It 'Should return the correct pipe name based on the passed ServerName parameter' { - $result.PipeName | Should -Be $differentPipeName - } + It 'Should not return any TCP Port' { + $result.TcpPort | Should -Be 0 + } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context + It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 0 -Scope Context + } } } - Context 'When the state differ between 32-bit OS and 64-bit OS registry keys' { - $testParameters = @{ - Name = $nameWow6432NodeDifferFrom64BitOS - ServerName = $serverNameNamedPipes - } + Context 'When node is 64-bit using Named Pipes' { + BeforeAll { + # Testing protocol NP (Named Pipes) + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' + } + } -Verifiable - $result = Get-TargetResource @testParameters + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' + } + } -Verifiable - It 'Should return the state as absent' { - $result.Ensure | Should -Be 'Absent' - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentPipeName } -MockWith { + return @{ + 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' + } + } -Verifiable - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentPipeName } -MockWith { + return @{ + 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' + } + } -Verifiable - It 'Should not return any protocol' { - $result.Protocol | Should -Be '' - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { + return @{ + 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\firstserver\PIPE\sql\query' + } + } -Verifiable - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { + return @{ + 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\secondserver\PIPE\sql\query' + } + } -Verifiable - It 'Should not return any pipe name' { - $result.PipeName | Should -Be '' + # Mocking 64-bit OS + Mock -CommandName Get-CimInstance -MockWith { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force + } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context - - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is in the desired present state' { + $testParameters = @{ + Name = $name + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context - } - } + $result = Get-TargetResource @testParameters - # Mocking 32-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '32-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - Context 'When the system is in the desired present state for 32-bit OS using Named Pipes' { - $testParameters = @{ - Name = $name - ServerName = $serverNameNamedPipes - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - $result = Get-TargetResource @testParameters + It 'Should return NP as the protocol used' { + $result.Protocol | Should -Be 'NP' + } - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 + } - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName - } + It 'Should return the correct pipe name based on the passed ServerName parameter' { + $result.PipeName | Should -Be "\\$serverNameNamedPipes\PIPE\sql\query" + } - It 'Should return NP as the protocol used' { - $result.Protocol | Should -Be 'NP' - } + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It 'Should not return a port number' { - $result.TcpPort | Should -Be 0 - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should return the correct pipe name based on the passed ServerName parameter' { - $result.PipeName | Should -Be $pipeName + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + Context 'When the system is not in the desired state because ServerName is different when desired protocol is Named Pipes' { + $testParameters = @{ + Name = $nameDifferentPipeName + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context - } + $result = Get-TargetResource @testParameters - It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 0 -Scope Context - } - } + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - # Mocking 64-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '64-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - Context 'When the system is in the desired present state for 64-bit OS using UseDynamicTcpPort' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + It 'Should return NP as the protocol used' { + $result.Protocol | Should -Be 'NP' + } - # Testing protocol TCP "With Dynamically determine port" - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 } - } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' + It 'Should return the correct pipe name based on the passed ServerName parameter' { + $result.PipeName | Should -Be $differentPipeName } - } -Verifiable - $result = Get-TargetResource @testParameters + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + Context 'When the state differ between 32-bit OS and 64-bit OS registry keys' { + $testParameters = @{ + Name = $nameWow6432NodeDifferFrom64BitOS + } - It 'Should return the UseDynamicTcpPort parameter as true' { - $result.UseDynamicTcpPort | Should -Be $true - } + $result = Get-TargetResource @testParameters - It "Should not return any pipe name" { - $result.PipeName | Should -Be '' - } + It 'Should return the state as absent' { + $result.Ensure | Should -Be 'Absent' + } - It 'Should not return any TCP Port' { - $result.TcpPort | Should -Be 0 - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should not return any protocol' { + $result.Protocol | Should -Be '' + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 1 -Scope Context + It 'Should not return any pipe name' { + $result.PipeName | Should -Be '' + } + + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context + + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 1 -Scope Context + } } } - # Mocking 32-bit OS - Mock -CommandName Get-CimInstance -MockWith { - return New-Object -TypeName Object | - Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '32-bit' -PassThru -Force - } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable + Context 'When node is 32-bit using Named Pipes' { + BeforeAll { + # Testing protocol NP (Named Pipes) + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' + } + } -Verifiable - Context 'When the system is in the desired present state for 32-bit OS using UseDynamicTcpPort' { - $testParameters = @{ - Name = $name - ServerName = $serverNameTcp - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { + return @{ + 'MyAlias' = 'DBNMPNTW,\\sqlnode\PIPE\sql\query' + } + } -Verifiable - # Testing protocol TCP "With Dynamically determine port" - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameDifferentPipeName } -MockWith { + return @{ + 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' + } + } -Verifiable - Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $name } -MockWith { - return @{ - 'MyAlias' = 'DBMSSOCN,sqlnode.company.local' - } - } -Verifiable + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameDifferentPipeName } -MockWith { + return @{ + 'DifferentPipeName' = 'DBNMPNTW,\\unknownserver\PIPE\sql\query' + } + } -Verifiable - $result = Get-TargetResource @testParameters + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { + return @{ + 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\firstserver\PIPE\sql\query' + } + } -Verifiable - It 'Should return the state as present' { - $result.Ensure | Should -Be 'Present' - } + Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node -and $Name -eq $nameWow6432NodeDifferFrom64BitOS } -MockWith { + return @{ + 'Wow6432NodeDifferFrom64BitOS' = 'DBNMPNTW,\\secondserver\PIPE\sql\query' + } + } -Verifiable - It 'Should return the same values as passed as parameters' { - $result.Name | Should -Be $testParameters.Name - $result.ServerName | Should -Be $testParameters.ServerName + # Mocking 32-bit OS + Mock -CommandName Get-CimInstance -MockWith { + return New-Object -TypeName Object | + Add-Member -MemberType NoteProperty -Name OSArchitecture -Value '32-bit' -PassThru -Force + } -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } -Verifiable } - It 'Should return TCP as the protocol used' { - $result.Protocol | Should -Be 'TCP' - } + Context 'When the system is in the desired present state for 32-bit OS using Named Pipes' { + $testParameters = @{ + Name = $name + } - It 'Should return the UseDynamicTcpPort parameter as true' { - $result.UseDynamicTcpPort | Should -Be $true - } + $result = Get-TargetResource @testParameters - It "Should not return any pipe name" { - $result.PipeName | Should -Be '' - } + It 'Should return the state as present' { + $result.Ensure | Should -Be 'Present' + } - It 'Should not return any TCP Port' { - $result.TcpPort | Should -Be 0 - } + It 'Should return the same values as passed as parameters' { + $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should -BeNullOrEmpty + } - It 'Should call the mocked functions exactly 1 time each' { - Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` - -Exactly -Times 1 -Scope Context + It 'Should return NP as the protocol used' { + $result.Protocol | Should -Be 'NP' + } - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` - -Exactly -Times 1 -Scope Context - } + It 'Should not return a port number' { + $result.TcpPort | Should -Be 0 + } - It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { - Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` - -Exactly -Times 0 -Scope Context + It 'Should return the correct pipe name based on the passed ServerName parameter' { + $result.PipeName | Should -Be $pipeName + } + + It 'Should call the mocked functions exactly 1 time each' { + Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' } ` + -Exactly -Times 1 -Scope Context + + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPath } ` + -Exactly -Times 1 -Scope Context + } + + It 'Should not call the Get-ItemProperty for the Wow6432Node-path' { + Assert-MockCalled -CommandName Get-ItemProperty -ParameterFilter { $Path -eq $registryPathWow6432Node } ` + -Exactly -Times 0 -Scope Context + } } }