---
title: "Find-DbaView"
description: "Searches database views for specific text patterns or regular expressions in their definitions."
url: "https://dbatools.io/Find-DbaView/"
availability: "Windows, Linux, macOS"
tags: ["View", "Lookup"]
author: "Claudio Silva  (@ClaudioESSilva)"
source: "https://github.com/dataplat/dbatools/blob/master/public/Find-DbaView.ps1"
last_updated: "2024-01-01"
---

# Find-DbaView

## Synopsis

Searches database views for specific text patterns or regular expressions in their definitions.

## Description

Scans view definitions across one or more databases to locate specific text patterns, table references, or code constructs. This helps DBAs identify views that reference particular tables before schema changes, find views containing sensitive data patterns like email addresses or SSNs, or locate views with specific business logic during troubleshooting. The function searches the actual view definition text (TextBody) and returns the matching views along with line numbers showing exactly where the pattern was found, making it easy to understand the context of each match.

## Syntax

```powershell
Find-DbaView
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [-Pattern] <String>
    [-IncludeSystemObjects]
    [-IncludeSystemDatabases]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Searches all user databases views for &quot;whatever&quot; in the text body

```powershell
PS C:\> Find-DbaView -SqlInstance DEV01 -Pattern whatever
```

### Example 2: Searches all databases for all views that contain a valid email pattern in the text body

```powershell
PS C:\> Find-DbaView -SqlInstance sql2016 -Pattern '\w+@\w+\.\w+'
```

### Example 3: Searches in &quot;mydb&quot; database views for &quot;some string&quot; in the text body

```powershell
PS C:\> Find-DbaView -SqlInstance DEV01 -Database MyDB -Pattern 'some string' -Verbose
```

### Example 4: Searches in &quot;mydb&quot; database views for &quot;runtime&quot; in the text body

```powershell
PS C:\> Find-DbaView -SqlInstance sql2016 -Database MyDB -Pattern RUNTIME -IncludeSystemObjects
```

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

##### -Pattern

Specifies the text pattern or regular expression to search for within view definitions. Supports full regex syntax for complex pattern matching.  
Use this to find views referencing specific tables before schema changes, locate sensitive data patterns like email addresses or SSNs, or identify views containing particular business logic.  
Common patterns include table names, column references, function calls, or data validation expressions.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| Default Value |  |

### Optional Parameters

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Database

Specifies which databases to search for views containing the pattern. Accepts wildcards and multiple database names.  
Use this when you need to limit the search scope to specific databases instead of scanning all databases on the instance.  
Particularly useful for large instances where you only need to check certain application databases.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -ExcludeDatabase

Specifies databases to skip during the view search operation. Accepts multiple database names.  
Use this to exclude large databases that you know don't contain relevant views, speeding up the search process.  
Common exclusions include development copies, archive databases, or third-party application databases.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -IncludeSystemObjects

Includes system views in the search operation alongside user-created views. System views are excluded by default.  
Use this when troubleshooting issues that might involve system view dependencies or when documenting complete database schemas.  
Warning: Including system views significantly slows down the search, especially when scanning multiple databases or large instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -IncludeSystemDatabases

Includes system databases (master, model, msdb, tempdb) in the view search operation. System databases are excluded by default.  
Use this when investigating SQL Server internals, troubleshooting replication issues, or documenting complete instance configurations.  
Most DBA tasks focus on user databases, so this parameter is typically used for advanced troubleshooting scenarios.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

## Outputs

**PSCustomObject**

Returns one object per view matching the specified pattern. Each object represents a single matching view with the matching text lines highlighted.

**Default display properties (via Select-DefaultView):**

- ComputerName: The name of the server where the view is located
- SqlInstance: The SQL Server instance name
- Database: The database name containing the view
- DatabaseId: The internal database ID
- Schema: The schema of the view
- Name: The name of the view
- Owner: The owner of the view
- IsSystemObject: Boolean indicating if this is a system view (affected by -IncludeSystemObjects parameter)
- CreateDate: DateTime when the view was created
- LastModified: DateTime when the view was last modified
- ViewTextFound: String containing the matching lines with line numbers in format "(LineNumber: N) matched text"

**Additional properties available (via Select-Object *):**

- View: The SMO View object itself
- ViewFullText: The complete text body of the view definition

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
