Get-sqmOrphanedFiles
Filesystem
sqmSQLTool v1.8.2+ · Diagnostics
sys.master_files. Searches directories from instance configuration (DefaultData/DefaultLog) and optional custom paths.
Returns summary (scanned count, registered count, orphaned count, total size) plus detailed orphaned file list with paths and last-modified dates. Useful for cleanup after database removals or migrations.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | Credentials for the connection. |
| -SearchPath | string[] | Optional | Default + registry paths | Custom directories to scan (e.g., UNC paths for remote instances). |
| -FileExtension | string[] | Optional | .mdf, .ldf, .ndf | File extensions to search for. |
| -Recurse | switch | Optional | $false | Recursively search subdirectories. |
| -EnableException | switch | Optional | $false | Re-throw exceptions instead of logging. |
Execution Flow
Examples
Scan default directories for orphaned files on local instance
Get-sqmOrphanedFiles -SqlInstance "SQL01"
Search custom paths with recursion on remote instance
Get-sqmOrphanedFiles -SqlInstance "SQL01" -SearchPath "D:\SQLData","E:\SQLLog" -Recurse