commands

^

Get-DbaDbFile

Author Stuart Moore (@napalmgram), stuart-moore.com
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Get-DbaDbFile on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaDbFile.

Synopsis

Returns detailed information about database files.

Description

Returns detailed information about database files. Does not use SMO - SMO causes enumeration and this command avoids that.

Syntax

Get-DbaDbFile
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-FileGroup] <Object[]>]
    [[-InputObject] <Database[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaDbFile -SqlInstance sql2016

Will return an object containing all file groups and their contained files for every database on the sql2016 SQL Server instance

Example: 2
PS C:\> Get-DbaDbFile -SqlInstance sql2016 -Database Impromptu

Will return an object containing all file groups and their contained files for the Impromptu Database on the sql2016 SQL Server instance

Example: 3
PS C:\> Get-DbaDbFile -SqlInstance sql2016 -Database Impromptu, Trading

Will return an object containing all file groups and their contained files for the Impromptu and Trading databases on the sql2016 SQL Server instance

Example: 4
PS C:\> Get-DbaDatabase -SqlInstance sql2016 -Database Impromptu, Trading | Get-DbaDbFile

Will accept piped input from Get-DbaDatabase and return an object containing all file groups and their contained files for the Impromptu and Trading databases on the sql2016 SQL Server instance

Example: 5
PS C:\> Get-DbaDbFile -SqlInstance sql2016 -Database AdventureWorks2017 -FileGroup Index

Return any files that are in the Index filegroup of the AdventureWorks2017 database.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances

Alias
Required False
Pipeline true (ByValue)
Default Value
-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.

Alias
Required False
Pipeline false
Default Value
-Database

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

The database(s) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-FileGroup

Filter results to only files within this certain filegroup.

Alias
Required False
Pipeline false
Default Value
-InputObject

A piped collection of database objects

Alias
Required False
Pipeline true (ByValue)
Default Value
-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.

Alias
Required False
Pipeline false
Default Value False