Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlServerDsc: Consequently use parameters ServerName and InstanceName #1409

Merged
merged 2 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([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.
Expand All @@ -25,7 +25,21 @@
- 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 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.
Expand Down
16 changes: 8 additions & 8 deletions DSCResources/MSFT_SqlAGDatabase/MSFT_SqlAGDatabase.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -355,14 +355,14 @@ 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 = @()
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 )
{
Expand Down Expand Up @@ -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) }

Expand Down Expand Up @@ -540,13 +540,13 @@ 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]

# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DSCResources/MSFT_SqlRS/MSFT_SqlRS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ function Set-TargetResource
ForceEncryption = $ForceEncryption
Ensure = $Ensure
ServiceAccount = $ServiceAccount
SuppressRestart = $SuppressRestart
}

$encryptionState = Get-TargetResource @parameters
Expand Down Expand Up @@ -282,7 +281,7 @@ function Set-TargetResource
$script:localizedData.RestartingService -f $InstanceName
)

Restart-SqlService -SQLServer localhost -SQLInstanceName $InstanceName
Restart-SqlService -ServerName localhost -InstanceName $InstanceName
}
}

Expand All @@ -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
{
Expand Down Expand Up @@ -349,7 +350,6 @@ function Test-TargetResource
ForceEncryption = $ForceEncryption
Ensure = $Ensure
ServiceAccount = $ServiceAccount
SuppressRestart = $SuppressRestart
}

Write-Verbose -Message (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading