Skip to content

Instantly share code, notes, and snippets.

@dgosbell
Last active September 22, 2015 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgosbell/83c4806ef5baaad2fc87 to your computer and use it in GitHub Desktop.
Save dgosbell/83c4806ef5baaad2fc87 to your computer and use it in GitHub Desktop.
$serverName="localhost"
$databaseName = "AdventureWorks"
$cubeName = "Model"
$outputFolder = "d:\data"
# load the AMO into the current runspace
[System.Reflection.Assembly]::LoadwithpartialName("Microsoft.AnalysisServices") > $null
# connect to the server
$svr = new-Object Microsoft.analysisservices.Server
$svr.Connect($serverName)
$db = $svr.Databases.GetByName($databaseName)
$cube = $db.Cubes.GetByName($cubeName)
$dateStamp = [DateTime]::Now.ToString("yyyyMMdd_HHmm")
$mdxScript = $cube.MDXScripts[0]
"Scripting $($db.name)"
# write out MDXScript XMLA
$xw = new-object System.Xml.XmlTextWriter("$($outputFolder)\MDXScript_$($db.Name)_$($dateStamp).xmla", [System.Text.Encoding]::UTF8)
$xw.Formatting = [System.Xml.Formatting]::Indented
[Microsoft.AnalysisServices.Scripter]::WriteAlter($xw, $mdxScript,$true,$true)
# clean up
$xw.Close()
$svr.Disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment