我试图使用PowerShell和SMO在SQL服务器中创建一个空数据库,但似乎无法找到一种方法.这可能吗?
sql server的连接脚本:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$serverName = "localhost"
$server = new-object ('Microsoft.SqlServer.Management.Smo.Server') $serverName
$server.ConnectionContext.LoginSecure=$false;
$credential = Get-Credential
$loginName = $credential.UserName -replace("\\","")
$server.ConnectionContext.set_Login($loginName);
$server.ConnectionContext.set_SecurePassword($credential.Password)
$server.ConnectionContext.ApplicationName="SQLDeploymentScript"
Run Code Online (Sandbox Code Playgroud)