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

PowerShell: How To Set IP and Domain Restrictions to Specific IIS Sites

# Enable IP Filtering Feature in IIS using PowerShell Install-WindowsFeature Web-IP-Security Restart-Service W3SVC # Optional:…

PowerShell: Use EMCOPY to Mirror a Directory

# Purpose: this PowerShell snippet is to demonstrate the use of Emcopy$source="C:\Users\tester\Desktop\Clients"$destination="C:\Users\tester\Desktop\Test"#$switches="/o /secforce /s /de…

Expanding System Volume C Drive of Windows Hyper-V Virtual Machine

There are three three steps to expand a disk of a virtual machine: Connect to…