Skip to content

Instantly share code, notes, and snippets.

@timyhac
Last active June 21, 2016 06:07
Show Gist options
  • Save timyhac/1093198648aaf565d8e0e5a3e74bba77 to your computer and use it in GitHub Desktop.
Save timyhac/1093198648aaf565d8e0e5a3e74bba77 to your computer and use it in GitHub Desktop.
Get SQL Server Backup Folder powershell
Import-Module sqlps
Function GetMSSQLBackupFolder
{
param([string]$ServerInstance)
# taken from https://www.mssqltips.com/sqlservertip/1966/function-to-return-default-sql-server-backup-folder/
$GetBackupFolder = "EXEC master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory'"
return (Invoke-sqlcmd -ServerInstance $ServerInstance -Query $GetBackupFolder).Data
}
GetMSSQLBackupFolder -ServerInstance "localhost\SQLEXPRESS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment