Go Back   CORTEX Forums > Local Happenings > CORTEX Blogs > Random Procrastination
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

SSAS: Automating the Scripting of an SSAS database

This is a discussion on SSAS: Automating the Scripting of an SSAS database within the Random Procrastination forums, part of the CORTEX Blogs category; I've been meaning to post this for a little while, and a recent post on the SSAS forum at ssas-info.com prompted me to finally get around to it. Basically the ...


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 22nd February 2010, 10:53 AM   #1
Senior Member
 
Join Date: Jun 2009
Posts: 63
Darren Gosbell is on a distinguished road
Thumbs up SSAS: Automating the Scripting of an SSAS database

I've been meaning to post this for a little while, and a recent post on the SSAS forum at ssas-info.com prompted me to finally get around to it.

Basically the small Powershell script below will attach to the specified SSAS server and script all of the databases out to an XMLA file. In this example I also add a timestamp in the form of YYYYMMDD to the end of the file.

*

$serverName = "localhost\sql08"
$outputFolder = "C:\data\"

## load the AMO and XML assemblies into the current runspace
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices" ) > $null
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml") > $null

$dateStamp = (get-Date).ToString("yyyyMMdd")


## connect to the server
$svr = new-Object Microsoft.AnalysisServices.Server
$svr.Connect($serverName)
foreach ($db in $svr.Databases)
{
*** write-Host "Scripting: " $db.Name
*** $xw = new-object System.Xml.XmlTextWriter("$($outputFolder)DBScript _$($db.Name)_$($dateStamp).xmla", [System.Text.Encoding]::UTF8)
*** $xw.Formatting = [System.Xml.Formatting]::Indented
*** [Microsoft.AnalysisServices.Scripter]::WriteCreate($xw,$svr,$db,$true,$true)
*** $xw.Close()
}
$svr.Disconnect()


*

This is mainly useful if there are potentially changes made to your live database that are not reflected in your project. Normally I would advise that people make changes to their database projects and re-deploy, but not everyone does that. And there are some things (like roles or partitioning) that may be dynamically generated outside of your project.

I have not put any error checking or anything like that in this script, I basically wanted to show how the Scripter object can be used from Powershell (or C# with a few minor syntax changes), but simply changing the server name and output folder should be enough to get you started. I think that the account that runs this script should only need the "read definition" rights on the database.

This script should work with SSAS 2005 or above. With SQL 2008 or higher, you could setup a SQL Agent job with a Powershell job step which executes this script on a regular basis. With 2005 you would have to use a command line step and shell out to Powershell.






Get More from the original blog...
Darren Gosbell is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.tbig.com.au/forums/random-procrastination/8310-ssas-automating-scripting-ssas-database.html
Posted By For Type Date
SSAS: Automating the Scripting of an SSAS database - PowerShell.com This thread Refback 4th March 2010 08:16 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
SSAS: Listing Attribute Relationships Darren Gosbell Random Procrastination 0 23rd June 2009 07:30 PM
SSAS: Are my Aggregations processed? Darren Gosbell Random Procrastination 0 23rd June 2009 07:30 PM
SSAS: There is no such thing as an Attribute in MDX! Darren Gosbell Random Procrastination 0 23rd June 2009 07:30 PM
SSAS: Executing Arbitrary SQL queries Darren Gosbell Random Procrastination 0 23rd June 2009 07:30 PM
SSAS: T-SQL Equivalent for a Many-to-Many relationship Darren Gosbell Random Procrastination 0 23rd June 2009 07:30 PM


All times are GMT +11. The time now is 04:01 PM.

© The Business Intelligence Group

Search Engine Optimization by vBSEO