PowerShell for Altering Database Properties
This article will help to understand how to alter databases properties using PowerShell V3.0 and SMO. In previous article we seen PowerShell for Creating a Database. Basically we can alter database options from Automatic, Containment, Cursor, File Stream, Miscellaneous, Recovery, Service Broker and State Categories.
Following PowerShell Script will help you to understand what I’m talking about.
#import SQL Server module Import-Module SQLPS -DisableNameChecking #your SQL Server Instance Name $SQLInstanceName = "SQL2012" $Server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $SQLInstanceName #provide your database name where you want to change database properties $DatabaseName = "PSDB" #create SMO handle to your database $DBObject = $Server.Databases[$DatabaseName] #Database Options to change ANSI PADDING, NULLS and Warnings $DBObject.DatabaseOptions.AnsiPaddingEnabled = $false $DBObject.DatabaseOptions.AnsiNullsEnabled = $false $DBObject.DatabaseOptions.AnsiWarningsEnabled = $false #Database Options to change Database User Access #DatabaseUserAccess enum :: single, multiple, restricted $DBObject.DatabaseOptions.UserAccess = [Microsoft.SqlServer.Management.Smo.DatabaseUserAccess]:: Restricted $DBObject.Alter() #In some cases you cannot use DatabaseOptions #where you can update your SMO handle directly $DBObject.CompatibilityLevel = [Microsoft.SqlServer.Management.Smo.CompatibilityLevel]::Version90 $DBObject.AutoUpdateStatisticsEnabled =$true $DBObject.Alter() #Set your database ReadOnly with DatabaseOptions $DBObject.DatabaseOptions.ReadOnly = $true $DBObject.Alter()
Following screen show is talking about the Updated Database Options during the execution of above PowerShell Script. You can browse this screen by selecting database properties and Options tab where you can notice updated Database Options during PowerShell Execution.
Hope this Helps
Sandip
Categories: Powershell, SQL Server
powershell, powershell for, sql server
This is going to be very useful for me thank you very much for posting
Your blog is very interesting. You write about very interesting things. Thanks for all your tips and information.
It’s an amazing piece of writing designed for all the online viewers; they will get advantage from it I am sure.
Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis.
It will always be useful to read through articles from other writers
and practice a little something from other web sites.
does beer cause cellulite
Can I just say what a relief to find a person that actually understands what
they are talking about on the net. You certainly realize how to bring
a problem to light and make it important. A lot more people should read this and understand this side of your story.
I was surprised you aren’t more popular because you certainly possess the gift.astrologer ithaca ny
Thanks on your marvelous posting! I quite enjoyed reading it, you can be a great author.
I will ensure that I bookmark your blog and
definitely will come back in the future. I want to encourage that you continue your great writing,
have a nice holiday weekend!motorbike vin check
Your style is unique compared to other people I’ve read stuff from. Thank you for posting when you’ve got the opportunity, Guess I’ll just book mark this blog.premature ventricular contractions tumblr
I am sure this paragraph has touched all the internet visitors, its really really
fastidious post on building up new web site.
Hello! I’m at work surfing around your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the outstanding work!become taller free
Amazing! Its truly amazing paragraph, I have got much clear idea regarding from this article.
I was recommended this web site by my cousin.
I am not sure whether this post is written by him as nobody else know such detailed about my difficulty.
You are wonderful! Thanks!
Does your website have a contact page? I’m having a tough time locating it but, I’d like
to send you an e-mail. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.
thanks for you interest. you can send emails to bi-bigdata@outlook.com or sandip.shinde@hotmail.com
Very nice article, totally what I was looking for.
There’s definately a lot to find out about this issue. I like all the points you have made.
If some one desires to be updated with newest technologies then he
must be pay a visit this web page and be up to date every day.
My brother suggested I may like this web site. He was totally
right. This submit actually made my day. You can not imagine just how a lot time I had spent for this information!
Thank you!
Excellent goods from you, man. I’ve understand your stuff previous to and you are just extremely fantastic. I really like what you’ve acquired here, certainly like what you are saying and
the way in which you say it. You make it enjoyable and you still take care of to keep it wise.
I cant wait to read much more from you. This is really a tremendous web site.
Howdy! This is my first visit to your blog!
We are a team of volunteers and starting a new initiative in a community in the
same niche. Your blog provided us valuable information to work
on. You have done a marvellous job!
What’s up, I check your blog regularly. Your story-telling style is awesome, keep up the good work!
Hi! This is kind of off topic but I need some help from
an established blog. Is it very difficult to set up your own blog?
I’m not very techincal but I can figure things out pretty fast. I’m thinking about making
my own but I’m not sure where to begin. Do you have any points or suggestions? Cheers
Have you ever thought about creating an ebook or guest authoring on
other websites? I have a blog based on the same information you
discuss and would love to have you share some stories/information.
I know my audience would appreciate your work. If you’re even remotely interested, feel free to shoot me an e mail
Hello, Neat post. There is a problem together with your web site
in web explorer, could check this? IE nonetheless is the marketplace
leader and a large component of other folks will leave out your wonderful writing because of this problem.
Hello, I enjoy reading through your article post.
I like to write a little comment to support you.
Very good info. Lucky me I discovered your blog by accident (stumbleupon).
I have book-marked it for later!
I have learn some excellent stuff here. Certainly price bookmarking
for revisiting. I surprise how so much attempt
you put to make such a magnificent informative web
site.
I don’t even know how I ended up here, but I thought this post was great. I don’t know who you are but
certainly you’re going to a famous blogger if you are not already 😉 Cheers!
Keep this going please, great job! std symptoms the next day
My partner and I stumbled over here by a different page
and thought I might check things out. I like what I see so now i am following
you. Look forward to looking at your web page yet again.