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

CentOS: Java & Tomcat Installation

Install Java 1.6.0_20:   The following instructions assume that there is no root access to…

Basic HTML and HTML5: Uncomment HTML

<!--<h1>Hello World</h1><h2>CatPhotoApp</h2><p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase…

PowerShell: Windows System Discovery – Deprecated

<# windows-localhost-discovery-v0.11.ps1 Purpose: scan the local or remote Windows machine for general system resources, security…