Skip to content

Instantly share code, notes, and snippets.

@piers7
Created November 12, 2015 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piers7/d8f4a75232e5983f7f5b to your computer and use it in GitHub Desktop.
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
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