This script provides my PowerShell translation of C# code created by the authors of Microsoft SQL Server 2008 Analysis Services Unleashed.  I have tested this code on 64-bit Windows 7 running SQL Server 2008 R2 with Analysis Services, and the Windows PowerShell version 2 IDE (Integrated Development Environment).  This code requires the sample “Food Mart 2008” database available from the authors’ website at http://www.informit.com/store/product.aspx?isbn=0672330016

I shared this code as part of my data mining blog.  I have been reviewing this book, and I made comments on this code at http://www.marktab.net/datamining/2010/07/22/adomd-net-with-powershell-2-0-and-c-4-0/

Gorbach, I., Berger, A., & Melomed, E. (2009). Microsoft SQL Server 2008 Analysis Services Unleashed. Indianapolis, IN: Pearson Education Inc.

PowerShell
Edit|Remove
# 3305_AdomdDimensionOrdinal.ps1
# Mark Tabladillo
#
# Last Updated: July 22, 2010
# Program Created: July 22, 2010

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.AdomdClient")
[Microsoft.AnalysisServices.AdomdClient.AdomdConnection] 

# Connect to the server
$con = new-object Microsoft.AnalysisServices.AdomdClient.AdomdConnection
$con.ConnectionString = "Datasource=localhost; Initial Catalog=FoodMart 2008;"
$con.Open()

$cube  = $con.cubes["Warehouse and Sales"]

# Iterate over the dimensions collection
foreach ($dim in $cube.Dimensions) 
{
	write-host "Dimension: '" $dim.Name "' Ordinal= " $dim.Properties["DIMENSION_ORDINAL"].Value.ToString()
}
$con.Close()