Created
November 12, 2015 02:47
-
-
Save piers7/d8f4a75232e5983f7f5b to your computer and use it in GitHub Desktop.
Uses SMO to determine the path that new databases will be created in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enter file contents hereparam( | |
[Parameter(Mandatory=$true)] [string]$sqlServer | |
) | |
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") > $null | |
$smoServer = new-object Microsoft.SqlServer.Management.Smo.Server $sqlServer | |
$str = $smoServer.DefaultFile # or .DefaultLog for tlog files | |
if ($str) | |
{ | |
# if DefaultFile property is present, an explicit default has been configured | |
$str; | |
}else{ | |
# if DefaultFile property is empty, it means default path has not been changed | |
# and should be taken from where the MasterDB sits | |
$smoServer.MasterDBPath; # or .MasterDBLogPath for tlog | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment