dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Get-DbaFile

This command searches all specified directories, allowing a DBA to see file information on a server without direct access.

You can filter by extension using the -FileType parameter. By default, the default data directory will be returned. You can provide and additional paths to search using the -Path parameter.

Thanks to serg-52 for the query: SqlServerCentral

Screenshots

dbatools-Get-DbaFile

Examples

Logs into the SQL Server “sqlserver2014a” using Windows credentials and searches E:\Dir for all files.

Get-DbaFile -SqlInstance sqlserver2014a -Path E:\Dir1

Logs into the SQL Server “sqlserver2014a” using alternative credentials and returns all files in ‘E:\sql files’.

Get-DbaFile -SqlInstance sqlserver2014a -SqlCredential $cred -Path ‘E:\sql files’

Returns the files in the default data, log and backup directories on sql2014, 3 directories deep (recursively).

$all = Get-DbaDefaultPath -SqlInstance sql2014
Get-DbaFile -SqlInstance sql2014 -Path $all.Data, $all.Log, $all.Backup -Depth 3

Returns the files in “E:\Dir1” and “E:Dir2” on sql2014.

Get-DbaFile -SqlInstance sql2014 -Path ‘E:\Dir1’, ‘E:\Dir2’

Finds files in E:\Dir1 ending with “.fsf” and “.mld” for both the servers sql2014 and sql2016.

Get-DbaFile -SqlInstance -Path ‘E:\Dir1’ sql2014, sql2016 -FileType fsf, mld

Author

This command was created by Brandon Abshire. You can find Brandon on his blog.

Get-Help

From PowerShell, execute Get-Help Get-DbaFile -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaFile.ps1 on GitHub
 

Related commands