Posted On June 15, 2020

PowerShell: Obtaining SQL Database Default Paths

kimconnect 0 comments
blog.KimConnect.com >> Codes , Database >> PowerShell: Obtaining SQL Database Default Paths
# This function returns an array of 3 string values reflecting default Data, Log, and Backup directories as set on a certain SQL server
function getDefaultSqlPaths($sqlServer=$env:computername){
    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    $sqlConnection = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlServer 
    $defaultBackupDirectory=$sqlConnection.Settings.BackupDirectory
    $defaultDataDirectory=$sqlConnection.Settings.DefaultFile
    $defaultLogDirectory=$sqlConnection.Settings.DefaultLog
    return @($defaultDataDirectory,$defaultLogDirectory,$defaultBackupDirectory)
    }
getDefaultSqlPaths

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

SQL: Exists Condition

The EXISTS condition is considered "to be met" if the subquery returns at least one…

PowerShell: Get ‘Size on Disk’ of Files in Windows

There are many methods of attempting to obtain "size on disk" values of files in…

Windows 2012: How To Install DotNet Framework 2.0 & 3.0

If there're HTTPS/TLS issues, run this function: https://blog.kimconnect.com/powershell-enable-tls-1-2-on-legacy-servers/ Toggle WSUS registry key to off prior…