Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # Use host\instance,port in general(port is only needed if you connect via TCP; Not needed for localhost)
  2. $DataSource = "localhost\SQLEXPRESS"
  3. $Username = "MyUser"
  4. $Password = "MyPassword"
  5. # Create a new server object
  6. $Server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $DataSource
  7. # Use LoginSecure = $true if you are using the Windows Authentification --> Integrated_Security
  8. # If you do so, you don't need the ConnectionContext.Login or .Password
  9. $Server.ConnectionContext.LoginSecure = $false
  10. $Server.ConnectionContext.Login = $Username
  11. $Server.ConnectionContext.Password = $Password
  12. # Create a new database
  13. $NewServerObj = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Database -ArgumentList $Server , "MyDatabaseName"
  14. $NewServerObj.Create()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement