Skip to content
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

Get-DbaCmObject - Improved CIM ErrorHandling #9107

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

FriedrichWeinmann
Copy link
Member

  • Centralized error resolution (Pure code cleanup & deduplication)
  • Added CIM/DCOM error handling for bad namespaces/class names

Please read -- recent changes to our repo

On November 10, 2022, we removed some bloat from our repository (for the second and final time). This change requires that all contributors reclone or refork their repo.

PRs from repos that have not been recently reforked or recloned will be closed and @potatoqualitee will cherry-pick your commits and open a new PR with your changes.

  • Please confirm you have the smaller repo (85MB .git directory vs 275MB or 110MB or 185MB .git directory)

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (affects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Purpose

When using CIM/DCOM (which automatically happens when executing against localhost), errors for bad namespace or class name - e.g. searching for SQL Service details on a machine that does not have the namespace - would incorrectly flag the machine as not reachable, due to .NET not correctly classifying the error record.

Approach

  • Centralized the error resolution to simplify the code
  • Added manual HResult error mapping as a fallback

Commands to test

The only modified command is Get-DbaCmObject.
To reproduce the error fixed, run the following two lines on the current gallery version.

Get-DbaCmObject -Query 'SELECT * FROM Win32_Servize' -ComputerName $env:COMPUTERNAME
Get-DbaCmObject -Query 'SELECT * FROM Win32_Service' -ComputerName $env:COMPUTERNAME

Executing the same again in this fixed version will work just fine :)

+ Centralized error resolution
+ Added CIM/DCOM error handling for bad namespaces/class names
@potatoqualitee
Copy link
Member

heeyyyyy, good to see you! thank you for the PR 🙇🏼

@FriedrichWeinmann
Copy link
Member Author

FriedrichWeinmann commented Oct 4, 2023

Aaaaand here's the second part on the library side, to expand into supporting Invoke-CimMethod, not just reading:

dataplat/dbatools.library#5

Just a quick reminder: I need the new library version to be released and deployed in order to apply the update to all the commands using Invoke-CimMethod - otherwise I'm just breaking all the tests :)

@potatoqualitee
Copy link
Member

Thank you @FriedrichWeinmann ! It will take me a moment to find my scritps to rebuild the library. Things changed drastically. I'll return to this asap.

@potatoqualitee potatoqualitee merged commit f6d99c0 into development Jan 24, 2024
12 checks passed
@potatoqualitee potatoqualitee deleted the fred-Get-DbaCmObject branch January 24, 2024 19:13
@potatoqualitee
Copy link
Member

thank you 🙇🏼

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.

2 participants