Skip to content

Commit

Permalink
Changes to SqlServiceAccount
Browse files Browse the repository at this point in the history
- Now the correct service type string value is returned by the function
  `Get-TargetResource`. Previously one value was passed in as a parameter
  (e.g. `DatabaseEngine`), but a different string value as returned
  (e.g. `SqlServer`). Now `Get-TargetResource` return the same values
  that can be passed as values in the parameter `ServiceType` (issue dsccommunity#981).
  • Loading branch information
johlju committed Feb 7, 2019
1 parent 1c60667 commit c281e19
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
- Add integration tests
([issue #744](https://github.com/PowerShell/SqlServerDsc/issues/744)).
[Maxime Daniou (@mdaniou)](https://github.com/mdaniou)
- Changes to SqlServiceAccount
- Now the correct service type string value is returned by the function
`Get-TargetResource`. Previously one value was passed in as a parameter
(e.g. `DatabaseEngine`), but a different string value as returned
(e.g. `SqlServer`). Now `Get-TargetResource` return the same values
that can be passed as values in the parameter `ServiceType`
([issue #981](https://github.com/PowerShell/SqlServerDsc/issues/981)).

## 12.2.0.0

Expand Down
91 changes: 88 additions & 3 deletions DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ function Get-TargetResource
# Replace a domain of '.' with the value for $ServerName
$serviceAccountName = $serviceObject.ServiceAccount -ireplace '^([\.])\\(.*)$', "$ServerName\`$2"

$serviceType = ConvertTo-ResourceServiceType -ServiceType $serviceObject.Type

# Return a hash table with the service information
return @{
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = $serviceObject.Type
ServiceType = $serviceType
ServiceAccountName = $serviceAccountName
}
}
Expand Down Expand Up @@ -271,7 +273,7 @@ function Set-TargetResource
.PARAMETER ServiceType
Type of service to be managed. Must be one of the following:
DatabaseEngine, SQLServerAgent, Search, IntegrationServices, AnalysisServices, ReportingServices, SQLServerBrowser, NotificationServices.
.PARAMETER VersionNumber
Version number of IntegrationServices.
Expand Down Expand Up @@ -306,7 +308,7 @@ function Get-ServiceObject
if (($ServiceType -eq 'IntegrationServices') -and ([String]::IsNullOrEmpty($VersionNumber)))
{
$errorMessage = $script:localizedData.MissingParameter -f $ServiceType
New-InvalidArgumentException -Message $errorMessage -ArgumentName 'VersionNumber'
New-InvalidArgumentException -Message $errorMessage -ArgumentName 'VersionNumber'
}

# Load the SMO libraries
Expand Down Expand Up @@ -405,6 +407,89 @@ function ConvertTo-ManagedServiceType
return $serviceTypeValue -as [Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]
}

<#
.SYNOPSIS
Converts from the string value, that was returned from the type
Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType, to the
appropriate project's standard SQL Service type string values.
.PARAMETER ServiceType
The string value of the Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType.
Must be one of the following:
SqlServer, SqlAgent, Search, SqlServerIntegrationService, AnalysisServer,
ReportServer, SqlBrowser, NotificationServer.
.NOTES
If an unknown type is passed in parameter ServiceType, the same type will
be returned.
.EXAMPLE
ConvertTo-ResourceServiceType -ServiceType 'SqlServer'
#>
function ConvertTo-ResourceServiceType
{
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty]
[System.String]
$ServiceType
)

# Map the project-specific ServiceType to a valid value from the ManagedServiceType enumeration
switch ($ServiceType)
{
'SqlServer'
{
$serviceTypeValue = 'DatabaseEngine'
}

'SqlAgent'
{
$serviceTypeValue = 'SQLServerAgent'
}

'Search'
{
$serviceTypeValue = 'Search'
}

'SqlServerIntegrationService'
{
$serviceTypeValue = 'IntegrationServices'
}

'AnalysisServer'
{
$serviceTypeValue = 'AnalysisServices'
}

'ReportServer'
{
$serviceTypeValue = 'ReportingServices'
}

'SqlBrowser'
{
$serviceTypeValue = 'SQLServerBrowser'
}

'NotificationServer'
{
$serviceTypeValue = 'NotificationServices'
}

default
{
$serviceTypeValue = $ServiceType
}
}

return $serviceTypeValue
}

<#
.SYNOPSIS
Gets the name of a service based on the instance name and type.
Expand Down

0 comments on commit c281e19

Please sign in to comment.