public/Get-SsasProcessingMessages.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-SsasProcessingMessages {
<#
    .SYNOPSIS
    Examines the XML returned by the Invoke-AsCmd function to find errors. Writes error message if errors are found.
 
    .DESCRIPTION
    Examines the XML returned by the Invoke-AsCmd function to find errors. Writes error message if errors are found.
 
    .PARAMETER ASCmdReturnString
    The XML returned by the Invoke-AsCmd function.
 
    .OUTPUTS
    No return parameters. Writes to error stream only if an error is detected.
 
    .EXAMPLE
    Get-SsasProcessingMessages -ASCmdReturnString $xmlMessages;
 
    Analyses the messages within the $xmlMessages for errors.
 
    .LINK
    https://github.com/DrJohnT/DeployCube
 
.NOTES
    Written by (c) Dr. John Tunnicliffe, 2019 https://github.com/DrJohnT/DeployCube
    This PowerShell script is released under the MIT license http://www.opensource.org/licenses/MIT
#>

    [CmdletBinding()]
    param
    (
        [String] [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        $ASCmdReturnString
    )

    $returnXml = New-Object -TypeName System.Xml.XmlDocument;
    $returnXml.LoadXml($ASCmdReturnString);

    [System.Xml.XmlNamespaceManager] $nsmgr = $returnXml.NameTable;
    $nsmgr.AddNamespace('xmlAnalysis',     'urn:schemas-microsoft-com:xml-analysis');
    $nsmgr.AddNamespace('rootNS',         'urn:schemas-microsoft-com:xml-analysis:empty');
    $nsmgr.AddNamespace('exceptionNS',  'urn:schemas-microsoft-com:xml-analysis:exception');

    $rows = $returnXML.SelectNodes("//xmlAnalysis:return/rootNS:root/exceptionNS:Messages/exceptionNS:Error", $nsmgr) ;
    foreach ($row in $rows) {
        throw $row.Description;
    }
}