Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Converted to class-based resource [Issue #151](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/151).
- WebAccessServer is now NOT a required parameter, mirroring the use
of the underlying cmdlet.
- `RDConnectionBrokerHAMode`
- Converted to class-based resource [Issue #144](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the required issue-link label format in changelog entries.

Please use lowercase issue in the link label to match the repository changelog rule.

Proposed fix
-  - Converted to class-based resource [Issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
+  - Converted to class-based resource [issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).

As per coding guidelines, "Reference issues using format issue #<issue_number>".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Converted to class-based resource [Issue #144](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
- Converted to class-based resource [issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` at line 15, Update the changelog entry "Converted to
class-based resource [Issue
`#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144)" to
use the required lowercase issue-link label by replacing "[Issue `#144`]" with
"[issue `#144`]" so it matches the repository changelog rule and the required
format referenced in the guidelines.


### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Resolve-Dependency.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AllowPrerelease = $false
WithYAML = $true

UseModuleFast = $true
# UseModuleFast = $true
#ModuleFastVersion = '0.1.2'
#ModuleFastBleedingEdge = $true

Expand Down
159 changes: 159 additions & 0 deletions source/Classes/020.RDConnectionBrokerHAMode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<#
.SYNOPSIS
The `RDConnectionBrokerHAMode` DSC resource is used to configure the Remote Desktop Connection Broker HA.

.DESCRIPTION
This resource is used to configure the Remote Desktop Connection Broker HA.

## Requirements

- Target machine must be running Windows Server 2012 or later.

## Known issues

All issues are not listed here, see [all open issues](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+RDConnectionBrokerHAMode).

.PARAMETER ClientAccessName
Specifies the Client Access Name for the RD Connection Broker HA deployment.

.PARAMETER DatabaseConnectionString
Specifies the primary database connection string for the RD Connection Broker HA deployment.

.PARAMETER DatabaseSecondaryConnectionString
Specifies the secondary database connection string for the RD Connection Broker HA deployment.

.PARAMETER DatabaseFilePath
Specifies the file path for the RD Connection Broker HA database.

.PARAMETER ConnectionBroker
Specifies the FQDN of a server to host the RD Connection Broker role service.

.PARAMETER ActiveManagementServer
Returns the FQDN of the server that is currently active for management tasks.

.PARAMETER Reasons
Returns the reason a property is not in desired state.
#>

[DscResource()]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In PowerShell DSC class resources, what is the default behavior when [DscResource()]omitsRunAsCredential, and how does RunAsCredential = 'Optional' affect PsDscRunAsCredential support?

💡 Result:

In PowerShell class-based DSC resources, the [DscResource()] attribute's RunAsCredential property defines how the resource interacts with the automatic PsDscRunAsCredential property [1]. Default Behavior When RunAsCredential is omitted from the [DscResource()] attribute, the default behavior is Optional [1]. This means that a user may optionally use the PsDscRunAsCredential property with the DSC resource [1]. This default behavior is functionally equivalent to explicitly setting RunAsCredential = 'Optional' or RunAsCredential = 'Default' [1]. Effect of 'Optional' Setting RunAsCredential = 'Optional' explicitly enables support for the PsDscRunAsCredential property [1]. When this is set (or defaulted), the DSC engine allows the user to provide a PSCredential object via the PsDscRunAsCredential parameter in the configuration [2][1]. If provided, the DSC engine attempts to execute the resource's methods under the context of the specified user account [2]. Important Context While these settings are defined in the [DscResource()] attribute, they are primarily relevant for DSC v1.1 and earlier [1]. In DSC v2.0 and later, the RunAsCredential property in the [DscResource()] attribute has no functional effect on the execution of the resource [1]. Additionally, the PsDscRunAsCredential property itself is only supported in DSC v1.1 and earlier [1].

Citations:


🏁 Script executed:

# Check the file and examine line 38
if [ -f "source/Classes/020.RDConnectionBrokerHAMode.ps1" ]; then
    echo "=== File exists ==="
    sed -n '35,42p' source/Classes/020.RDConnectionBrokerHAMode.ps1
else
    echo "File not found"
fi

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 284


🏁 Script executed:

# Search for all DSC resources and their attribute declarations
echo "=== All DSC resources in Classes directory ==="
find source/Classes -name "*.ps1" -type f -exec grep -l "class.*ResourceBase" {} \;

echo ""
echo "=== Their DscResource attributes ==="
find source/Classes -name "*.ps1" -type f -exec grep -B2 "class.*ResourceBase" {} + | grep -E "\[DscResource|class"

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 558


Add RunAsCredential to the DSC resource attribute.

The coding guidelines require explicit declaration as [DscResource(RunAsCredential = 'Optional')] for class-based resources.

Proposed fix
-[DscResource()]
+[DscResource(RunAsCredential = 'Optional')]
 class RDConnectionBrokerHAMode : ResourceBase
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[DscResource()]
[DscResource(RunAsCredential = 'Optional')]
class RDConnectionBrokerHAMode : ResourceBase
🧰 Tools
🪛 PSScriptAnalyzer (1.25.0)

[info] 38-159: No examples found for resource 'RDConnectionBrokerHAMode'

(PSDSCDscExamplesPresent)


[info] 38-159: No tests found for resource 'RDConnectionBrokerHAMode'

(PSDSCDscTestsPresent)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/Classes/020.RDConnectionBrokerHAMode.ps1` at line 38, The DSC resource
attribute on the class is missing an explicit RunAsCredential setting; update
the class attribute `[DscResource()]` to include `RunAsCredential = 'Optional'`
so it becomes `[DscResource(RunAsCredential = 'Optional')]`, ensuring the
class-based resource explicitly declares RunAsCredential as required by
guidelines.

class RDConnectionBrokerHAMode : ResourceBase
{
[DscProperty(Key)]
[ValidateLength(1, 256)]
[System.String]
$ClientAccessName

[DscProperty()]
[System.String]
$ConnectionBroker

[DscProperty(Mandatory)]
[System.String]
$DatabaseConnectionString

[DscProperty()]
[System.String]
$DatabaseSecondaryConnectionString

[DscProperty()]
[System.String]
$DatabaseFilePath

[DscProperty(NotConfigurable)]
[System.String]
$ActiveManagementServer

[DscProperty(NotConfigurable)]
[RDSReason[]]
$Reasons

RDConnectionBrokerHAMode () : base ($PSScriptRoot)
{
$this.ExcludeDscProperties = @(
'ConnectionBroker'
'DatabaseSecondaryConnectionString'
'DatabaseFilePath'
)
}

[RDConnectionBrokerHAMode] Get()
{
# Call the base method to return the properties.
return ([ResourceBase] $this).Get()
}

[void] Set()
{
# Call the base method to enforce the properties.
([ResourceBase] $this).Set()
}

[System.Boolean] Test()
{
# Call the base method to test all of the properties that should be enforced.
return ([ResourceBase] $this).Test()
}

# Base method Get() call this method to get the current state as a Hashtable.
hidden [System.Collections.Hashtable] GetCurrentState([System.Collections.Hashtable] $properties)
{
$getParameters = @{
ConnectionBroker = $this.ConnectionBroker
ErrorAction = 'SilentlyContinue'
}

if ([string]::IsNullOrWhiteSpace($this.ConnectionBroker))
{
$getParameters.ConnectionBroker = (Get-ComputerName -FullyQualifiedDomainName)
}

$currentStateResult = Get-RDConnectionBrokerHighAvailability @getParameters

return @{
DatabaseConnectionString = $currentStateResult.DatabaseConnectionString
DatabaseSecondaryConnectionString = $currentStateResult.DatabaseSecondaryConnectionString
DatabaseFilePath = $currentStateResult.DatabaseFilePath
ActiveManagementServer = $currentStateResult.ActiveManagementServer
}
}

<#
Base method Set() call this method with the properties that should be
enforced and that are not in desired state.
#>
hidden [void] Modify([System.Collections.Hashtable] $properties)
{
# If the ActiveManagementServer property is not empty, then the configuration is currently active and cannot be modified.
if (-not [string]::IsNullOrEmpty($this.ActiveManagementServer))
{
New-InvalidOperationException -Message $this.localizedData.RDConnectionBrokerHAMode_ConfigurationCannotBeModified
}

$setParameters = @{
ClientAccessName = $this.ClientAccessName
ConnectionBroker = $this.ConnectionBroker
}

if ([string]::IsNullOrWhiteSpace($this.ConnectionBroker))
{
$setParameters.ConnectionBroker = (Get-ComputerName -FullyQualifiedDomainName)
}

Set-RDConnectionBrokerHighAvailability @setParameters @properties
}

<#
Base method Assert() call this method with the properties that was assigned
a value.
#>
hidden [void] AssertProperties([System.Collections.Hashtable] $properties)
{
if (-not (Test-RemoteDesktopServicesDscOsRequirement))
{
New-InvalidOperationException -Message $this.localizedData.RDConnectionBrokerHAMode_OSRequirementNotMet
}

# Module Import in verbose mode outputs lots of data, so redirecting to null.
Import-RemoteDesktopModule 4>&1 > $null
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In PowerShell, how is 4>&1 > $null evaluated, and what is the correct redirection syntax to suppress only stream 4 (verbose)?

💡 Result:

In PowerShell, the syntax 4>&1 > $null is evaluated as a two-step redirection process [1][2]. First, 4>&1 redirects the Verbose stream (stream 4) into the Success stream (stream 1) [1][2]. Second, the > $null operator redirects the resulting Success stream (which now contains the original Success output plus the redirected Verbose output) to the $null automatic variable, effectively discarding both [1][2]. To suppress only the Verbose stream (stream 4) without affecting the Success stream, you should redirect stream 4 directly to $null [1][2]. The correct syntax is: 4> $null This directs only the Verbose output to the $null device, leaving the Success stream (stream 1) to be displayed in the console or handled by other redirections as intended [1][2].

Citations:


🏁 Script executed:

cat -n source/Classes/020.RDConnectionBrokerHAMode.ps1 | sed -n '150,165p'

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 499


Fix stream redirection order in AssertProperties.

Line 157 uses 4>&1 > $null, which redirects both the Verbose stream (4) and Success stream (1) to $null. To suppress only the Verbose output as intended, use 4> $null.

Proposed fix
-        Import-RemoteDesktopModule 4>&1 > $null
+        Import-RemoteDesktopModule 4> $null
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Import-RemoteDesktopModule 4>&1 > $null
Import-RemoteDesktopModule 4> $null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/Classes/020.RDConnectionBrokerHAMode.ps1` at line 157, In the
AssertProperties function change the stream redirection on the
Import-RemoteDesktopModule call so only the Verbose stream is suppressed;
replace the incorrect "4>&1 > $null" redirection with "4> $null" (i.e., update
the Import-RemoteDesktopModule invocation inside AssertProperties to use 4>
$null instead of 4>&1 > $null).

}
}

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions source/DSCResources/DSC_RDConnectionBrokerHAMode/README.md

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions source/RemoteDesktopServicesDsc.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '4.0'

# Aliases to export from this module
AliasesToExport = @()

# Functions to export from this module
FunctionsToExport = @()

Expand Down
6 changes: 6 additions & 0 deletions source/en-US/RDConnectionBrokerHAMode.strings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Localized resources for RDConnectionBrokerHAMode

ConvertFrom-StringData @'
RDConnectionBrokerHAMode_OSRequirementNotMet = The minimum OS requirement was not met. (RDSHA0001)
RDConnectionBrokerHAMode_ConfigurationCannotBeModified = The configuration of the Connection Broker High Availability mode cannot be modified once configured. (RDSHA0002)
'@
Loading
Loading