Skip to content

Instantly share code, notes, and snippets.

@develohpanda
Last active May 24, 2022 15:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save develohpanda/255292ffa58a0924b20662442c365e24 to your computer and use it in GitHub Desktop.
Save develohpanda/255292ffa58a0924b20662442c365e24 to your computer and use it in GitHub Desktop.
Drop SQL database from Powershell
function Delete-SqlDatabase($serverName, $databaseName) {
Import-Module SQLPS
$server = New-Object Microsoft.SqlServer.Management.Smo.Server($serverName)
$db = $server.databases[$databaseName]
if ($db) {
$server.KillAllprocesses($databaseName)
$db.Drop()
}
}
@gwInsurtech24
Copy link

Awesome, thanks!

@FrancoisCamus
Copy link

Thanks for this!

@mikhail-cabilao
Copy link

Thanks!

@rajeshsys
Copy link

Hi,
This worked perfectly for the first time and then it gave all sorts of error for Import-Module SQLPS/SQLServer. any one faced similar issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment