Created
August 14, 2020 05:41
-
-
Save dgosbell/591ca0a62ec4ea6ed8f6cdd885ec1e7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### | |
### Script : AMO_GetTraceEventCategories.ps1 | |
### Author : Darren Gosbell (https://darren.gosbell.com) | |
### Date : 14 August 2020 | |
### Description: Outputs a list of the Trace Event Category and Subcategories for Analysis Services | |
### | |
$server = "Localhost\tab17" | |
$null = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.adomdclient") | |
[Microsoft.AnalysisServices.adomdclient.adomdconnection]$adomd = new-object Microsoft.AnalysisServices.adomdclient.adomdconnection("data source=$server;") | |
$adomd.Open() | |
$ds = $adomd.GetSchemaDataSet("DISCOVER_TRACE_EVENT_CATEGORIES",$null) | |
## There is a row in the dataset for each event category | |
$result = foreach ($row in $ds.Tables.item(0).rows ) | |
{ | |
$xml = [xml]$row["Data"] | |
## each 'event' is an event class | |
foreach($class in $xml.EVENTCATEGORY.EVENTLIST.ChildNodes) | |
{ | |
$foundSubClass = $false | |
foreach($subclassEvent in $class.EVENTCOLUMNLIST.ChildNodes) | |
{ | |
## not every event class has subclasses so we need to check if ID=1 exists | |
if ($subclassEvent.ID -eq 1) { | |
$foundSubClass = $true | |
foreach( $subclass in $subclassEvent.EVENTCOLUMNSUBCLASSLIST.ChildNodes) | |
{ | |
## output a custom object per subclass | |
[PSCustomObject]@{ | |
Category = $class.ParentNode.ParentNode.NAME | |
ClassID = $class.ID | |
ClassName = $class.NAME | |
SubClassID = $subclass.ID | |
SubClassName = $subclass.NAME | |
} | |
} | |
} | |
} | |
if ($foundSubClass -eq $false) | |
{ | |
## output a custom object for an event class which does not have any subclasses | |
[PSCustomObject]@{ | |
Category = $class.ParentNode.ParentNode.NAME | |
ClassID = $class.ID | |
ClassName = $class.NAME | |
SubClassID = "" | |
SubClassName = "" | |
} | |
} | |
} | |
} | |
## This command outputs the results to the console | |
## but you could easily redirect to a file or write code to insert | |
## this array of objects into a custom table | |
$result | ft | |
$adomd.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment