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

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

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

# 3319_AdomdIterateOlapInfo.ps1
# Mark Tabladillo
# Last Updated: July 22, 2010
# Program Created: July 22, 2010

# [Microsoft.AnalysisServices.AdomdClient.AdomdConnection] 

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

# Send a simple MDX statement
$command = $con.CreateCommand()
$command.CommandText = "SELECT Measures.Members ON COLUMNS FROM [Warehouse and Sales]"
$cellset = $command.ExecuteCellSet()

# Iterate the data on the cubes used in the request
# In the current version Microsoft SQL Server Analysis Services, only one cube can be used in the request
foreach ($cubeInfo in $cellset.OlapInfo.CubeInfo.Cubes)
	write-host "CubeName = " $cubeInfo.CubeName
	write-host "Cube was last updated on " $cubeInfo.LastDataUpdate

# Iterate the metadata for the axes 
foreach ($axisInfo in $cellset.OlapInfo.AxesInfo.Axes)
	# For each axis, print the name of the axis
	write-host "AxisName = " $axisInfo.Name
	# Iterate the hierarchies on the current axis.
	foreach ($hierarchyInfo in $axisInfo.Hierarchies)
		write-host "HierarchyName = " $hierarchyInfo.Name
		foreach ($hierarchyPropertyInfo in $hierarchyInfo.HierarchyProperties)
			write-host "HierarchyProperty = " $hierarchyPropertyInfo.Name

# Iterate the cell properties that are  used in the request
foreach ($cellPropertyInfo in $cellset.OlapInfo.CellInfo.CellProperties)
	write-host "CellPropertyName = " $cellPropertyInfo.Name

# Close the connection