Skip to content

Find-DbaObject - Add unified command to search database objects by name#10321

Merged
potatoqualitee merged 4 commits intodevelopmentfrom
claude/issue-9245-20260405-0932
Apr 9, 2026
Merged

Find-DbaObject - Add unified command to search database objects by name#10321
potatoqualitee merged 4 commits intodevelopmentfrom
claude/issue-9245-20260405-0932

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Closes #9245

Adds Find-DbaObject, a unified command to search all database object types by name pattern, with optional column name searching.

What does this PR do?

  • Searches object names across tables, views, stored procedures, functions, synonyms, and triggers
  • Optionally searches column names with -IncludeColumns
  • Filter by object type with -ObjectType
  • Uses T-SQL against sys.objects and sys.columns for performance
  • Full regex support for pattern matching

Generated with Claude Code

github-actions bot and others added 2 commits April 5, 2026 09:44
Adds Find-DbaObject which searches all database object types (tables, views,
stored procedures, functions, synonyms, triggers) by name pattern, with optional
column name searching. Uses T-SQL against sys.objects and sys.columns for performance.

(do Find-DbaObject)

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

@claude one test is still failing:

Failed tests summary:
Path           : Find-DbaObject/System databases/Should include system databases when IncludeSystemDatabases is specified
Name           : It Should include system databases when IncludeSystemDatabases is specified
Result         : Failed
Message        : ErrorRecord: Expected a value, but got $null or empty.
StackTrace     : 
RawErrorRecord : Expected a value, but got $null or empty.
Uploading artifact DetailedTestFailures_Pester5.json (933 bytes)...100%

@claude
Copy link
Copy Markdown

claude bot commented Apr 6, 2026

Claude finished @andreasjordan's task in 1m 1s —— View job


Fixed failing test

  • Gather context
  • Read test file and function to identify the issue
  • Fix the failing test
  • Commit and push

Root cause: The test searched for syslogins (a system view in the master database) with IncludeSystemDatabases = $true, but the T-SQL query always filters AND o.is_ms_shipped = 0 unless IncludeSystemObjects is also set. Since syslogins has is_ms_shipped = 1, it was being excluded.

Fix: Added IncludeSystemObjects = $true to the test splat in tests/Find-DbaObject.Tests.ps1:229 so the test correctly finds the syslogins system view when searching system databases.
|

syslogins is a system view (is_ms_shipped=1) so IncludeSystemObjects
is required to find it alongside IncludeSystemDatabases.

(do Find-DbaObject)

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

@claude the test is still failing.

@claude
Copy link
Copy Markdown

claude bot commented Apr 9, 2026

Claude finished @andreasjordan's task in 4m 41s —— View job


Fixed failing test

  • Gather context
  • Read test file and implementation to identify the issue
  • Fix the failing test
  • Commit and push

Root cause: The test tried to find syslogins (a Microsoft-shipped system view with is_ms_shipped = 1) to verify IncludeSystemDatabases works. This is unreliable — system objects vary across SQL Server versions and configurations.

Fix: Rewrote the "System databases" context to follow the established dbatools pattern used by Find-DbaView and Find-DbaStoredProcedure tests:

  1. BeforeAll: Create a user-created table (t_dbatoolsci_systemdb_<random>) in master
  2. It: Search for it with IncludeSystemDatabases = $true — verifies both that system databases are searched AND that the correct database name appears in results
  3. AfterAll: Drop the table from master

No IncludeSystemObjects needed since the test table is user-created (not is_ms_shipped).
| Branch

… in master

Replace unreliable search for system-shipped syslogins view with the
established dbatools pattern: create a user object in master, then verify
IncludeSystemDatabases finds it. Matches Find-DbaView and Find-DbaStoredProcedure
test patterns.

(do Find-DbaObject)

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

Ok, tests pass now.

@andreasjordan andreasjordan marked this pull request as ready for review April 9, 2026 07:24
@potatoqualitee potatoqualitee merged commit db77a34 into development Apr 9, 2026
14 checks passed
@potatoqualitee potatoqualitee deleted the claude/issue-9245-20260405-0932 branch April 9, 2026 21:59
@potatoqualitee
Copy link
Copy Markdown
Member

Woohoo! Thank you 🙇🏼

potatoqualitee added a commit that referenced this pull request Apr 10, 2026
…10321)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Find-DbaObject

2 participants