Skip to content

Set-DbaNetworkCertificate: Refactor with best practices and Test-DbaNetworkCertificate validation#10227

Closed
andreasjordan wants to merge 1 commit intodevelopmentfrom
claude/issue-10125-20260311-0707
Closed

Set-DbaNetworkCertificate: Refactor with best practices and Test-DbaNetworkCertificate validation#10227
andreasjordan wants to merge 1 commit intodevelopmentfrom
claude/issue-10125-20260311-0707

Conversation

@andreasjordan
Copy link
Collaborator

Refactors Set-DbaNetworkCertificate to use Test-DbaNetworkCertificate for certificate validation and applies all best practices identified in the code review.

Changes:

  • Use Test-DbaNetworkCertificate to validate certificate suitability before setting
  • Add -SkipCertificateValidation switch to bypass validation when needed
  • Add [ValidatePattern] to enforce 40-char hex thumbprint format
  • Fix PSEdition check for PS v3 compatibility
  • Remove redundant ParameterSets; use Test-Bound pattern
  • Wrap ACL operations in try/catch with proper error handling
  • Fix registry read with -ErrorAction SilentlyContinue
  • Search only in LocalMachine\My
  • Add explicit continue after Stop-Function in foreach loop

Closes #10125

Generated with Claude Code

…etworkCertificate validation

- Use Test-DbaNetworkCertificate to validate certificate suitability before setting
- Add -SkipCertificateValidation switch to bypass validation when needed
- Add [ValidatePattern] to enforce 40-char hex thumbprint format
- Fix PSEdition check: use PSVersionTable.PSVersion.Major for PS v3 compatibility
- Remove redundant ParameterSets; use Test-Bound pattern instead
- Fix variable casing: KeyFullPath consistency in else branch
- Wrap ACL operations in try/catch with proper error handling
- Fix registry read: add -ErrorAction SilentlyContinue for first-time setup
- Search only in LocalMachine\My (not all cert stores)
- Add HasPrivateKey check in script block
- Add explicit continue after Stop-Function -Continue in foreach loop
- Update test file with SkipCertificateValidation parameter

(do Set-DbaNetworkCertificate)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Collaborator Author

I'm not happy with major parts of this pr, so I will close and work on a new pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactoring Set-DbaNetworkCertificate

1 participant