Last active
September 22, 2015 00:17
-
-
Save dgosbell/83c4806ef5baaad2fc87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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