From a971c830141747d1dc877181cbabc2ab19a41121 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 18 Jul 2019 12:47:28 +0200 Subject: [PATCH 1/2] Changes to helper function Invoke-Query - Parameters now match that of Connect-SQL. --- CHANGELOG.md | 4 +- .../MSFT_SqlAGDatabase.psm1 | 6 +-- .../SqlServerDsc.Common.psm1 | 38 +++++++++---------- Tests/Unit/SqlServerDsc.Common.Tests.ps1 | 6 +-- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cf52c85..9d4fc26c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - Changes to helper function Invoke-Query - Fixes issues in [issue #1355](https://github.com/PowerShell/SqlServerDsc/issues/1355). - Works together with Connect-SQL now. - - Parameters and Aliases now match that of Connect-SQL. + - Parameters now match that of Connect-SQL. - Can now pass in credentials. - Can now pass in 'Microsoft.SqlServer.Management.Smo.Server' object. - Can also pipe in 'Microsoft.SqlServer.Management.Smo.Server' object. @@ -25,7 +25,7 @@ - Minor style fixes in unit tests. - Changes to helper function Connect-SQL - When impersonating WindowsUser credential use the NetworkCredential UserName. - - Added addtional verbose logging. + - Added additional verbose logging. - Changes to SqlServerSecureConnection - Forced $Thumbprint to lowercase to fix [issue #1350](https://github.com/PowerShell/SqlServerDsc/issues/1350). - Add parameter SuppressRestart with default value false. diff --git a/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 index 7f1d23a05..be39f88ee 100644 --- a/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 +++ b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 @@ -362,7 +362,7 @@ function Set-TargetResource foreach ( $databaseFileDirectory in $databaseFileDirectories ) { $fileExistsQuery = "EXEC master.dbo.xp_fileexist '$databaseFileDirectory'" - $fileExistsResult = Invoke-Query -SQLServer $currentAvailabilityGroupReplicaServerObject.NetName -SQLInstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $fileExistsQuery -WithResults + $fileExistsResult = Invoke-Query -ServerName $currentAvailabilityGroupReplicaServerObject.NetName -InstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $fileExistsQuery -WithResults if ( $fileExistsResult.Tables.Rows.'File is a Directory' -ne 1 ) { @@ -545,8 +545,8 @@ function Set-TargetResource $currentReplicaAvailabilityGroupObject = $currentAvailabilityGroupReplicaServerObject.AvailabilityGroups[$AvailabilityGroupName] # Restore the database - Invoke-Query -SQLServer $currentAvailabilityGroupReplicaServerObject.NetName -SQLInstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $restoreDatabaseQueryString -StatementTimeout 0 - Invoke-Query -SQLServer $currentAvailabilityGroupReplicaServerObject.NetName -SQLInstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $restoreLogQueryString -StatementTimeout 0 + Invoke-Query -ServerName $currentAvailabilityGroupReplicaServerObject.NetName -InstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $restoreDatabaseQueryString -StatementTimeout 0 + Invoke-Query -ServerName $currentAvailabilityGroupReplicaServerObject.NetName -InstanceName $currentAvailabilityGroupReplicaServerObject.ServiceName -Database master -Query $restoreLogQueryString -StatementTimeout 0 # Add the database to the Availability Group Add-SqlAvailabilityDatabase -InputObject $currentReplicaAvailabilityGroupObject -Database $databaseToAddToAvailabilityGroup diff --git a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 4f36e2b04..3ccccaa6c 100644 --- a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -918,10 +918,10 @@ function Start-SqlSetupProcess .SYNOPSIS Connect to a SQL Server Database Engine and return the server object. - .PARAMETER SQLServer + .PARAMETER ServerName String containing the host name of the SQL Server to connect to. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName String containing the SQL Server Database Engine instance to connect to. .PARAMETER SetupCredential @@ -1581,10 +1581,10 @@ function Restart-ReportingServicesService .SYNOPSIS Executes a query on the specified database. - .PARAMETER SQLServer + .PARAMETER ServerName The hostname of the server that hosts the SQL instance. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance that hosts the database. .PARAMETER Database @@ -1619,11 +1619,11 @@ function Restart-ReportingServicesService be interpreted as regular expressions (RegEx). .EXAMPLE - Invoke-Query -SQLServer Server1 -SQLInstanceName MSSQLSERVER -Database master ` + Invoke-Query -ServerName Server1 -InstanceName MSSQLSERVER -Database master ` -Query 'SELECT name FROM sys.databases' -WithResults .EXAMPLE - Invoke-Query -SQLServer Server1 -SQLInstanceName MSSQLSERVER -Database master ` + Invoke-Query -ServerName Server1 -InstanceName MSSQLSERVER -Database master ` -Query 'RESTORE DATABASE [NorthWinds] WITH RECOVERY' .EXAMPLE @@ -1642,15 +1642,13 @@ function Invoke-Query param ( [Parameter(ParameterSetName='SqlServer')] - [Alias('ServerName')] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter(ParameterSetName='SqlServer')] - [Alias('InstanceName')] [System.String] - $SQLInstanceName = 'MSSQLSERVER', + $InstanceName = 'MSSQLSERVER', [Parameter(Mandatory = $true)] [System.String] @@ -1696,8 +1694,8 @@ function Invoke-Query elseif ($PSCmdlet.ParameterSetName -eq 'SqlServer') { $connectSQLParameters = @{ - ServerName = $SQLServer - InstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName LoginType = $LoginType StatementTimeout = $StatementTimeout } @@ -1865,10 +1863,10 @@ function Test-LoginEffectivePermissions $permissionsPresent = $false $invokeQueryParameters = @{ - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Database = 'master' - WithResults = $true + ServerName = $SQLServer + InstanceName = $SQLInstanceName + Database = 'master' + WithResults = $true } if ( [System.String]::IsNullOrEmpty($SecurableName) ) @@ -1959,10 +1957,10 @@ function Test-AvailabilityReplicaSeedingModeAutomatic if ( $serverObject.Version -ge 13 ) { $invokeQueryParams = @{ - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName - Database = 'master' - WithResults = $true + ServerName = $SQLServer + InstanceName = $SQLInstanceName + Database = 'master' + WithResults = $true } $queryToGetSeedingMode = " diff --git a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 index 032b940cb..ccb312d85 100644 --- a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -1452,8 +1452,8 @@ InModuleScope 'SqlServerDsc.Common' { } $queryParams = @{ - SQLServer = 'Server1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'Server1' + InstanceName = 'MSSQLSERVER' Database = 'master' Query = '' DatabaseCredential = $mockSqlCredential @@ -1461,7 +1461,7 @@ InModuleScope 'SqlServerDsc.Common' { $queryParametersWithSMO = @{ Query = '' - SqlServerObject = $mockSMOServer + SqlServerObject = $mockSMOServer Database = 'master' } From 416462ee712c343c9eaae05848e754530f14d847 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 18 Jul 2019 13:30:27 +0200 Subject: [PATCH 2/2] Parameters now match that of Connect-SQL (issue #1392) --- CHANGELOG.md | 16 +- .../MSFT_SqlAGDatabase.psm1 | 10 +- .../MSFT_SqlAlwaysOnService.psm1 | 2 +- .../MSFT_SqlDatabaseDefaultLocation.psm1 | 2 +- DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 | 2 +- .../MSFT_SqlServerConfiguration.psm1 | 2 +- .../MSFT_SqlServerNetwork.psm1 | 6 +- .../MSFT_SqlServerSecureConnection.psm1 | 6 +- .../MSFT_SqlServiceAccount.psm1 | 3 +- DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 | 2 +- .../SqlServerDsc.Common.psm1 | 168 +++++++++--------- Tests/Unit/SqlServerDsc.Common.Tests.ps1 | 76 ++++---- 12 files changed, 158 insertions(+), 137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d4fc26c7..db2bdcacb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - Changes to helper function Invoke-Query - Fixes issues in [issue #1355](https://github.com/PowerShell/SqlServerDsc/issues/1355). - Works together with Connect-SQL now. - - Parameters now match that of Connect-SQL. + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). - Can now pass in credentials. - Can now pass in 'Microsoft.SqlServer.Management.Smo.Server' object. - Can also pipe in 'Microsoft.SqlServer.Management.Smo.Server' object. @@ -26,6 +26,20 @@ - Changes to helper function Connect-SQL - When impersonating WindowsUser credential use the NetworkCredential UserName. - Added additional verbose logging. + - Changes to helper function Connect-SQLAnalysis + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). + - Changes to helper function Restart-SqlService + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). + - Changes to helper function Restart-ReportingServicesService + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). + - Changes to helper function Split-FullSqlInstanceName + - Parameters and function name changed to use correct casing. + - Changes to helper function Get-SqlInstanceMajorVersion + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). + - Changes to helper function Test-LoginEffectivePermissions + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). + - Changes to helper function Test-AvailabilityReplicaSeedingModeAutomatic + - Parameters now match that of Connect-SQL ([issue #1392](https://github.com/PowerShell/SqlServerDsc/issues/1392)). - Changes to SqlServerSecureConnection - Forced $Thumbprint to lowercase to fix [issue #1350](https://github.com/PowerShell/SqlServerDsc/issues/1350). - Add parameter SuppressRestart with default value false. diff --git a/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 index be39f88ee..0b450e717 100644 --- a/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 +++ b/DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1 @@ -316,7 +316,7 @@ function Set-TargetResource $availabilityReplicaFilestreamLevel = @{} foreach ( $availabilityGroupReplica in $secondaryReplicas ) { - $connectSqlParameters = Split-FullSQLInstanceName -FullSQLInstanceName $availabilityGroupReplica.Name + $connectSqlParameters = Split-FullSqlInstanceName -FullSqlInstanceName $availabilityGroupReplica.Name $currentAvailabilityGroupReplicaServerObject = Connect-SQL @connectSqlParameters $availabilityReplicaFilestreamLevel.Add($availabilityGroupReplica.Name, $currentAvailabilityGroupReplicaServerObject.FilestreamLevel) } @@ -334,7 +334,7 @@ function Set-TargetResource $availabilityReplicaContainmentEnabled = @{} foreach ( $availabilityGroupReplica in $secondaryReplicas ) { - $connectSqlParameters = Split-FullSQLInstanceName -FullSQLInstanceName $availabilityGroupReplica.Name + $connectSqlParameters = Split-FullSqlInstanceName -FullSqlInstanceName $availabilityGroupReplica.Name $currentAvailabilityGroupReplicaServerObject = Connect-SQL @connectSqlParameters $availabilityReplicaContainmentEnabled.Add($availabilityGroupReplica.Name, $currentAvailabilityGroupReplicaServerObject.Configuration.ContainmentEnabled.ConfigValue) } @@ -355,7 +355,7 @@ function Set-TargetResource $availabilityReplicaMissingDirectories = @{} foreach ( $availabilityGroupReplica in $secondaryReplicas ) { - $connectSqlParameters = Split-FullSQLInstanceName -FullSQLInstanceName $availabilityGroupReplica.Name + $connectSqlParameters = Split-FullSqlInstanceName -FullSqlInstanceName $availabilityGroupReplica.Name $currentAvailabilityGroupReplicaServerObject = Connect-SQL @connectSqlParameters $missingDirectories = @() @@ -393,7 +393,7 @@ function Set-TargetResource $availabilityReplicaMissingCertificates = @{} foreach ( $availabilityGroupReplica in $secondaryReplicas ) { - $connectSqlParameters = Split-FullSQLInstanceName -FullSQLInstanceName $availabilityGroupReplica.Name + $connectSqlParameters = Split-FullSqlInstanceName -FullSqlInstanceName $availabilityGroupReplica.Name $currentAvailabilityGroupReplicaServerObject = Connect-SQL @connectSqlParameters [System.Array]$installedCertificateThumbprints = $currentAvailabilityGroupReplicaServerObject.Databases['master'].Certificates | ForEach-Object { [System.BitConverter]::ToString($_.Thumbprint) } @@ -540,7 +540,7 @@ function Set-TargetResource foreach ( $availabilityGroupReplica in $secondaryReplicas ) { # Connect to the replica - $connectSqlParameters = Split-FullSQLInstanceName -FullSQLInstanceName $availabilityGroupReplica.Name + $connectSqlParameters = Split-FullSqlInstanceName -FullSqlInstanceName $availabilityGroupReplica.Name $currentAvailabilityGroupReplicaServerObject = Connect-SQL @connectSqlParameters $currentReplicaAvailabilityGroupObject = $currentAvailabilityGroupReplicaServerObject.AvailabilityGroups[$AvailabilityGroupName] diff --git a/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 index 1798de057..053f479c2 100644 --- a/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 +++ b/DSCResources/MSFT_SqlAlwaysOnService/MSFT_SqlAlwaysOnService.psm1 @@ -150,7 +150,7 @@ function Set-TargetResource ) # Now restart the SQL service so that all dependent services are also returned to their previous state - Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout + Restart-SqlService -ServerName $ServerName -InstanceName $InstanceName -Timeout $RestartTimeout # Verify always on was set if ( -not ( Test-TargetResource @PSBoundParameters ) ) diff --git a/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 index 823c6a140..76e7b4a53 100644 --- a/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 +++ b/DSCResources/MSFT_SqlDatabaseDefaultLocation/MSFT_SqlDatabaseDefaultLocation.psm1 @@ -193,7 +193,7 @@ Function Set-TargetResource if ($RestartService) { Write-Verbose -Message ($script:localizedData.RestartSqlServer -f $ServerName, $InstanceName) - Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName + Restart-SqlService -ServerName $ServerName -InstanceName $InstanceName } } catch diff --git a/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 index 71dc65df9..13b461c4d 100644 --- a/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 +++ b/DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1 @@ -726,7 +726,7 @@ function Set-TargetResource elseif ( $restartReportingService -and (-not $SuppressRestart) ) { Write-Verbose -Message $script:localizedData.Restart - Restart-ReportingServicesService -SQLInstanceName $InstanceName -WaitTime 30 + Restart-ReportingServicesService -InstanceName $InstanceName -WaitTime 30 } } diff --git a/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 index c30c72917..cc70dfbf6 100644 --- a/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 +++ b/DSCResources/MSFT_SqlServerConfiguration/MSFT_SqlServerConfiguration.psm1 @@ -171,7 +171,7 @@ function Set-TargetResource -f $ServerName, $InstanceName ) - Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout + Restart-SqlService -ServerName $ServerName -InstanceName $InstanceName -Timeout $RestartTimeout } else { diff --git a/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 index 31a82a65a..1e6b013fe 100644 --- a/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 +++ b/DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1 @@ -215,9 +215,9 @@ function Set-TargetResource if ($RestartService -and $isRestartNeeded) { $restartSqlServiceParameters = @{ - SQLServer = $ServerName - SQLInstanceName = $InstanceName - Timeout = $RestartTimeout + ServerName = $ServerName + InstanceName = $InstanceName + Timeout = $RestartTimeout } if ($getTargetResourceResult.IsEnabled -eq $false -and $IsEnabled -eq $true) diff --git a/DSCResources/MSFT_SqlServerSecureConnection/MSFT_SqlServerSecureConnection.psm1 b/DSCResources/MSFT_SqlServerSecureConnection/MSFT_SqlServerSecureConnection.psm1 index f18efa3a5..248bb1bbb 100644 --- a/DSCResources/MSFT_SqlServerSecureConnection/MSFT_SqlServerSecureConnection.psm1 +++ b/DSCResources/MSFT_SqlServerSecureConnection/MSFT_SqlServerSecureConnection.psm1 @@ -236,7 +236,6 @@ function Set-TargetResource ForceEncryption = $ForceEncryption Ensure = $Ensure ServiceAccount = $ServiceAccount - SuppressRestart = $SuppressRestart } $encryptionState = Get-TargetResource @parameters @@ -282,7 +281,7 @@ function Set-TargetResource $script:localizedData.RestartingService -f $InstanceName ) - Restart-SqlService -SQLServer localhost -SQLInstanceName $InstanceName + Restart-SqlService -ServerName localhost -InstanceName $InstanceName } } @@ -309,6 +308,8 @@ function Set-TargetResource If set to $true then the required restart will be suppressed. You will need to restart the service before changes will take effect. The default value is $false. + + Not used in Test-TargetResource. #> function Test-TargetResource { @@ -349,7 +350,6 @@ function Test-TargetResource ForceEncryption = $ForceEncryption Ensure = $Ensure ServiceAccount = $ServiceAccount - SuppressRestart = $SuppressRestart } Write-Verbose -Message ( diff --git a/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 index f5b841338..d56d23f23 100644 --- a/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 +++ b/DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1 @@ -260,7 +260,8 @@ function Set-TargetResource if ($RestartService) { Write-Verbose -Message ($script:localizedData.RestartingService -f $InstanceName) - Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName + + Restart-SqlService -ServerName $ServerName -InstanceName $InstanceName } } diff --git a/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 index b50142baf..d9d237243 100644 --- a/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 +++ b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 @@ -336,7 +336,7 @@ function Get-TargetResource $analysisServiceAccountUsername = $analysisServiceCimInstance.StartName $AsSvcStartupType = ConvertTo-StartupType -StartMode $analysisServiceCimInstance.StartMode - $analysisServer = Connect-SQLAnalysis -SQLServer $sqlHostName -SQLInstanceName $InstanceName + $analysisServer = Connect-SQLAnalysis -ServerName $sqlHostName -InstanceName $InstanceName $analysisCollation = $analysisServer.ServerProperties['CollationName'].Value $analysisDataDirectory = $analysisServer.ServerProperties['DataDir'].Value diff --git a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 3ccccaa6c..883d0fed6 100644 --- a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -1075,10 +1075,10 @@ function Connect-SQL .SYNOPSIS Connect to a SQL Server Analysis Service and return the server object. - .PARAMETER SQLServer + .PARAMETER ServerName String containing the host name of the SQL Server to connect to. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName String containing the SQL Server Analysis Service instance to connect to. .PARAMETER SetupCredential @@ -1093,12 +1093,12 @@ function Connect-SQLAnalysis [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer = $env:COMPUTERNAME, + $ServerName = $env:COMPUTERNAME, [Parameter()] [ValidateNotNullOrEmpty()] [System.String] - $SQLInstanceName = 'MSSQLSERVER', + $InstanceName = 'MSSQLSERVER', [Parameter()] [ValidateNotNullOrEmpty()] @@ -1109,13 +1109,13 @@ function Connect-SQLAnalysis $null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.AnalysisServices') - if ($SQLInstanceName -eq 'MSSQLSERVER') + if ($InstanceName -eq 'MSSQLSERVER') { - $analysisServiceInstance = $SQLServer + $analysisServiceInstance = $ServerName } else { - $analysisServiceInstance = "$SQLServer\$SQLInstanceName" + $analysisServiceInstance = "$ServerName\$InstanceName" } if ($SetupCredential) @@ -1158,7 +1158,7 @@ function Connect-SQLAnalysis .SYNOPSIS Returns the major SQL version for the specific instance. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName String containing the name of the SQL instance to be configured. Default value is 'MSSQLSERVER'. .OUTPUTS @@ -1172,15 +1172,15 @@ function Get-SqlInstanceMajorVersion ( [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName = 'MSSQLSERVER' + $InstanceName = 'MSSQLSERVER' ) - $sqlInstanceId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$SQLInstanceName + $sqlInstanceId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$InstanceName $sqlVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$sqlInstanceId\Setup").Version if (-not $sqlVersion) { - $errorMessage = $script:localizedData.SqlServerVersionIsInvalid -f $SQLInstanceName + $errorMessage = $script:localizedData.SqlServerVersionIsInvalid -f $InstanceName New-InvalidResultException -Message $errorMessage } @@ -1321,10 +1321,10 @@ function Import-SQLPSModule .SYNOPSIS Restarts a SQL Server instance and associated services - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configured. Default is 'MSSQLSERVER' .PARAMETER Timeout @@ -1345,16 +1345,16 @@ function Import-SQLPSModule resource when it's used to disable protocol. .EXAMPLE - Restart-SqlService -SQLServer localhost + Restart-SqlService -ServerName localhost .EXAMPLE - Restart-SqlService -SQLServer localhost -SQLInstanceName 'NamedInstance' + Restart-SqlService -ServerName localhost -InstanceName 'NamedInstance' .EXAMPLE - Restart-SqlService -SQLServer localhost -SQLInstanceName 'NamedInstance' -SkipClusterCheck -SkipWaitForOnline + Restart-SqlService -ServerName localhost -InstanceName 'NamedInstance' -SkipClusterCheck -SkipWaitForOnline .EXAMPLE - Restart-SqlService -SQLServer CLU01 -Timeout 300 + Restart-SqlService -ServerName CLU01 -Timeout 300 #> function Restart-SqlService { @@ -1363,11 +1363,11 @@ function Restart-SqlService ( [Parameter(Mandatory = $true)] [System.String] - $SQLServer, + $ServerName, [Parameter()] [System.String] - $SQLInstanceName = 'MSSQLSERVER', + $InstanceName = 'MSSQLSERVER', [Parameter()] [System.UInt32] @@ -1385,7 +1385,7 @@ function Restart-SqlService if (-not $SkipClusterCheck.IsPresent) { ## Connect to the instance - $serverObject = Connect-SQL -ServerName $SQLServer -InstanceName $SQLInstanceName + $serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName if ($serverObject.IsClustered) { @@ -1430,13 +1430,13 @@ function Restart-SqlService if ($restartWindowsService) { - if ($SQLInstanceName -eq 'MSSQLSERVER') + if ($InstanceName -eq 'MSSQLSERVER') { $serviceName = 'MSSQLSERVER' } else { - $serviceName = 'MSSQL${0}' -f $SQLInstanceName + $serviceName = 'MSSQL${0}' -f $InstanceName } Write-Verbose -Message ($script:localizedData.GetServiceInformation -f 'SQL Server') -Verbose @@ -1459,7 +1459,7 @@ function Restart-SqlService } } - Write-Verbose -Message ($script:localizedData.WaitingInstanceTimeout -f $SQLServer, $SQLInstanceName, $Timeout) -Verbose + Write-Verbose -Message ($script:localizedData.WaitingInstanceTimeout -f $ServerName, $InstanceName, $Timeout) -Verbose if (-not $SkipWaitForOnline.IsPresent) { @@ -1468,7 +1468,7 @@ function Restart-SqlService do { # This call, if it fails, will take between ~9-10 seconds to return. - $testConnectionServerObject = Connect-SQL -ServerName $SQLServer -InstanceName $SQLInstanceName -ErrorAction SilentlyContinue + $testConnectionServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction SilentlyContinue # Make sure we have an SMO object to test Status if ($testConnectionServerObject) @@ -1488,7 +1488,7 @@ function Restart-SqlService # Was the timeout period reach before able to connect to the SQL Server instance? if (-not $testConnectionServerObject -or $testConnectionServerObject.Status -ne 'Online') { - $errorMessage = $script:localizedData.FailedToConnectToInstanceTimeout -f $SQLServer, $SQLInstanceName, $Timeout + $errorMessage = $script:localizedData.FailedToConnectToInstanceTimeout -f $ServerName, $InstanceName, $Timeout New-InvalidOperationException -Message $errorMessage } } @@ -1498,7 +1498,7 @@ function Restart-SqlService .SYNOPSIS Restarts a Reporting Services instance and associated services - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the instance to be restarted. Default is 'MSSQLSERVER' (the default instance). @@ -1513,14 +1513,14 @@ function Restart-ReportingServicesService ( [Parameter()] [System.String] - $SQLInstanceName = 'MSSQLSERVER', + $InstanceName = 'MSSQLSERVER', [Parameter()] [System.UInt16] $WaitTime = 0 ) - if ($SQLInstanceName -eq 'SSRS') + if ($InstanceName -eq 'SSRS') { # Check if we're dealing with SSRS 2017 $ServiceName = 'SQLServerReportingServices' @@ -1537,9 +1537,9 @@ function Restart-ReportingServicesService Pre-2017 SSRS support multiple instances, check if we're dealing with a named instance. #> - if (-not ($SQLInstanceName -eq 'MSSQLSERVER')) + if (-not ($InstanceName -eq 'MSSQLSERVER')) { - $ServiceName += '${0}' -f $SQLInstanceName + $ServiceName += '${0}' -f $InstanceName } Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose @@ -1794,10 +1794,10 @@ function Update-AvailabilityGroupReplica .SYNOPSIS Impersonates a login and determines whether required permissions are present. - .PARAMETER SQLServer + .PARAMETER ServerName String containing the host name of the SQL Server to connect to. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName String containing the SQL Server Database Engine instance to connect to. .PARAMETER LoginName @@ -1834,11 +1834,11 @@ function Test-LoginEffectivePermissions [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -1863,8 +1863,8 @@ function Test-LoginEffectivePermissions $permissionsPresent = $false $invokeQueryParameters = @{ - ServerName = $SQLServer - InstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName Database = 'master' WithResults = $true } @@ -1888,7 +1888,7 @@ function Test-LoginEffectivePermissions " } - Write-Verbose -Message ($script:localizedData.GetEffectivePermissionForLogin -f $LoginName, $sqlInstanceName) -Verbose + Write-Verbose -Message ($script:localizedData.GetEffectivePermissionForLogin -f $LoginName, $InstanceName) -Verbose $loginEffectivePermissionsResult = Invoke-Query @invokeQueryParameters -Query $queryToGetEffectivePermissionsForLogin $loginEffectivePermissions = $loginEffectivePermissionsResult.Tables.Rows.permission_name @@ -1912,10 +1912,10 @@ function Test-LoginEffectivePermissions .SYNOPSIS Determine if the seeding mode of the specified availability group is automatic. - .PARAMETER SQLServer + .PARAMETER ServerName The hostname of the server that hosts the SQL instance. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName The name of the SQL instance that hosts the availability group. .PARAMETER AvailabilityGroupName @@ -1931,11 +1931,11 @@ function Test-AvailabilityReplicaSeedingModeAutomatic [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [System.String] - $SQLInstanceName, + $InstanceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -1951,14 +1951,14 @@ function Test-AvailabilityReplicaSeedingModeAutomatic # Assume automatic seeding is disabled by default $availabilityReplicaSeedingModeAutomatic = $false - $serverObject = Connect-SQL -ServerName $SQLServer -InstanceName $SQLInstanceName + $serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName # Only check the seeding mode if this is SQL 2016 or newer if ( $serverObject.Version -ge 13 ) { $invokeQueryParams = @{ - ServerName = $SQLServer - InstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName Database = 'master' WithResults = $true } @@ -2042,87 +2042,93 @@ function Test-ImpersonatePermissions # The impersonate any login permission only exists in SQL 2014 and above $testLoginEffectivePermissionsParams = @{ - SQLServer = $ServerObject.ComputerNamePhysicalNetBIOS - SQLInstanceName = $ServerObject.ServiceName - LoginName = $ServerObject.ConnectionContext.TrueLogin - Permissions = @('IMPERSONATE ANY LOGIN') + ServerName = $ServerObject.ComputerNamePhysicalNetBIOS + InstanceName = $ServerObject.ServiceName + LoginName = $ServerObject.ConnectionContext.TrueLogin + Permissions = @('IMPERSONATE ANY LOGIN') } $impersonatePermissionsPresent = Test-LoginEffectivePermissions @testLoginEffectivePermissionsParams + if ($impersonatePermissionsPresent) { - Write-Verbose -Message ( 'The login "{0}" has impersonate any login permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" has impersonate any login permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.SInstanceName ) -Verbose return $impersonatePermissionsPresent } else { - Write-Verbose -Message ( 'The login "{0}" does not have impersonate any login permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" does not have impersonate any login permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName ) -Verbose } # Check for sysadmin / control server permission which allows impersonation $testLoginEffectivePermissionsParams = @{ - SQLServer = $ServerObject.ComputerNamePhysicalNetBIOS - SQLInstanceName = $ServerObject.ServiceName - LoginName = $ServerObject.ConnectionContext.TrueLogin - Permissions = @('CONTROL SERVER') + ServerName = $ServerObject.ComputerNamePhysicalNetBIOS + InstanceName = $ServerObject.ServiceName + LoginName = $ServerObject.ConnectionContext.TrueLogin + Permissions = @('CONTROL SERVER') } + $impersonatePermissionsPresent = Test-LoginEffectivePermissions @testLoginEffectivePermissionsParams + if ($impersonatePermissionsPresent) { - Write-Verbose -Message ( 'The login "{0}" has control server permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" has control server permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName ) -Verbose return $impersonatePermissionsPresent } else { - Write-Verbose -Message ( 'The login "{0}" does not have control server permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" does not have control server permissions on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName ) -Verbose } if (-not [System.String]::IsNullOrEmpty($SecurableName)) { # Check for login-specific impersonation permissions $testLoginEffectivePermissionsParams = @{ - SQLServer = $ServerObject.ComputerNamePhysicalNetBIOS - SQLInstanceName = $ServerObject.ServiceName - LoginName = $ServerObject.ConnectionContext.TrueLogin - Permissions = @('IMPERSONATE') - SecurableClass = 'LOGIN' - SecurableName = $SecurableName + ServerName = $ServerObject.ComputerNamePhysicalNetBIOS + InstanceName = $ServerObject.ServiceName + LoginName = $ServerObject.ConnectionContext.TrueLogin + Permissions = @('IMPERSONATE') + SecurableClass = 'LOGIN' + SecurableName = $SecurableName } $impersonatePermissionsPresent = Test-LoginEffectivePermissions @testLoginEffectivePermissionsParams + if ($impersonatePermissionsPresent) { - Write-Verbose -Message ( 'The login "{0}" has impersonate permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName, $SecurableName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" has impersonate permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName, $SecurableName ) -Verbose return $impersonatePermissionsPresent } else { - Write-Verbose -Message ( 'The login "{0}" does not have impersonate permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName, $SecurableName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" does not have impersonate permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName, $SecurableName ) -Verbose } # Check for login-specific control permissions $testLoginEffectivePermissionsParams = @{ - SQLServer = $ServerObject.ComputerNamePhysicalNetBIOS - SQLInstanceName = $ServerObject.ServiceName - LoginName = $ServerObject.ConnectionContext.TrueLogin - Permissions = @('CONTROL') - SecurableClass = 'LOGIN' - SecurableName = $SecurableName + ServerName = $ServerObject.ComputerNamePhysicalNetBIOS + InstanceName = $ServerObject.ServiceName + LoginName = $ServerObject.ConnectionContext.TrueLogin + Permissions = @('CONTROL') + SecurableClass = 'LOGIN' + SecurableName = $SecurableName } $impersonatePermissionsPresent = Test-LoginEffectivePermissions @testLoginEffectivePermissionsParams + if ($impersonatePermissionsPresent) { - Write-Verbose -Message ( 'The login "{0}" has control permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName, $SecurableName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" has control permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName, $SecurableName ) -Verbose return $impersonatePermissionsPresent } else { - Write-Verbose -Message ( 'The login "{0}" does not have control permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName, $SecurableName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" does not have control permissions on the instance "{1}\{2}" for the login "{3}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName, $SecurableName ) -Verbose } } - Write-Verbose -Message ( 'The login "{0}" does not have any impersonate permissions required on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.SQLServer, $testLoginEffectivePermissionsParams.SQLInstanceName ) -Verbose + Write-Verbose -Message ( 'The login "{0}" does not have any impersonate permissions required on the instance "{1}\{2}".' -f $testLoginEffectivePermissionsParams.LoginName, $testLoginEffectivePermissionsParams.ServerName, $testLoginEffectivePermissionsParams.InstanceName ) -Verbose + return $impersonatePermissionsPresent } @@ -2130,11 +2136,11 @@ function Test-ImpersonatePermissions .SYNOPSIS Takes a SQL Instance name in the format of 'Server\Instance' and splits it into a hash table prepared to be passed into Connect-SQL. - .PARAMETER FullSQLInstanceName + .PARAMETER FullSqlInstanceName The full SQL instance name string to be split. .OUTPUTS - Hash table with the properties SQLServer and SQLInstanceName. + Hash table with the properties ServerName and InstanceName. #> function Split-FullSqlInstanceName { @@ -2143,10 +2149,10 @@ function Split-FullSqlInstanceName [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] - $FullSQLInstanceName + $FullSqlInstanceName ) - $sqlServer, $sqlInstanceName = $FullSQLInstanceName.Split('\') + $sqlServer, $sqlInstanceName = $FullSqlInstanceName.Split('\') if ( [System.String]::IsNullOrEmpty($sqlInstanceName) ) { @@ -2191,10 +2197,10 @@ function Test-ClusterPermissions if ( $ServerObject.Logins[$loginName] -and -not $clusterPermissionsPresent ) { $testLoginEffectivePermissionsParams = @{ - SQLServer = $sqlServer - SQLInstanceName = $sqlInstanceName - LoginName = $loginName - Permissions = $availabilityGroupManagementPerms + ServerName = $sqlServer + InstanceName = $sqlInstanceName + LoginName = $loginName + Permissions = $availabilityGroupManagementPerms } $clusterPermissionsPresent = Test-LoginEffectivePermissions @testLoginEffectivePermissionsParams diff --git a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 index ccb312d85..228b14e98 100644 --- a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -1062,7 +1062,7 @@ InModuleScope 'SqlServerDsc.Common' { $mockDynamicStatus = 'Online' It 'Should restart SQL Service and running SQL Agent service' { - { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'MSSQLSERVER' } | Should -Not -Throw + { Restart-SqlService -ServerName $env:ComputerName -InstanceName 'MSSQLSERVER' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL -ParameterFilter { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1075,7 +1075,7 @@ InModuleScope 'SqlServerDsc.Common' { It 'Should restart SQL Service, and not do cluster cluster check' { Mock -CommandName Get-CimInstance - { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'NOCLUSTERCHECK' -SkipClusterCheck } | Should -Not -Throw + { Restart-SqlService -ServerName $env:ComputerName -InstanceName 'NOCLUSTERCHECK' -SkipClusterCheck } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL -Scope It -Exactly -Times 1 Assert-MockCalled -CommandName Get-Service -Scope It -Exactly -Times 1 @@ -1087,7 +1087,7 @@ InModuleScope 'SqlServerDsc.Common' { It 'Should restart SQL Service, and not do cluster cluster check nor check online status' { Mock -CommandName Get-CimInstance - { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'NOCONNECT' -SkipClusterCheck -SkipWaitForOnline } | Should -Not -Throw + { Restart-SqlService -ServerName $env:ComputerName -InstanceName 'NOCONNECT' -SkipClusterCheck -SkipWaitForOnline } | Should -Not -Throw Assert-MockCalled -CommandName Get-Service -Scope It -Exactly -Times 1 Assert-MockCalled -CommandName Restart-Service -Scope It -Exactly -Times 1 @@ -1097,7 +1097,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart SQL Service and not try to restart missing SQL Agent service' { - { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'NOAGENT' } | Should -Not -Throw + { Restart-SqlService -ServerName $env:ComputerName -InstanceName 'NOAGENT' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1108,7 +1108,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart SQL Service and not try to restart stopped SQL Agent service' { - { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'STOPPEDAGENT' } | Should -Not -Throw + { Restart-SqlService -ServerName $env:ComputerName -InstanceName 'STOPPEDAGENT' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1136,7 +1136,7 @@ InModuleScope 'SqlServerDsc.Common' { $errorMessage = $localizedData.FailedToConnectToInstanceTimeout -f $env:ComputerName, 'MSSQLSERVER', 4 { - Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'MSSQLSERVER' -Timeout 4 + Restart-SqlService -ServerName $env:ComputerName -InstanceName 'MSSQLSERVER' -Timeout 4 } | Should -Throw $errorMessage Assert-MockCalled -CommandName Connect-SQL -ParameterFilter { @@ -1213,7 +1213,7 @@ InModuleScope 'SqlServerDsc.Common' { $mockDynamicStatus = 'Online' It 'Should restart SQL Server and SQL Agent resources for a clustered default instance' { - { Restart-SqlService -SQLServer 'CLU01' } | Should -Not -Throw + { Restart-SqlService -ServerName 'CLU01' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1225,7 +1225,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart SQL Server and SQL Agent resources for a clustered named instance' { - { Restart-SqlService -SQLServer 'CLU01' -SQLInstanceName 'NAMEDINSTANCE' } | Should -Not -Throw + { Restart-SqlService -ServerName 'CLU01' -InstanceName 'NAMEDINSTANCE' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1237,7 +1237,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should not try to restart a SQL Agent resource that is not online' { - { Restart-SqlService -SQLServer 'CLU01' -SQLInstanceName 'STOPPEDAGENT' } | Should -Not -Throw + { Restart-SqlService -ServerName 'CLU01' -InstanceName 'STOPPEDAGENT' } | Should -Not -Throw Assert-MockCalled -CommandName Connect-SQL { $PSBoundParameters.ContainsKey('ErrorAction') -eq $false @@ -1313,7 +1313,7 @@ InModuleScope 'SqlServerDsc.Common' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$env:COMPUTERNAME\$mockInstanceName" - { Connect-SQLAnalysis -SQLInstanceName $mockInstanceName } | Should -Not -Throw + { Connect-SQLAnalysis -InstanceName $mockInstanceName } | Should -Not -Throw Assert-MockCalled -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1324,7 +1324,7 @@ InModuleScope 'SqlServerDsc.Common' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$env:COMPUTERNAME\$mockInstanceName;User ID=$mockSqlCredentialUserName;Password=$mockSqlCredentialPassword" - { Connect-SQLAnalysis -SQLInstanceName $mockInstanceName -SetupCredential $mockSqlCredential } | Should -Not -Throw + { Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockSqlCredential } | Should -Not -Throw Assert-MockCalled -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1371,11 +1371,11 @@ InModuleScope 'SqlServerDsc.Common' { $mockExpectedDataSource = "Force wrong data source" $testParameters = @{ - SQLServer = 'DummyHost' - SQLInstanceName = $mockInstanceName + ServerName = 'DummyHost' + InstanceName = $mockInstanceName } - $mockCorrectErrorMessage = ($script:localizedData.FailedToConnectToAnalysisServicesInstance -f "$($testParameters.SQLServer)\$($testParameters.SQLInstanceName)") + $mockCorrectErrorMessage = ($script:localizedData.FailedToConnectToAnalysisServicesInstance -f "$($testParameters.ServerName)\$($testParameters.InstanceName)") { Connect-SQLAnalysis @testParameters } | Should -Throw $mockCorrectErrorMessage Assert-MockCalled -CommandName New-Object -Exactly -Times 1 -Scope It ` @@ -1682,15 +1682,15 @@ InModuleScope 'SqlServerDsc.Common' { } $testLoginEffectiveServerPermissionsParams = @{ - SQLServer = 'Server1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'Server1' + InstanceName = 'MSSQLSERVER' Login = 'NT SERVICE\ClusSvc' Permissions = @() } $testLoginEffectiveLoginPermissionsParams = @{ - SQLServer = 'Server1' - SQLInstanceName = 'MSSQLSERVER' + ServerName = 'Server1' + InstanceName = 'MSSQLSERVER' Login = 'NT SERVICE\ClusSvc' Permissions = @() SecurableClass = 'LOGIN' @@ -2050,7 +2050,7 @@ InModuleScope 'SqlServerDsc.Common' { Context 'When calling Get-SqlInstanceMajorVersion' { It 'Should return the correct major SQL version number' { - $result = Get-SqlInstanceMajorVersion -SQLInstanceName $mockInstanceName + $result = Get-SqlInstanceMajorVersion -InstanceName $mockInstanceName $result | Should -Be $mockSqlMajorVersion Assert-MockCalled -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` @@ -2070,7 +2070,7 @@ InModuleScope 'SqlServerDsc.Common' { } -Verifiable $mockCorrectErrorMessage = ($script:localizedData.SqlServerVersionIsInvalid -f $mockInstanceName) - { Get-SqlInstanceMajorVersion -SQLInstanceName $mockInstanceName } | Should -Throw $mockCorrectErrorMessage + { Get-SqlInstanceMajorVersion -InstanceName $mockInstanceName } | Should -Throw $mockCorrectErrorMessage Assert-MockCalled -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_InstanceNames_SQL @@ -2200,9 +2200,9 @@ InModuleScope 'SqlServerDsc.Common' { } $testAvailabilityReplicaSeedingModeAutomaticParams = @{ - SQLServer = 'Server1' - SQLInstanceName = 'MSSQLSERVER' - AvailabilityGroupName = 'Group1' + ServerName = 'Server1' + InstanceName = 'MSSQLSERVER' + AvailabilityGroupName = 'Group1' AvailabilityReplicaName = 'Replica2' } @@ -2572,28 +2572,28 @@ InModuleScope 'SqlServerDsc.Common' { Assert-VerifiableMock } - Describe 'SqlServerDsc.Common\Split-FullSQLInstanceName' { - Context 'When the "FullSQLInstanceName" parameter is not supplied' { - It 'Should throw when the "FullSQLInstanceName" parameter is $null' { - { Split-FullSQLInstanceName -FullSQLInstanceName $null } | Should -Throw + Describe 'SqlServerDsc.Common\Split-FullSqlInstanceName' { + Context 'When the "FullSqlInstanceName" parameter is not supplied' { + It 'Should throw when the "FullSqlInstanceName" parameter is $null' { + { Split-FullSqlInstanceName -FullSqlInstanceName $null } | Should -Throw } - It 'Should throw when the "FullSQLInstanceName" parameter is an empty string' { - { Split-FullSQLInstanceName -FullSQLInstanceName '' } | Should -Throw + It 'Should throw when the "FullSqlInstanceName" parameter is an empty string' { + { Split-FullSqlInstanceName -FullSqlInstanceName '' } | Should -Throw } } - Context 'When the "FullSQLInstanceName" parameter is supplied' { - It 'Should throw when the "FullSQLInstanceName" parameter is "ServerName"' { - $result = Split-FullSQLInstanceName -FullSQLInstanceName 'ServerName' + Context 'When the "FullSqlInstanceName" parameter is supplied' { + It 'Should throw when the "FullSqlInstanceName" parameter is "ServerName"' { + $result = Split-FullSqlInstanceName -FullSqlInstanceName 'ServerName' $result.Count | Should -Be 2 $result.ServerName | Should -Be 'ServerName' $result.InstanceName | Should -Be 'MSSQLSERVER' } - It 'Should throw when the "FullSQLInstanceName" parameter is "ServerName\InstanceName"' { - $result = Split-FullSQLInstanceName -FullSQLInstanceName 'ServerName\InstanceName' + It 'Should throw when the "FullSqlInstanceName" parameter is "ServerName\InstanceName"' { + $result = Split-FullSqlInstanceName -FullSqlInstanceName 'ServerName\InstanceName' $result.Count | Should -Be 2 $result.ServerName | Should -Be 'ServerName' @@ -2724,7 +2724,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -SQLInstanceName 'MSSQLSERVER' } | Should -Not -Throw + { Restart-ReportingServicesService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw Assert-MockCalled -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2749,7 +2749,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -SQLInstanceName 'SSRS' } | Should -Not -Throw + { Restart-ReportingServicesService -InstanceName 'SSRS' } | Should -Not -Throw Assert-MockCalled -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2774,7 +2774,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -SQLInstanceName 'TEST' } | Should -Not -Throw + { Restart-ReportingServicesService -InstanceName 'TEST' } | Should -Not -Throw Assert-MockCalled -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2800,7 +2800,7 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -SQLInstanceName 'TEST' -WaitTime 1 } | Should -Not -Throw + { Restart-ReportingServicesService -InstanceName 'TEST' -WaitTime 1 } | Should -Not -Throw Assert-MockCalled -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName