Skip to content

Instantly share code, notes, and snippets.

@timyhac
Last active July 31, 2023 11:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timyhac/c1bc5906fdd12d6d2bab850e7164ee5b to your computer and use it in GitHub Desktop.
Save timyhac/c1bc5906fdd12d6d2bab850e7164ee5b to your computer and use it in GitHub Desktop.
Get the pipe name for a Local DB instance in powershell
Function GetLocalDBNamedPipe()
{
param( [string]$DB)
# This function can accept instance names in the format '(localdb)\Instance'
$DB = $DB.replace("(localdb)\", '')
# Ensure that it is running (assumes the DB already exists)
# Note: pipe names change each time the database starts
sqllocaldb start $DB | Out-Null
return ((sqllocaldb info $DB | Select-String -Pattern "Instance pipe name") -split " ")[3]
}
sqllocaldb create TheDatabase
$ThePipe = GetLocalDBNamedPipe -DB TheDatabase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment