<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Database Administration', 'SQL Server 2008', and 'SMO'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Database+Administration,SQL+Server+2008,SMO&amp;orTags=0</link><description>Search results matching tags 'Database Administration', 'SQL Server 2008', and 'SMO'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Change SQL Servers Authentication Mode with PowerShell</title><link>http://sqlblog.com/blogs/allen_white/archive/2011/05/19/change-sql-servers-authentication-mode-with-powershell.aspx</link><pubDate>Thu, 19 May 2011 20:22:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35748</guid><dc:creator>AllenMWhite</dc:creator><description>&lt;p&gt;Lately I've been working on scripts to check and set security and configuration settings for SQL Server using PowerShell.  One of the settings that I normally set and forget at install time is the Authentication Mode setting.  Best practices suggest that you set this to Windows Authentication, but my experience has been that it's always better to set it to Mixed mode, and set a very strong password for the sa account.&lt;/p&gt;
&lt;p&gt;So, what if we want to change it after the fact? Well, it's a registry setting. Management Studio allows you to make that change via the Security page in Server Properties, but I prefer scripting when setting configuration settings.  The setting is exposed in SMO (Server Management Objects), however, and we can check the setting using PowerShell.  (I'm going to assume you're either running SQLPS.exe or you've already loaded the SMO libraries.  If you don't know what I'm talking about, check &lt;a href="http://sqlblog.com/blogs/allen_white/archive/2008/01/09/create-agent-jobs-to-run-powershell-scripts.aspx"&gt;here&lt;/a&gt;.)&lt;/p&gt;
&lt;pre&gt;# Connect to the instance using SMO&lt;br&gt;$s = new-object ('Microsoft.SqlServer.Management.Smo.Server') 'MyServer\MyInstance'&lt;br&gt;[string]$nm = $s.Name&lt;br&gt;[string]$mode = $s.Settings.LoginMode&lt;br&gt;&lt;br&gt;write-output "Instance Name: $nm"&lt;br&gt;write-output "Login Mode: $mode"&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;What the script returns is the instance name, and the authentication mode it's using.  The property in SMO is called LoginMode, and can have one of four values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Integrated - Windows Authentication&lt;/li&gt;
&lt;li&gt;Mixed - Mixed Mode&lt;/li&gt;
&lt;li&gt;Normal - SQL Server Only Authentication&lt;/li&gt;
&lt;li&gt;Unknown - Undefined (and no, I haven't tried it.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I sometimes encounter a system that was set to Integrated, and I want to change it to Mixed mode, because I like to have that safety net of sa if something goes wrong.  Here's how I do that:&lt;/p&gt;
&lt;pre&gt;#Change to Mixed Mode&lt;br&gt;$s.Settings.LoginMode = [Microsoft.SqlServer.Management.SMO.ServerLoginMode]::Mixed&lt;br&gt;&lt;br&gt;# Make the changes&lt;br&gt;$srv.Alter()&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;Once that's done the server does need to be restarted, and I need to go in and set the sa password to something VERY strong right away.  But now the server is set to the authentication mode I prefer, and it's a lot easier (in my mind) than going into the registry to do it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Allen&lt;/p&gt;</description></item><item><title>Discover Facets and Properties in PowerShell</title><link>http://sqlblog.com/blogs/allen_white/archive/2010/09/27/discover-facets-and-properties-in-powershell.aspx</link><pubDate>Mon, 27 Sep 2010 14:56:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:29002</guid><dc:creator>AllenMWhite</dc:creator><description>&lt;p&gt;When you're trying to set up scripts to deploy policies to your servers (because you ALWAYS automate with PowerShell, right?), it can be sometimes difficult to determine exactly what facets are there, and when you do know the facet name, what properties are available to you.&lt;/p&gt;
&lt;p&gt;First, in a native PowerShell window you'll need to load the assemblies with the Policy-Based Management objects.  Because PBM was originally called Dynamic Management Framework, the DLL carries the original name, so the following two lines will load the correct assemblies:&lt;/p&gt;
&lt;pre&gt;[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Dmf')
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SQLServer.Management.Sdk.Sfc')
&lt;/pre&gt;
&lt;p&gt;The next thing to do is to connect to our SQL Server instance, and load the instance's PolicyStore object, which is where the existing policies are kept.&lt;/p&gt;
&lt;pre&gt;$conn = New-Object Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection("server=SQLTBWS\INST01;Trusted_Connection=true");
$PolicyStore = New-Object Microsoft.SqlServer.Management.DMF.PolicyStore($conn);
&lt;/pre&gt;
&lt;p&gt;Now we can start exploring.  We can pull the list of facets by referencing them within the PolicyStore object, and then store them in a variable called $facets.  We can then pipe that variable into a select-object cmdlet and get the name and description of the available facets:&lt;/p&gt;
&lt;pre&gt;$facets = [Microsoft.SqlServer.Management.Dmf.PolicyStore]::Facets
$facets | select Name, Description
&lt;/pre&gt;
&lt;p&gt;Now we know what facets are available.  Let's say we want to set up some database maintenance policies.  We can figure out what properties are available to us by creating a facet object variable for the 'IDatabaseMaintenanceFacet' facet.  Then we grab the properties list from it by setting a variable to the facet's FacetProperties object.  Finally we can pipe the property list through the select-object cmdlet to see the name and property type of each property for the facet:&lt;/p&gt;
&lt;pre&gt;$f = $facets['IDatabaseMaintenanceFacet']
$fp = $f.FacetProperties
$fp | select Name, PropertyType
&lt;/pre&gt;
&lt;p&gt;Once we have this information we can use it to build conditions, and from those conditions, the policies we want to establish on our servers.&lt;/p&gt;
&lt;p&gt;Allen&lt;/p&gt;</description></item><item><title>PASS PowerShell/SQL Server PreCon</title><link>http://sqlblog.com/blogs/allen_white/archive/2010/08/19/pass-powershell-sql-server-precon.aspx</link><pubDate>Thu, 19 Aug 2010 19:17:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28067</guid><dc:creator>AllenMWhite</dc:creator><description>&lt;p&gt;PowerShell is an amazing tool to help you automate your administrative processes.  There are a lot of books and online sources to help you learn PowerShell, but how do you learn how to use it with SQL Server?  Simple, just sign up for my PASS PreCon session.  Here's the outline:&lt;/p&gt;
&lt;p&gt;&lt;a&gt;Use PowerShell to Get the Most out of SQL Server&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Module 1: Introduction to PowerShell&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Cmdlets&lt;/li&gt;
	&lt;li&gt;Aliases&lt;/li&gt;
	&lt;li&gt;The Pipeline&lt;/li&gt;
	&lt;li&gt;Variables&lt;/li&gt;
	&lt;li&gt;Objects&lt;/li&gt;
	&lt;li&gt;Control Flow&lt;/li&gt;
	&lt;li&gt;Functions&lt;/li&gt;
	&lt;li&gt;Modules&lt;/li&gt;
	&lt;li&gt;Error Handling&lt;/li&gt;
	&lt;li&gt;Command-line Arguments&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 2: Introduction to SMO&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Introduction to the SMO Library&lt;/li&gt;
	&lt;li&gt;SQLPS.exe - The SQL Server Mini-Shell&lt;/li&gt;
	&lt;li&gt;The SMO Object Model&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 3: Backup and Recovery&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Backup&lt;/li&gt;
	&lt;li&gt;Restore&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 4: Automating &amp;amp; Maintaining Databases&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Automating Index Maintenance&lt;/li&gt;
	&lt;li&gt;Automating DBCC&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 5: Importing, Exporting and Transforming Data&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;ADO.NET&lt;/li&gt;
	&lt;li&gt;Invoke-SQLCMD&lt;/li&gt;
	&lt;li&gt;Importing and Exporting using CSV Files&lt;/li&gt;
	&lt;li&gt;Importing and Exporting using XML Files&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 6: Manipulating Database Objects&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Creating and Deleting Schemas&lt;/li&gt;
	&lt;li&gt;Creating, Modifying and Deleting Tables&lt;/li&gt;
	&lt;li&gt;Creating, Modifying and Deleting Triggers&lt;/li&gt;
	&lt;li&gt;Creating, Modifying and Deleting Indexes&lt;/li&gt;
	&lt;li&gt;Creating, Modifying and Deleting Views&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 7: Managing the Enterprise&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Registering Servers&lt;/li&gt;
	&lt;li&gt;Creating a Central Management Server&lt;/li&gt;
	&lt;li&gt;Connecting to a Central Management Server&lt;/li&gt;
	&lt;li&gt;Running Scripts Against Multiple Servers&lt;/li&gt;
	&lt;li&gt;Defining Policies for Policy-Based Management&lt;/li&gt;
	&lt;li&gt;Evaluating Policies for Policy-Based Management&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 8: Profiling and Monitoring SQL Server&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Gathering WMI Information&lt;/li&gt;
	&lt;li&gt;Gathering Performance Counters&lt;/li&gt;
	&lt;li&gt;Setting up a Server Side Trace&lt;/li&gt;
	&lt;li&gt;Monitor Log Growth&lt;/li&gt;
	&lt;/ul&gt;
&lt;li&gt;Module 9: Configuring and Tuning SQL Server&lt;/li&gt;
	&lt;ul&gt;
	&lt;li&gt;Setting Configuration Options&lt;/li&gt;
	&lt;li&gt;Setting Windows Mode or Mixed Mode&lt;/li&gt;
	&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;As you can see, we're going to spend the first part of the day learning the basics of PowerShell, but the focus is on how you can manage your own environment using this powerful language, so you can spend your time solving problems instead of the constant point-and-click drudgery of typical DBA tasks.&lt;/p&gt;
&lt;p&gt;The all-day session is reasonably priced, and you'll come away with scripts to help you put this tool into use right away.  Check out the session details at &lt;a href="http://sqlpass.eventpoint.com/topic/details/DBA232P" title="SQLPass.org" target="_blank"&gt;Use PowerShell to Get the Most out of SQL Server&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;See you there!&lt;/p&gt;
&lt;p&gt;Allen&lt;/p&gt;</description></item></channel></rss>