PowerShell for Creating a Database
This script explains creating a MS SQL Server database with default properties using PowerShell V3.0. In this script we are going to create a database called “PSDB”, by assuming that this database does not yet exist in current instance.
This is equivalent by creating database with following T-SQL Script.
CREATE DATABASE PSDB
Below is PowerShell V3.0 Script for same.
#Import SQL Server Module called SQLPS Import-Module SQLPS -DisableNameChecking #Your SQL Server Instance Name $Inst = "YourInstanceName" $Srvr = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $Inst #database PSDB with default settings #by assuming that this database does not yet exist in current instance $DBName = "PSDB" $db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database($Srvr, $DBName) $db.Create() #Confirm, list databases in your current instance $Srvr.Databases | Select Name, Status, Owner, CreateDate
Hope this helps.
Sandip
Categories: Powershell, SQL Server
powershell, powershell for, sql server
lovely stuff post!
This is going to be very useful for me thank you very much for posting
This blog is amazing. I realy like it
Hey There. I discovered your weblog the use of msn.
This is an extremely neatly written article. I will make sure to bookmark it and come
back to read more of your helpful information. Thanks for the post.
I’ll certainly return.
Wonderful blog! Do you have any suggestions for aspioring writers?
I’m planning to start my owwn webssite soon buut I’m a little lost on everything.
Would you propose starting with a free platform like WordPress or go for
a paid option? There are so many options out there that I’m totally confused ..
Any tips? Kudos!
I was recommended this website by mmeans of my cousin.
I am noww not sure whether this publish is written by him as no one else know such special about my problem.
You are amazing! Thank you!