{"id":45,"date":"2008-03-26T21:32:59","date_gmt":"2008-03-27T02:32:59","guid":{"rendered":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/45_analysis-services-2005-and-2008-with-powershell-it-works"},"modified":"2008-03-26T21:40:50","modified_gmt":"2008-03-27T02:40:50","slug":"analysis-services-2005-and-2008-with-powershell-it-works","status":"publish","type":"post","link":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/45_analysis-services-2005-and-2008-with-powershell-it-works","title":{"rendered":"Analysis Services 2005 and 2008 with PowerShell &#8211; it works"},"content":{"rendered":"<p>A few weeks ago I asked a <a target=\"_blank\" href=\"http:\/\/forums.microsoft.com\/MSDN\/ShowPost.aspx?PostID=3020443&amp;SiteID=1\">question on Analysis Services 2008 forum<\/a>\u00a0if there will be PowerShell support for SSAS 2008. I got an answer from Microsoft, that no native support is planned. I know that Darren Gosbell released <a target=\"_blank\" href=\"http:\/\/www.codeplex.com\/powerSSAS\">PowerShell Provider for SSAS 2005<\/a>, but for\u00a0the different reasons I cannot use it with all clients. But just this week Carl Rabeler (Microsoft)\u00a0<a target=\"_blank\" href=\"http:\/\/www.ssas-info.com\/analysis-services-news\/13-news\/757-new-ms-released-new-set-of-analysis-services-20052008-samples\">posted a\u00a0new updated set of Analysis Services 2005\/2008 Samples<\/a>. One folder in these samples contained 4 PowerShell script examples that shows how to use it with Analysis Services. I tested these samples and they worked on a standard SSAS 2008 installation. Today\u00a0Carl Rabeler\u00a0actually updated these samples &#8211; fixed some minor issues and added one more sample &#8211; to get a size of Analysis Services database.<\/p>\n<p><!--more--><\/p>\n<p>So I grabbed that latest Carl&#8217;s example and added a few lines of code to iterate through cubes, measure groups, partitions and dimensions and print a simple list of names and sizes. I tested this code on my virtual SSAS 2008 machine and this worked without any problems. I got very excited\u00a0&#8211; so we do have some PowerShell support with SSAS 2008.<\/p>\n<p>Just to see an error message, I run the same code on SSAS 2005 machine (without additional providers installed) and to my surprise it worked as well. So we do have PowerShell support for Analysis Services 2005 and 2008.\u00a0From\u00a0PowerSSAS documentation I can see that\u00a0that provider allows you to navigate Analysis Services database like drive. Standard provider behaves differently, but it does let you to do quite a lot. In my previous posts I showed examples on how to use Windows Scripting Host (WSH) to write scripts for Analysis Services. But I know that WSH has many limitations. For example, Analysis Services supports different set of parameters passed to the same method. I had problems that WSH\u00a0was expecting just one set of parameters for each method (I believe). I do not know yet what are limitations are with PowerShell, but I hope that somebody who worked with PowerShell a lot (Darren Gosbell, maybe you?) will blog about this. If no, I&#8217;ll investigate and post here later myself.<\/p>\n<p>The good news is that Analysis Services 2005 and 2008 supports PowerShell. So it is definitely an option for your scripting needs.<\/p>\n<p>You might wonder why I am so excited about PowerShell? Some of our clients do not give us access to their production environment. So if you need to send client a small fix, it is much easier to script that fix and send it like file, instead of sending\u00a0a list of steps that describes what to do. Changes could be very simple &#8211; like add new translation to a specific attribute, or hide\/show a measure in the perspective or\u00a0cube.<\/p>\n<p>Anyway,\u00a0 here is my code that I tested on SSAS 2005 and 2008 versions:<\/p>\n<blockquote><p>## Add the AMO namespace<br \/>\n$loadInfo = [Reflection.Assembly]::LoadWithPartialName(&#8220;Microsoft.AnalysisServices&#8221;)<\/p>\n<p>## Connect and get the edition of the local server<br \/>\n$connection = &#8220;localhost&#8221;<br \/>\n$server = New-Object Microsoft.AnalysisServices.Server<br \/>\n$server.connect($connection)<\/p>\n<p>foreach ($d in $server.Databases )<br \/>\n{<br \/>\n\u00a0Write-Output ( &#8220;`nDatabase: {0} Size: {1}`n&#8221; -f $d.Name, $d.EstimatedSize )<\/p>\n<p>\u00a0foreach ($cube in $d.Cubes) {<br \/>\n\u00a0 Write-Output ( &#8220;Cube: {0}&#8221; -f $Cube.Name )<br \/>\n\u00a0 foreach ($mg in $cube.MeasureGroups) {<br \/>\n\u00a0\u00a0 Write-Output ( &#8221; Measure Group: {0} Size: {1}&#8221; -f $mg.Name, $mg.EstimatedSize )<br \/>\n\u00a0\u00a0 foreach ($part in $mg.Partitions) {<br \/>\n\u00a0\u00a0\u00a0 Write-Output ( &#8221;\u00a0 Partition: {0} Size: {1}&#8221; -f $part.Name, $part.EstimatedSize )<br \/>\n\u00a0\u00a0 } # Partition<br \/>\n\u00a0 } # Measure group<br \/>\n\u00a0<br \/>\n\u00a0 foreach ($dim in $d.Dimensions) {<br \/>\n\u00a0\u00a0 Write-Output ( &#8220;Dimension: {0}&#8221; -f $dim.Name)<br \/>\n\u00a0 } # Dimensions<\/p>\n<p>\u00a0} # Cube<\/p>\n<p>} # Databases<\/p><\/blockquote>\n<p>Note: My blogging software replaces double quotes with different symbol, so if you&#8217;ll grab this code, then be sure to fix double quotes.\u00a0<\/p>\n<p>And here are results &#8211; this printout is from SSAS 2008 server with just Adventure Works DW database installed. SSAS 2005 results are very similar:<\/p>\n<blockquote><p>PS C:\\Utilities\\Scripts&gt; .\\dbinfo.ps1<br \/>\nDatabase: Adventure Works DW Size: 34535913<br \/>\nCube: Adventure Works<br \/>\n\u00a0Measure Group: Internet Sales Size: 2390949<br \/>\n\u00a0 Partition: Internet_Sales_2001 Size: 29642<br \/>\n\u00a0 Partition: Internet_Sales_2002 Size: 78911<br \/>\n\u00a0 Partition: Internet_Sales_2003 Size: 993042<br \/>\n\u00a0 Partition: Internet_Sales_2004 Size: 1153218<br \/>\n\u00a0Measure Group: Internet Orders Size: 1816480<br \/>\n\u00a0 Partition: Internet_Orders_2001 Size: 32637<br \/>\n\u00a0 Partition: Internet_Orders_2002 Size: 86898<br \/>\n\u00a0 Partition: Internet_Orders_2003 Size: 765137<br \/>\n\u00a0 Partition: Internet_Orders_2004 Size: 894744<br \/>\n\u00a0Measure Group: Internet Customers Size: 1223972<br \/>\n\u00a0 Partition: Customers_2001 Size: 10307<br \/>\n\u00a0 Partition: Customers_2002 Size: 27960<br \/>\n\u00a0 Partition: Customers_2003 Size: 538016<br \/>\n\u00a0 Partition: Customers_2004 Size: 610657<br \/>\n\u00a0Measure Group: Sales Reasons Size: 3215<br \/>\n\u00a0 Partition: Internet_Sales_Reasons Size: 1034<br \/>\n\u00a0Measure Group: Reseller Sales Size: 3308697<br \/>\n\u00a0 Partition: Reseller_Sales_2001 Size: 304565<br \/>\n\u00a0 Partition: Reseller_Sales_2002 Size: 801746<br \/>\n\u00a0 Partition: Reseller_Sales_2003 Size: 1223908<br \/>\n\u00a0 Partition: Reseller_Sales_2004 Size: 673284<br \/>\n\u00a0Measure Group: Reseller Orders Size: 1295396<br \/>\n\u00a0 Partition: Reseller_Orders_2001 Size: 140197<br \/>\n\u00a0 Partition: Reseller_Orders_2002 Size: 330174<br \/>\n\u00a0 Partition: Reseller_Orders_2003 Size: 480043<br \/>\n\u00a0 Partition: Reseller_Orders_2004 Size: 275198<br \/>\n\u00a0Measure Group: Sales Summary Size: 2987696<br \/>\n\u00a0 Partition: Total_Sales_2001 Size: 80094<br \/>\n\u00a0 Partition: Total_Sales_2002 Size: 441643<br \/>\n\u00a0 Partition: Total_Sales_2003 Size: 1144905<br \/>\n\u00a0 Partition: Total_Sales_2004 Size: 1118404<br \/>\n\u00a0Measure Group: Sales Orders Size: 2153776<br \/>\n\u00a0 Partition: Total_Orders_2001 Size: 133590<br \/>\n\u00a0 Partition: Total_Orders_2002 Size: 332047<br \/>\n\u00a0 Partition: Total_Orders_2003 Size: 831851<br \/>\n\u00a0 Partition: Total_Orders_2004 Size: 801419<br \/>\n\u00a0Measure Group: Sales Targets Size: 3656<br \/>\n\u00a0 Partition: Sales_Quotas Size: 1514<br \/>\n\u00a0Measure Group: Financial Reporting Size: 404464<br \/>\n\u00a0 Partition: Finance Size: 373520<br \/>\n\u00a0Measure Group: Exchange Rates Size: 293811<br \/>\n\u00a0 Partition: Currency_Rates Size: 289223<br \/>\nDimension: Promotion<br \/>\nDimension: Product<br \/>\nDimension: Customer<br \/>\nDimension: Geography<br \/>\nDimension: Reseller<br \/>\nDimension: Sales Territory<br \/>\nDimension: Employee<br \/>\nDimension: Scenario<br \/>\nDimension: Department<br \/>\nDimension: Organization<br \/>\nDimension: Account<br \/>\nDimension: Date<br \/>\nDimension: Source Currency<br \/>\nDimension: Sales Reason<br \/>\nDimension: Reseller Sales Order Details<br \/>\nDimension: Internet Sales Order Details<br \/>\nDimension: Sales Channel<br \/>\nDimension: Destination Currency<br \/>\nDimension: Sales Summary Order Details<br \/>\nPS C:\\Utilities\\Scripts&gt;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I asked a question on Analysis Services 2008 forum\u00a0if there will be PowerShell support for SSAS 2008. I got an answer from Microsoft, that no native support is planned. I know that Darren Gosbell released PowerShell Provider for SSAS 2005, but for\u00a0the different reasons I cannot use it with all clients. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts\/45"}],"collection":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":0,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ssas-info.com\/VidasMatelisBlog\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}