Author | Brandon Abshire, netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaFile on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaFile.
Get-DbaFile finds files in any directory specified on a remote SQL Server
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: https://www.sqlservercentral.com/Forums/Topic1642213-391-1.aspx
Get-DbaFile
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Path] <String[]>]
[[-FileType] <String[]>]
[[-Depth] <Int32>]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-DbaFile -SqlInstance sqlserver2014a -Path E:\Dir1
Logs into the SQL Server "sqlserver2014a" using Windows credentials and searches E:\Dir for all files
PS C:\> Get-DbaFile -SqlInstance sqlserver2014a -SqlCredential $cred -Path 'E:\sql files'
Logs into the SQL Server "sqlserver2014a" using alternative credentials and returns all files in 'E:\sql files'
PS C:\> $all = Get-DbaDefaultPath -SqlInstance sql2014
PS C:\> Get-DbaFile -SqlInstance sql2014 -Path $all.Data, $all.Log, $all.Backup -Depth 3
Returns the files in the default data, log and backup directories on sql2014, 3 directories deep (recursively).
PS C:\> Get-DbaFile -SqlInstance sql2014 -Path 'E:\Dir1', 'E:\Dir2'
Returns the files in "E:\Dir1" and "E:Dir2" on sql2014
PS C:\> Get-DbaFile -SqlInstance sql2014, sql2016 -Path 'E:\Dir1' -FileType fsf, mld
Finds files in E:\Dir1 ending with ".fsf" and ".mld" for both the servers sql2014 and sql2016.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Allows you to login to servers using alternative credentials
Alias | |
Required | False |
Pipeline | false |
Default Value |
Used to specify extra directories to search in addition to the default data directory.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Used to specify filter by filetype. No dot required, just pass the extension.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Used to specify recursive folder depth. Default is 1, non-recursive.
Alias | |
Required | False |
Pipeline | false |
Default Value | 1 |
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 |