-
Notifications
You must be signed in to change notification settings - Fork 47
Convert RDConnectionBrokerHAMode to class-based
#155
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
base: main
Are you sure you want to change the base?
Changes from all commits
dde0254
4809771
be6a03c
0500a96
707b889
65cbcce
8393541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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()] | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In PowerShell class-based DSC resources, the 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"
fiRepository: 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 The coding guidelines require explicit declaration as Proposed fix-[DscResource()]
+[DscResource(RunAsCredential = 'Optional')]
class RDConnectionBrokerHAMode : ResourceBase📝 Committable suggestion
Suggested change
🧰 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 |
||||||||
| 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 | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 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 Line 157 uses Proposed fix- Import-RemoteDesktopModule 4>&1 > $null
+ Import-RemoteDesktopModule 4> $null📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| } | ||||||||
| } | ||||||||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| 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) | ||
| '@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the required issue-link label format in changelog entries.
Please use lowercase
issuein the link label to match the repository changelog rule.Proposed fix
As per coding guidelines, "Reference issues using format issue #<issue_number>".
📝 Committable suggestion
🤖 Prompt for AI Agents