< Back

Get-DbaFile

Mon Jan 13, 2020 11:05 am

NAME Get-DbaFile



SYNOPSIS

Get-DbaFile finds files in any directory specified on a remote SQL Server





SYNTAX

Get-DbaFile [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Path] <System.String[]>] [[-FileType] <System.String[]>] [[-Depth] <Int>] [-EnableException

<Switch>] [<CommonParameters>]





DESCRIPTION

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 ... 391-1.aspx





PARAMETERS

-Depth [<Int>]

Used to specify recursive folder depth. Default is 1, non-recursive.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileType [<System.String[]>]

Used to specify filter by filetype. No dot required, just pass the extension.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Path [<System.String[]>]

Used to specify extra directories to search in addition to the default data directory.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Allows you to login to servers using alternative credentials



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Discovery

Author: Brandon Abshire, netnerds.net



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



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

-------------------------- EXAMPLE 2 --------------------------



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'

-------------------------- EXAMPLE 3 --------------------------



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).

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-DbaFile -SqlInstance sql2014 -Path 'E:\\Dir1', 'E:\\Dir2'



Returns the files in "E:\\Dir1" and "E:Dir2" on sql2014

-------------------------- EXAMPLE 5 --------------------------



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.



RELATED LINKS

https://dbatools.io/Get-DbaFile