Created
March 21, 2017 08:35
-
-
Save jdstaerk/5a0a369a05d2612eb38e93d9bba67456 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Use host\instance,port in general(port is only needed if you connect via TCP; Not needed for localhost) | |
| $DataSource = "localhost\SQLEXPRESS" | |
| $Username = "MyUser" | |
| $Password = "MyPassword" | |
| # Create a new server object | |
| $Server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $DataSource | |
| # Use LoginSecure = $true if you are using the Windows Authentification --> Integrated_Security | |
| # If you do so, you don't need the ConnectionContext.Login or .Password | |
| $Server.ConnectionContext.LoginSecure = $false | |
| $Server.ConnectionContext.Login = $Username | |
| $Server.ConnectionContext.Password = $Password | |
| # Create a new database | |
| $NewServerObj = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Database -ArgumentList $Server , "MyDatabaseName" | |
| $NewServerObj.Create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment