Last active
July 2, 2024 19:05
-
-
Save develohpanda/255292ffa58a0924b20662442c365e24 to your computer and use it in GitHub Desktop.
Drop SQL database from Powershell
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
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() | |
} | |
} |
Thanks for this!
Thanks!
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
Awesome, thanks!