From eaac9d4132299fc62710c0970de751e46a477748 Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Wed, 10 Jun 2020 15:32:28 -0400 Subject: [PATCH 1/7] Initial Sync --- CHANGELOG.md | 1 + README.md | 30 ++ source/ConfigMgrCBDsc.psd1 | 3 +- .../DSC_CMReportingServicePoint.psm1 | 343 +++++++++++++ .../DSC_CMReportingServicePoint.schema.mof | 12 + .../DSC_CMReportingServicePoint.strings.psd1 | 12 + .../CMReportingServicePoint_Absent.ps1 | 18 + .../CMReportingServicePoint_Present.ps1 | 19 + tests/Unit/CMReportingServicePoint.tests.ps1 | 457 ++++++++++++++++++ 9 files changed, 894 insertions(+), 1 deletion(-) create mode 100644 source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 create mode 100644 source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof create mode 100644 source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 create mode 100644 source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Absent.ps1 create mode 100644 source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 create mode 100644 tests/Unit/CMReportingServicePoint.tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aafee0..3f63a94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added CMAssetIntelligencePoint Resource - Added VSCode Project Settings and PS Script Analyzer rules - Added Issue and PR template. +- Added CMReportingServicePoint Resource ### Changed diff --git a/README.md b/README.md index f54298a..d8e3c37 100644 --- a/README.md +++ b/README.md @@ -358,3 +358,33 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu - [CMAssetIntelligencePoint_Absent](Source\Examples\Resources\CMAssetIntelligencePoint\CMAssetIntelligencePoint_Absent.ps1) - [CMAssetIntelligencePoint_Present](Source\Examples\Resources\CMAssetIntelligencePoint\CMAssetIntelligencePoint_Present.ps1) + +### CMReportingServicePoint + +- **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration + Manager site. +- **[String] SiteServerName** _(Required)_: Specifies the Site Server to install + or configure the role on. +- **[String] DatabaseName** _(Write)_: Specifies the name of the Configuration + Manager database that you want to use as the data source for reports from Microsoft + SQL Server Reporting Services. +- **[String] DatabaseServerName** _(Write)_: Specifies the name of the Configuration + Manager database server that you want to use as the data source for reports from + Microsoft SQL Server Reporting Services. + To specify a database instance, use the format Server Name\Instance Name. +- **[String] FolderName** _(Write)_: Specifies the name of the report folder on + the report server. This parameter can only be used when installing the role. +- **[String] ReportServerInstance** _(Write)_: Specifies the name of an instance + of Microsoft SQL Server Reporting Services. This parameter can only be used + when installing the role. +- **[String] UserName** _(Write)_: Specifies a user name for an account that + Configuration Manager uses to connect with Microsoft SQL Server Reporting Services + and that gives this user access to the site database. +- **[String] Ensure** _(Write)_: Specifies whether the asset reporting + service point is present or absent. + - Values include: { Present | Absent } + +#### CMReportingServicePoint Examples + +- [CMReportingServicePoint_Absent](Source\Examples\Resources\CMReportingServicePoint\CMReportingServicePoint_Absent.ps1) +- [CMReportingServicePoint_Present](Source\Examples\Resources\CMReportingServicePoint\CMReportingServicePoint_Present.ps1) diff --git a/source/ConfigMgrCBDsc.psd1 b/source/ConfigMgrCBDsc.psd1 index a1ab2f6..6103cf3 100644 --- a/source/ConfigMgrCBDsc.psd1 +++ b/source/ConfigMgrCBDsc.psd1 @@ -51,6 +51,7 @@ 'CMBoundaryGroups' 'CMManagementPoint' 'CMAssetIntelligencePoint' + 'CMReportingServicePoint' ) <# @@ -64,7 +65,7 @@ # Tags applied to this module. These help with module discovery in online galleries. Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource', 'ConfigMgrCBDsc','CMAccounts','CMIniFile','Collections', - 'CMBoundaries','CMForestDiscovery','ClientStatusSettings','BoundaryGroups','ManagementPoint','CMAssetIntelligencePoint') + 'CMBoundaries','CMForestDiscovery','ClientStatusSettings','BoundaryGroups','ManagementPoint','CMAssetIntelligencePoint','ReportingServicePoint') # A URL to the license for this module. LicenseUri = 'https://github.com/dsccommunity/ConfigMgrCBDsc/blob/master/LICENSE' diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 new file mode 100644 index 0000000..b04dc1e --- /dev/null +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 @@ -0,0 +1,343 @@ +$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' +$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' + +Import-Module -Name $script:dscResourceCommonPath +Import-Module -Name $script:configMgrResourcehelper + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + + <# + .SYNOPSIS + This will return a hashtable of results. + + .PARAMETER SiteCode + Specifies the site code for Configuration Manager site. + + .PARAMETER SiteServerName + Specifies the Site Server to install or configure the role on. + + .Notes + In order to use this resource, SQL Server Reporting Services must be installed and configured. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $SiteServerName + ) + + Write-Verbose -Message $script:localizedData.RetrieveSettingValue + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + + $rspProps = (Get-CMReportingServicePoint -SiteCode $SiteCode -SiteSystemServerName $SiteServerName).Props + + if ($rspProps) + { + foreach ($rspProp in $rspProps) + { + switch ($rspProp.PropertyName) + { + 'DatabaseName' { $dbName = $rspProp.Value2 } + 'DatabaseServerName' { $dbServerName = $rspProp.Value2 } + 'UserName' { $account = $rspProp.Value2 } + 'ReportServerInstance' { $rptInstance = $rspProp.Value2 } + 'RootFolder' { $folder = $rspProp.Value2 } + } + } + + $status = 'Present' + } + else + { + $status = 'Absent' + } + + return @{ + SiteServerName = $SiteServerName + SiteCode = $SiteCode + DatabaseName = $dbName + DatabaseServerName = $dbServerName + UserName = $account + FolderName = $folder + ReportServerInstance = $rptInstance + Ensure = $status + } +} + + <# + .SYNOPSIS + This will set the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .PARAMETER SiteServerName + Specifies the Site Server to install or configure the role on. + + .PARAMETER DatabaseName + Specifies the name of the Configuration Manager database that you want to use as the data source for reports + from Microsoft SQL Server Reporting Services. + + .PARAMETER DatabaseServerName + Specifies the name of the Configuration Manager database server that you want to use as the data source for + reports from Microsoft SQL Server Reporting Services. + + To specify a database instance, use the format \. + + .PARAMETER FolderName + Specifies the name of the report folder on the report server. + This parameter can only be used when installing the role. + Once the role is installed, this parameter cannot be changed without uninstalling the role. + + .PARAMETER ReportServerInstance + Specifies the name of an instance of Microsoft SQL Server Reporting Services. + This parameter can only be used when installing the role. + Once the role is installed, this parameter cannot be changed without uninstalling the role. + + .PARAMETER UserName + Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server + Reporting Services and that gives this user access to the site database. + + If specifying an account the account must already exist in + Configuration Manager. This can be achieved by using the CMAccounts Resource. + + .PARAMETER Ensure + Specifies whether the asset intelligence synchronization point is present or absent. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $SiteServerName, + + [Parameter()] + [String] + $DatabaseName, + + [Parameter()] + [String] + $DatabaseServerName, + + [Parameter()] + [String] + $FolderName, + + [Parameter()] + [String] + $ReportServerInstance, + + [Parameter()] + [String] + $UserName, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] + $Ensure = 'Present' + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -SiteServerName $SiteServerName + + try + { + if ($Ensure -eq 'Present') + { + $evalList = @('DatabaseName','DatabaseServerName','UserName','FolderName','ReportServerInstance') + + foreach ($param in $PSBoundParameters.GetEnumerator()) + { + if ($evalList -contains $param.key) + { + if ($param.Value -ne $state[$param.key]) + { + Write-Verbose -Message ($script:localizedData.SettingValue -f $param.Key, $param.Value) + $buildingParams += @{ + $param.Key = $param.Value + } + } + } + } + + if ($state.Ensure -eq 'Absent') + { + if ([string]::IsNullOrEmpty($buildingParams.UserName)) + { + throw $script:localizedData.SpecifyUser + } + + if ($null -eq (Get-CMSiteSystemServer -SiteCode $SiteCode -SiteSystemServerName $SiteServerName)) + { + Write-Verbose -Message ($script:localizedData.SiteServerRole -f $SiteServerName) + New-CMSiteSystemServer -SiteCode $SiteCode -SiteSystemServerName $SiteServerName + } + + Write-Verbose -Message ($script:localizedData.AddRSPRole -f $SiteServerName) + Add-CMReportingServicePoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode @buildingParams + } + else + { + if ((-not [string]::IsNullOrEmpty($buildingParams.FolderName)) -or (-not [string]::IsNullOrEmpty($buildingParams.ReportServerInstance))) + { + throw $script:localizedData.ThrowParams + } + elseif ($buildingParams) + { + Set-CMReportingServicePoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode @buildingParams + } + } + } + elseif ($state.Ensure -eq 'Present') + { + Write-Verbose -Message ($script:localizedData.RemoveRSPRole -f $SiteServerName) + Remove-CMReportingServicePoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode + } + } + catch + { + throw $_ + } + finally + { + Set-Location -Path "$env:temp" + } +} + +<# + .SYNOPSIS + This will test the desired state. + + .PARAMETER SiteCode + Specifies a site code for the Configuration Manager site. + + .PARAMETER SiteServerName + Specifies the Site Server to install or configure the role on. + + .PARAMETER DatabaseName + Specifies the name of the Configuration Manager database that you want to use as the data source for reports + from Microsoft SQL Server Reporting Services. + + .PARAMETER DatabaseServerName + Specifies the name of the Configuration Manager database server that you want to use as the data source for + reports from Microsoft SQL Server Reporting Services. + + To specify a database instance, use the format \. + + .PARAMETER FolderName + Specifies the name of the report folder on the report server. + This parameter can only be used when installing the role. + Once the role is installed, this parameter cannot be changed without uninstalling the role. + + .PARAMETER ReportServerInstance + Specifies the name of an instance of Microsoft SQL Server Reporting Services. + This parameter can only be used when installing the role. + Once the role is installed, this parameter cannot be changed without uninstalling the role. + + .PARAMETER UserName + Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server + Reporting Services and that gives this user access to the site database. + + If specifying an account the account must already exist in + Configuration Manager. This can be achieved by using the CMAccounts Resource. + + .PARAMETER Ensure + Specifies whether the asset intelligence synchronization point is present or absent. +#> + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [String] + $SiteCode, + + [Parameter(Mandatory = $true)] + [String] + $SiteServerName, + + [Parameter()] + [String] + $DatabaseName, + + [Parameter()] + [String] + $DatabaseServerName, + + [Parameter()] + [String] + $FolderName, + + [Parameter()] + [String] + $ReportServerInstance, + + [Parameter()] + [String] + $UserName, + + [Parameter()] + [ValidateSet('Present','Absent')] + [String] + $Ensure = 'Present' + ) + + Import-ConfigMgrPowerShellModule -SiteCode $SiteCode + Set-Location -Path "$($SiteCode):\" + $state = Get-TargetResource -SiteCode $SiteCode -SiteServerName $SiteServerName + $result = $true + + if ($Ensure -eq 'Present') + { + if ($state.Ensure -eq 'Absent') + { + Write-Verbose -Message ($script:localizedData.RSPNotInstalled -f $SiteServerName) + $result = $false + } + else + { + $testParams = @{ + CurrentValues = $state + DesiredValues = $PSBoundParameters + ValuesToCheck = ('DatabaseName','DatabaseServerName','UserName','FolderName','ReportServerInstance') + } + + $result = Test-DscParameterState @testParams -Verbose + + if ($FolderName -or $ReportServerInstance) + { + Write-Warning -Message $script:localizedData.ThrowParams + } + } + } + elseif ($state.Ensure -eq 'Present') + { + Write-Verbose -Message ($script:localizedData.RSPAbsent -f $SiteServerName) + $result = $false + } + + Write-Verbose -Message ($script:localizedData.TestState -f $result) + Set-Location -Path "$env:temp" + return $result +} + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof new file mode 100644 index 0000000..e3f9417 --- /dev/null +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof @@ -0,0 +1,12 @@ +[ClassVersion("1.0.0"), FriendlyName("CMReportingServicePoint")] +class DSC_CMReportingServicePoint: OMI_BaseResource +{ + [Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; + [Key, Description("Specifies the Site Server to install or configure the role on.")] String SiteServerName; + [Write, Description("Specifies the name of the Configuration Manager database that you want to use as the data source for reports from Microsoft SQL Server Reporting Services.")] String DatabaseName; + [Write, Description("Specifies the name of the Configuration Manager database server that you want to use as the data source for reports from Microsoft SQL Server Reporting Services.")] String DatabaseServerName; + [Write, Description("Specifies the name of the report folder on the report server.")] String FolderName; + [Write, Description("Specifies the name of an instance of Microsoft SQL Server Reporting Services.")] String ReportServerInstance; + [Write, Description("Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database.")] String UserName; + [Write, Description("Specifies whether the reporting service point is present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; +}; diff --git a/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 new file mode 100644 index 0000000..9d8c287 --- /dev/null +++ b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 @@ -0,0 +1,12 @@ +ConvertFrom-StringData @' + RetrieveSettingValue = Getting information for the specified Reporting Service Point. + RSPNotInstalled = Reporting Service Point is not installed on server: {0}. + RSPAbsent = {0} Reporting Service Point expected absent returned Present. + TestState = Test-TargetResource compliance check returned: {0}. + SiteServerRole = {0} is not currently a site system server adding site system role. + AddRSPRole = Adding Reporting Service Point role to {0}. + SettingValue = Setting value: {0} to {1}. + RemoveRSPRole = Removing Reporting Service Point role from {0}. + SpecifyUser = The UserName parameter is required when installing the Reporting Service Point Role. + ThrowParams = Folder Name and Report Server Instance can not be changed once the Reporting Service Point is installed. +'@ diff --git a/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Absent.ps1 b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Absent.ps1 new file mode 100644 index 0000000..1035cf8 --- /dev/null +++ b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Absent.ps1 @@ -0,0 +1,18 @@ +<# + .SYNOPSIS + A DSC configuration script to remove a software update point from Configuration Manager. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMReportingServicePoint ExampleSettings + { + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + Ensure = 'Absent' + } + } +} diff --git a/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 new file mode 100644 index 0000000..6078093 --- /dev/null +++ b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 @@ -0,0 +1,19 @@ +<# + .SYNOPSIS + A DSC configuration script to add a software update point to Configuration Manager with default settings. +#> +Configuration Example +{ + Import-DscResource -ModuleName ConfigMgrCBDsc + + Node localhost + { + CMReportingServicePoint ExampleSettings + { + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + UserName = 'contoso\Admin' + Ensure = 'Present' + } + } +} diff --git a/tests/Unit/CMReportingServicePoint.tests.ps1 b/tests/Unit/CMReportingServicePoint.tests.ps1 new file mode 100644 index 0000000..41ee23d --- /dev/null +++ b/tests/Unit/CMReportingServicePoint.tests.ps1 @@ -0,0 +1,457 @@ +param () + +$script:dscModuleName = 'ConfigMgrCBDsc' +$script:dscResourceName = 'DSC_CMReportingServicePoint' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import Stub function + $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ConfigMgrCBDscStub.psm1') -Force -WarningAction SilentlyContinue +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +#Begin Testing +try +{ + InModuleScope $script:dscResourceName { + $moduleResourceName = 'ConfigMgrCBDsc - DSC_CMReportingServicePoint' + + Describe 'ConfigMgrCBDsc - DSC_CMReportingServicePoint\Get-TargetResource' -Tag 'Get'{ + BeforeAll{ + $getInput = @{ + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + } + + $getRSPReturn = @{ + Props = @( + @{ + PropertyName = 'DatabaseName' + Value2 = 'CM_LAB' + } + @{ + PropertyName = 'DatabaseServerName' + Value2 = 'CA01.contoso.com' + } + @{ + PropertyName = 'UserName' + Value2 = 'contoso\SQLAdmin' + } + @{ + PropertyName = 'ReportServerInstance' + Value2 = 'MSSQLSERVER' + } + @{ + PropertyName = 'RootFolder' + Value2 = 'ConfigMgr_LAB' + } + ) + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When retrieving reporting service point settings' { + + It 'Should return desired result when the reporting service point is not currently installed' { + Mock -CommandName Get-CMReportingServicePoint + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.SiteServerName | Should -Be -ExpectedValue 'CA01.contoso.com' + $result.DatabaseName | Should -Be -ExpectedValue $null + $result.DatabaseServerName | Should -Be -ExpectedValue $null + $result.UserName | Should -Be -ExpectedValue $null + $result.FolderName | Should -Be -ExpectedValue $null + $result.ReportServerInstance | Should -Be -ExpectedValue $null + $result.Ensure | Should -Be -ExpectedValue 'Absent' + } + + It 'Should return desired result when the reporting service point is currently installed' { + Mock -CommandName Get-CMReportingServicePoint -MockWith { $getRSPReturn } + + $result = Get-TargetResource @getInput + $result | Should -BeOfType System.Collections.HashTable + $result.SiteCode | Should -Be -ExpectedValue 'Lab' + $result.SiteServerName | Should -Be -ExpectedValue 'CA01.contoso.com' + $result.DatabaseName | Should -Be -ExpectedValue 'CM_LAB' + $result.DatabaseServerName | Should -Be -ExpectedValue 'CA01.contoso.com' + $result.UserName | Should -Be -ExpectedValue 'contoso\SQLAdmin' + $result.FolderName | Should -Be -ExpectedValue 'ConfigMgr_LAB' + $result.ReportServerInstance | Should -Be -ExpectedValue 'MSSQLSERVER' + $result.Ensure | Should -Be -ExpectedValue 'Present' + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMReportingServicePoint\Set-TargetResource' -Tag 'Set'{ + BeforeAll{ + $inputAbsent = @{ + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + Ensure = 'Absent' + } + + $inputMatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\SQLAdmin' + Ensure = 'Present' + } + + $inputMismatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\CMAdmin' + Ensure = 'Present' + } + + $getReturnAll = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\SQLAdmin' + FolderName = 'ConfigMgr_LAB' + ReportServerInstance = 'MSSQLSERVER' + Ensure = 'Present' + } + + $getReturnAbsent = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = $null + DatabaseServerName = $null + UserName = $null + FolderName = $null + ReportServerInstance = $null + Ensure = 'Absent' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + Mock -CommandName Get-CMSiteSystemServer + Mock -CommandName New-CMSiteSystemServer + Mock -CommandName Add-CMReportingServicePoint + Mock -CommandName Set-CMReportingServicePoint + Mock -CommandName Remove-CMReportingServicePoint + } + + Context 'When Set-TargetResource runs successfully' { + + It 'Should call expected commands for when changing settings' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + + Set-TargetResource @inputMismatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 1 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when reporting service point is absent' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + + Set-TargetResource @inputMatch + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands when software update point exists and expected absent' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + + Set-TargetResource @inputAbsent + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 1 -Scope It + } + } + + Context 'When Set-TargetResource throws' { + BeforeEach{ + $inputPresent = @{ + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + Ensure = 'Present' + } + + $immutableParamMismatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + FolderName = 'ConfigMgr_TST' + Ensure = 'Present' + } + + $userThrowMsg = 'The UserName parameter is required when installing the Reporting Service Point Role.' + + $paramThrowMsg = 'Folder Name and Report Server Instance can not be changed once the Reporting Service Point is installed.' + + } + + It 'Should call throws when the role needs to be installed and a username is not specified' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + + { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $userThrowMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call throws when an immutable parameter is specified for change' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + + { Set-TargetResource @immutableParamMismatch } | Should -Throw -ExpectedMessage $paramThrowMsg + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands and throw if Get-CMSiteSystemServer throws' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + Mock -CommandName Get-CMSiteSystemServer -MockWith { throw } + + { Set-TargetResource @inputMatch } | Should -Throw + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands and throw if New-CMSiteSystemServer throws' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + Mock -CommandName Get-CMSiteSystemServer + Mock -CommandName New-CMSiteSystemServer -MockWith { throw } + + { Set-TargetResource @inputMatch } | Should -Throw + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands and throw if Add-CMReportingServicePoint throws' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + Mock -CommandName New-CMSiteSystemServer -MockWith { $true } + Mock -CommandName Add-CMReportingServicePoint -MockWith { throw } + + { Set-TargetResource @inputMatch } | Should -Throw + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 1 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 1 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands and throw if Set-CMReportingServicePoint throws' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + Mock -CommandName Set-CMReportingServicePoint -MockWith { throw } + + { Set-TargetResource @inputMismatch } | Should -Throw + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly 1 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 0 -Scope It + } + + It 'Should call expected commands and throw if Remove-CMReportingServicePoint throws' { + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + Mock -CommandName Remove-CMReportingServicePoint -MockWith { throw } + + { Set-TargetResource @inputAbsent } | Should -Throw + Assert-MockCalled Import-ConfigMgrPowerShellModule -Exactly -Times 1 -Scope It + Assert-MockCalled Set-Location -Exactly -Times 2 -Scope It + Assert-MockCalled Get-TargetResource -Exactly -Times 1 -Scope It + Assert-MockCalled Get-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled New-CMSiteSystemServer -Exactly -Times 0 -Scope It + Assert-MockCalled Add-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Set-CMReportingServicePoint -Exactly -Times 0 -Scope It + Assert-MockCalled Remove-CMReportingServicePoint -Exactly -Times 1 -Scope It + } + } + } + + Describe 'ConfigMgrCBDsc - DSC_CMReportingServicePoint\Test-TargetResource' -Tag 'Test'{ + BeforeAll{ + $inputPresent = @{ + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + Ensure = 'Present' + } + + $inputAbsent = @{ + SiteCode = 'Lab' + SiteServerName = 'CA01.contoso.com' + Ensure = 'Absent' + } + + $inputMatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\SQLAdmin' + Ensure = 'Present' + } + + $inputMismatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\CMAdmin' + Ensure = 'Present' + } + + $immutableParamMismatch = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + FolderName = 'ConfigMgr_TST' + Ensure = 'Present' + } + + $getReturnAll = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = 'CM_LAB' + DatabaseServerName = 'CA01.contoso.com' + UserName = 'contoso\SQLAdmin' + FolderName = 'ConfigMgr_LAB' + ReportServerInstance = 'MSSQLSERVER' + Ensure = 'Present' + } + + $getReturnAbsent = @{ + SiteServerName = 'CA01.contoso.com' + SiteCode = 'Lab' + DatabaseName = $null + DatabaseServerName = $null + UserName = $null + FolderName = $null + ReportServerInstance = $null + Ensure = 'Absent' + } + + Mock -CommandName Import-ConfigMgrPowerShellModule + Mock -CommandName Set-Location + } + + Context 'When running Test-TargetResource and Get-TargetResource Returns ' { + BeforeEach{ + Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } + } + + It 'Should return desired result false when ensure = absent and RSP is present' { + + Test-TargetResource @inputAbsent | Should -Be $false + } + + It 'Should return desired result true when all returned values match inputs' { + + Test-TargetResource @inputMatch | Should -Be $true + } + + It 'Should return desired result false when there is a mismatch between returned values and inputs' { + + Test-TargetResource @inputMismatch | Should -Be $false + } + + It 'Should return desired result false when there is a mismatch with immutable parameters' { + + Test-TargetResource @immutableParamMismatch | Should -Be $false + } + } + + Context 'When running Test-TargetResource and Get-TargetResource Returns absent' { + BeforeEach{ + Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } + } + + It 'Should return desired result false when ensure = present and RSP is absent' { + + Test-TargetResource @inputPresent | Should -Be $false + } + + It 'Should return desired result true when ensure = absent and RSP is absent' { + + Test-TargetResource @inputAbsent | Should -Be $true + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} From 883925c438c71946138523904627d6485f2a6ecf Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Thu, 11 Jun 2020 07:45:34 -0400 Subject: [PATCH 2/7] Removing unneeded variable --- tests/Unit/CMReportingServicePoint.tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Unit/CMReportingServicePoint.tests.ps1 b/tests/Unit/CMReportingServicePoint.tests.ps1 index 41ee23d..ba6517b 100644 --- a/tests/Unit/CMReportingServicePoint.tests.ps1 +++ b/tests/Unit/CMReportingServicePoint.tests.ps1 @@ -36,8 +36,6 @@ Invoke-TestSetup try { InModuleScope $script:dscResourceName { - $moduleResourceName = 'ConfigMgrCBDsc - DSC_CMReportingServicePoint' - Describe 'ConfigMgrCBDsc - DSC_CMReportingServicePoint\Get-TargetResource' -Tag 'Get'{ BeforeAll{ $getInput = @{ From 7da0c2fbc289a2c7b7496017713a061c39f4bf0d Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Thu, 11 Jun 2020 07:52:28 -0400 Subject: [PATCH 3/7] Adding info to ReadMe --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d8e3c37..678e34c 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu management points. - **CMAssetIntelligencePoint**: Provides a resource for creating and managing the SCCM Asset Intelligence Synchronization Point role. +- **CMReportingServicePoint**: Provides a resource for creating and managing + the SCCM Reporting Service Point role. ### CMAccounts From e666fe2e66da7f3aa670dc38ea900414a793e7b6 Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Thu, 11 Jun 2020 10:21:49 -0400 Subject: [PATCH 4/7] Untabification --- .../DSC_CMReportingServicePoint.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 index b04dc1e..2fea7ea 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 @@ -323,7 +323,7 @@ function Test-TargetResource $result = Test-DscParameterState @testParams -Verbose - if ($FolderName -or $ReportServerInstance) + if ($FolderName -or $ReportServerInstance) { Write-Warning -Message $script:localizedData.ThrowParams } From 48154b8a521fafee5835d29d698f07d25da12c83 Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Wed, 17 Jun 2020 07:32:00 -0400 Subject: [PATCH 5/7] Addressing PR comments --- README.md | 4 +-- .../DSC_CMReportingServicePoint.psm1 | 28 ++++++++--------- .../DSC_CMReportingServicePoint.schema.mof | 2 +- .../DSC_CMReportingServicePoint.strings.psd1 | 8 ++--- tests/Unit/CMReportingServicePoint.tests.ps1 | 30 +++++++++---------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 780dc85..cf195d4 100644 --- a/README.md +++ b/README.md @@ -424,7 +424,7 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu - **[String] SiteCode** _(Key)_: Specifies the Site Code for the Configuration Manager site. -- **[String] SiteServerName** _(Required)_: Specifies the Site Server to install +- **[String] SiteServerName** _(Key)_: Specifies the Site Server to install or configure the role on. - **[String] DatabaseName** _(Write)_: Specifies the name of the Configuration Manager database that you want to use as the data source for reports from Microsoft @@ -438,7 +438,7 @@ Please check out common DSC Community [contributing guidelines](https://dsccommu - **[String] ReportServerInstance** _(Write)_: Specifies the name of an instance of Microsoft SQL Server Reporting Services. This parameter can only be used when installing the role. -- **[String] UserName** _(Write)_: Specifies a user name for an account that +- **[String] Username** _(Write)_: Specifies a Username for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database. - **[String] Ensure** _(Write)_: Specifies whether the asset reporting diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 index 2fea7ea..133a7e7 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 @@ -66,7 +66,7 @@ function Get-TargetResource SiteCode = $SiteCode DatabaseName = $dbName DatabaseServerName = $dbServerName - UserName = $account + Username = $account FolderName = $folder ReportServerInstance = $rptInstance Ensure = $status @@ -103,8 +103,8 @@ function Get-TargetResource This parameter can only be used when installing the role. Once the role is installed, this parameter cannot be changed without uninstalling the role. - .PARAMETER UserName - Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server + .PARAMETER Username + Specifies a Username for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database. If specifying an account the account must already exist in @@ -144,7 +144,7 @@ function Set-TargetResource [Parameter()] [String] - $UserName, + $Username, [Parameter()] [ValidateSet('Present','Absent')] @@ -160,7 +160,7 @@ function Set-TargetResource { if ($Ensure -eq 'Present') { - $evalList = @('DatabaseName','DatabaseServerName','UserName','FolderName','ReportServerInstance') + $evalList = @('DatabaseName','DatabaseServerName','Username','FolderName','ReportServerInstance') foreach ($param in $PSBoundParameters.GetEnumerator()) { @@ -178,7 +178,7 @@ function Set-TargetResource if ($state.Ensure -eq 'Absent') { - if ([string]::IsNullOrEmpty($buildingParams.UserName)) + if ([string]::IsNullOrEmpty($buildingParams.Username)) { throw $script:localizedData.SpecifyUser } @@ -189,7 +189,7 @@ function Set-TargetResource New-CMSiteSystemServer -SiteCode $SiteCode -SiteSystemServerName $SiteServerName } - Write-Verbose -Message ($script:localizedData.AddRSPRole -f $SiteServerName) + Write-Verbose -Message ($script:localizedData.AddRspRole -f $SiteServerName) Add-CMReportingServicePoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode @buildingParams } else @@ -206,7 +206,7 @@ function Set-TargetResource } elseif ($state.Ensure -eq 'Present') { - Write-Verbose -Message ($script:localizedData.RemoveRSPRole -f $SiteServerName) + Write-Verbose -Message ($script:localizedData.RemoveRspRole -f $SiteServerName) Remove-CMReportingServicePoint -SiteSystemServerName $SiteServerName -SiteCode $SiteCode } } @@ -250,8 +250,8 @@ function Set-TargetResource This parameter can only be used when installing the role. Once the role is installed, this parameter cannot be changed without uninstalling the role. - .PARAMETER UserName - Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server + .PARAMETER Username + Specifies a Username for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database. If specifying an account the account must already exist in @@ -293,7 +293,7 @@ function Test-TargetResource [Parameter()] [String] - $UserName, + $Username, [Parameter()] [ValidateSet('Present','Absent')] @@ -310,7 +310,7 @@ function Test-TargetResource { if ($state.Ensure -eq 'Absent') { - Write-Verbose -Message ($script:localizedData.RSPNotInstalled -f $SiteServerName) + Write-Verbose -Message ($script:localizedData.RspNotInstalled -f $SiteServerName) $result = $false } else @@ -318,7 +318,7 @@ function Test-TargetResource $testParams = @{ CurrentValues = $state DesiredValues = $PSBoundParameters - ValuesToCheck = ('DatabaseName','DatabaseServerName','UserName','FolderName','ReportServerInstance') + ValuesToCheck = ('DatabaseName','DatabaseServerName','Username','FolderName','ReportServerInstance') } $result = Test-DscParameterState @testParams -Verbose @@ -331,7 +331,7 @@ function Test-TargetResource } elseif ($state.Ensure -eq 'Present') { - Write-Verbose -Message ($script:localizedData.RSPAbsent -f $SiteServerName) + Write-Verbose -Message ($script:localizedData.RspAbsent -f $SiteServerName) $result = $false } diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof index e3f9417..6bbd391 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.schema.mof @@ -7,6 +7,6 @@ class DSC_CMReportingServicePoint: OMI_BaseResource [Write, Description("Specifies the name of the Configuration Manager database server that you want to use as the data source for reports from Microsoft SQL Server Reporting Services.")] String DatabaseServerName; [Write, Description("Specifies the name of the report folder on the report server.")] String FolderName; [Write, Description("Specifies the name of an instance of Microsoft SQL Server Reporting Services.")] String ReportServerInstance; - [Write, Description("Specifies a user name for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database.")] String UserName; + [Write, Description("Specifies a Username for an account that Configuration Manager uses to connect with Microsoft SQL Server Reporting Services and that gives this user access to the site database.")] String Username; [Write, Description("Specifies whether the reporting service point is present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; }; diff --git a/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 index 9d8c287..7661393 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 @@ -1,12 +1,12 @@ ConvertFrom-StringData @' RetrieveSettingValue = Getting information for the specified Reporting Service Point. RSPNotInstalled = Reporting Service Point is not installed on server: {0}. - RSPAbsent = {0} Reporting Service Point expected absent returned Present. + RspAbsent = {0} Reporting Service Point expected absent returned Present. TestState = Test-TargetResource compliance check returned: {0}. SiteServerRole = {0} is not currently a site system server adding site system role. - AddRSPRole = Adding Reporting Service Point role to {0}. + AddRspRole = Adding Reporting Service Point role to {0}. SettingValue = Setting value: {0} to {1}. - RemoveRSPRole = Removing Reporting Service Point role from {0}. - SpecifyUser = The UserName parameter is required when installing the Reporting Service Point Role. + RemoveRspRole = Removing Reporting Service Point role from {0}. + SpecifyUser = The Username parameter is required when installing the Reporting Service Point role. ThrowParams = Folder Name and Report Server Instance can not be changed once the Reporting Service Point is installed. '@ diff --git a/tests/Unit/CMReportingServicePoint.tests.ps1 b/tests/Unit/CMReportingServicePoint.tests.ps1 index ba6517b..478a04e 100644 --- a/tests/Unit/CMReportingServicePoint.tests.ps1 +++ b/tests/Unit/CMReportingServicePoint.tests.ps1 @@ -43,7 +43,7 @@ try SiteServerName = 'CA01.contoso.com' } - $getRSPReturn = @{ + $getRspReturn = @{ Props = @( @{ PropertyName = 'DatabaseName' @@ -73,7 +73,6 @@ try } Context 'When retrieving reporting service point settings' { - It 'Should return desired result when the reporting service point is not currently installed' { Mock -CommandName Get-CMReportingServicePoint @@ -83,14 +82,14 @@ try $result.SiteServerName | Should -Be -ExpectedValue 'CA01.contoso.com' $result.DatabaseName | Should -Be -ExpectedValue $null $result.DatabaseServerName | Should -Be -ExpectedValue $null - $result.UserName | Should -Be -ExpectedValue $null + $result.Username | Should -Be -ExpectedValue $null $result.FolderName | Should -Be -ExpectedValue $null $result.ReportServerInstance | Should -Be -ExpectedValue $null $result.Ensure | Should -Be -ExpectedValue 'Absent' } It 'Should return desired result when the reporting service point is currently installed' { - Mock -CommandName Get-CMReportingServicePoint -MockWith { $getRSPReturn } + Mock -CommandName Get-CMReportingServicePoint -MockWith { $getRspReturn } $result = Get-TargetResource @getInput $result | Should -BeOfType System.Collections.HashTable @@ -98,7 +97,7 @@ try $result.SiteServerName | Should -Be -ExpectedValue 'CA01.contoso.com' $result.DatabaseName | Should -Be -ExpectedValue 'CM_LAB' $result.DatabaseServerName | Should -Be -ExpectedValue 'CA01.contoso.com' - $result.UserName | Should -Be -ExpectedValue 'contoso\SQLAdmin' + $result.Username | Should -Be -ExpectedValue 'contoso\SQLAdmin' $result.FolderName | Should -Be -ExpectedValue 'ConfigMgr_LAB' $result.ReportServerInstance | Should -Be -ExpectedValue 'MSSQLSERVER' $result.Ensure | Should -Be -ExpectedValue 'Present' @@ -119,7 +118,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\SQLAdmin' + Username = 'contoso\SQLAdmin' Ensure = 'Present' } @@ -128,7 +127,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\CMAdmin' + Username = 'contoso\CMAdmin' Ensure = 'Present' } @@ -137,7 +136,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\SQLAdmin' + Username = 'contoso\SQLAdmin' FolderName = 'ConfigMgr_LAB' ReportServerInstance = 'MSSQLSERVER' Ensure = 'Present' @@ -148,7 +147,7 @@ try SiteCode = 'Lab' DatabaseName = $null DatabaseServerName = $null - UserName = $null + Username = $null FolderName = $null ReportServerInstance = $null Ensure = 'Absent' @@ -164,7 +163,6 @@ try } Context 'When Set-TargetResource runs successfully' { - It 'Should call expected commands for when changing settings' { Mock -CommandName Get-TargetResource -MockWith { $getReturnAll } @@ -225,13 +223,13 @@ try Ensure = 'Present' } - $userThrowMsg = 'The UserName parameter is required when installing the Reporting Service Point Role.' + $userThrowMsg = 'The Username parameter is required when installing the Reporting Service Point role.' $paramThrowMsg = 'Folder Name and Report Server Instance can not be changed once the Reporting Service Point is installed.' } - It 'Should call throws when the role needs to be installed and a username is not specified' { + It 'Should call throws when the role needs to be installed and a Username is not specified' { Mock -CommandName Get-TargetResource -MockWith { $getReturnAbsent } { Set-TargetResource @inputPresent } | Should -Throw -ExpectedMessage $userThrowMsg @@ -357,7 +355,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\SQLAdmin' + Username = 'contoso\SQLAdmin' Ensure = 'Present' } @@ -366,7 +364,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\CMAdmin' + Username = 'contoso\CMAdmin' Ensure = 'Present' } @@ -384,7 +382,7 @@ try SiteCode = 'Lab' DatabaseName = 'CM_LAB' DatabaseServerName = 'CA01.contoso.com' - UserName = 'contoso\SQLAdmin' + Username = 'contoso\SQLAdmin' FolderName = 'ConfigMgr_LAB' ReportServerInstance = 'MSSQLSERVER' Ensure = 'Present' @@ -395,7 +393,7 @@ try SiteCode = 'Lab' DatabaseName = $null DatabaseServerName = $null - UserName = $null + Username = $null FolderName = $null ReportServerInstance = $null Ensure = 'Absent' From 1bbf84d6ca5b0a816d5a01976ad9e06862bf4bb0 Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Wed, 17 Jun 2020 10:17:15 -0400 Subject: [PATCH 6/7] finalizing some casing issues --- .../DSC_CMReportingServicePoint.psm1 | 2 +- .../CMReportingServicePoint/CMReportingServicePoint_Present.ps1 | 2 +- tests/Unit/CMReportingServicePoint.tests.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 index 133a7e7..e662cad 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 @@ -48,7 +48,7 @@ function Get-TargetResource { 'DatabaseName' { $dbName = $rspProp.Value2 } 'DatabaseServerName' { $dbServerName = $rspProp.Value2 } - 'UserName' { $account = $rspProp.Value2 } + 'Username' { $account = $rspProp.Value2 } 'ReportServerInstance' { $rptInstance = $rspProp.Value2 } 'RootFolder' { $folder = $rspProp.Value2 } } diff --git a/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 index 6078093..b4b1afd 100644 --- a/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 +++ b/source/Examples/Resources/CMReportingServicePoint/CMReportingServicePoint_Present.ps1 @@ -12,7 +12,7 @@ Configuration Example { SiteCode = 'Lab' SiteServerName = 'CA01.contoso.com' - UserName = 'contoso\Admin' + Username = 'contoso\Admin' Ensure = 'Present' } } diff --git a/tests/Unit/CMReportingServicePoint.tests.ps1 b/tests/Unit/CMReportingServicePoint.tests.ps1 index 478a04e..a16fb88 100644 --- a/tests/Unit/CMReportingServicePoint.tests.ps1 +++ b/tests/Unit/CMReportingServicePoint.tests.ps1 @@ -54,7 +54,7 @@ try Value2 = 'CA01.contoso.com' } @{ - PropertyName = 'UserName' + PropertyName = 'Username' Value2 = 'contoso\SQLAdmin' } @{ From cd0fe56450b4610feacb28f215bddef9929bb124 Mon Sep 17 00:00:00 2001 From: Nicholas Ellis Date: Wed, 17 Jun 2020 12:42:30 -0400 Subject: [PATCH 7/7] Fixing indents and capitalization --- .../DSC_CMReportingServicePoint.psm1 | 2 +- .../en-US/DSC_CMReportingServicePoint.strings.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 index e662cad..66729a6 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/DSC_CMReportingServicePoint.psm1 @@ -164,7 +164,7 @@ function Set-TargetResource foreach ($param in $PSBoundParameters.GetEnumerator()) { - if ($evalList -contains $param.key) + if ($evalList -contains $param.key) { if ($param.Value -ne $state[$param.key]) { diff --git a/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 index 7661393..86f53ed 100644 --- a/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 +++ b/source/DSCResources/DSC_CMReportingServicePoint/en-US/DSC_CMReportingServicePoint.strings.psd1 @@ -1,6 +1,6 @@ ConvertFrom-StringData @' RetrieveSettingValue = Getting information for the specified Reporting Service Point. - RSPNotInstalled = Reporting Service Point is not installed on server: {0}. + RspNotInstalled = Reporting Service Point is not installed on server: {0}. RspAbsent = {0} Reporting Service Point expected absent returned Present. TestState = Test-TargetResource compliance check returned: {0}. SiteServerRole = {0} is not currently a site system server adding site system role.