Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement