Asked by:
How to select only the "description" from output?

Question
-
I run the following command to process a database/and its partitions.
Invoke-ASCmd –InputFile $file -Server $Server >$output
from the output, if there is an error, this is whats displayed:
<return xmlns="urn:schemas-microsoft-com:xml-analysis"><root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"><Excep tion xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /><Messages xmlns="urn:schemas-microsoft-com:xml-analysis: exception"><Error ErrorCode="-1055653884" Description="Either the dimension with the ID of '0f585685' does not exist in the database with the ID of '', or the u ser does not have permissions to access the object." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /> </Messages></root></return>
can i extract the
description
part since its the most useful?i want to extract it to have meaningful email messages with errors that can be understood right away without having to search through the whole other XML mess
$Email_Body = Get-Content -Path $output | Out-String
essentially, the email would have:
Either the dimension with the ID of '0f585685' does not exist in the database with the ID of '', or the u ser does not have permissions to access the object.
also some outputs sometimes contain multiple errors/descriptions.
how would i handle that?
for example:
<return xmlns="urn:schemas-microsoft-com:xml-analysis"><root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"><Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /><Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"><Error ErrorCode="-1055784933" Description="[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /><Error ErrorCode="-1055784860" Description="A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" />
can all descriptions be stored as part of
$Email_body
and sent? so in this case, it would be:[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface.
A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '.
Monday, March 11, 2019 8:26 PM
All replies
-
[xml]$xml = Invoke-ASCmd -InputFile $file -Server $Server $xml.return.root.Messages.error.Description
Here is how it works:
[xml]$xml = @' <return xmlns="urn:schemas-microsoft-com:xml-analysis"> <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"> <Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /> <Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"> <Error
ErrorCode="-1055653884" Description="Either the dimension with the ID of '0f585685' does not exist in the database with the ID of '', or the user does not have permissions to access the object." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /> </Messages> </root> </return> '@ $xml.return.root.Messages.Error.Description
\_(ツ)_/
Monday, March 11, 2019 8:56 PM -
[xml]$xml = Invoke-ASCmd -InputFile $file -Server $Server $xml.return.root.Messages.error.Description
Here is how it works:
[xml]$xml = @' <return xmlns="urn:schemas-microsoft-com:xml-analysis"> <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"> <Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /> <Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"> <Error
ErrorCode="-1055653884" Description="Either the dimension with the ID of '0f585685' does not exist in the database with the ID of '', or the user does not have permissions to access the object." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /> </Messages> </root> </return> '@ $xml.return.root.Messages.Error.Description
\_(ツ)_/
also, some outputs sometimes contain multiple errors/descriptions.
how would i handle that?
for example:
<return xmlns="urn:schemas-microsoft-com:xml-analysis"><root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"><Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /><Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"><Error ErrorCode="-1055784933" Description="[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /><Error ErrorCode="-1055784860" Description="A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" />
can all descriptions be stored as part of
$xml
and sent? so in this case, it would be:[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface.
A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '.
- Edited by cataster Monday, March 11, 2019 9:05 PM
Monday, March 11, 2019 9:05 PM -
Hi,
Based on the complexity and the specific situation, we need to do more researches. If we have any updates or any thoughts about this issue, we will keep you posted as soon as possible. Your kind understanding is appreciated. If you have further information during this period, you could post it on the forum, which helps us understand and analyze this issue comprehensively.
Sorry for the inconvenience and thank you for your understanding and patience.
Best regards,
Lee
Just do it.
Wednesday, March 13, 2019 7:44 AM -
[xml]$xml = Invoke-ASCmd -InputFile $file -Server $Server $xml.return.root.Messages.error.Description
Here is how it works:
[xml]$xml = @' <return xmlns="urn:schemas-microsoft-com:xml-analysis"> <root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"> <Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /> <Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"> <Error
ErrorCode="-1055653884" Description="Either the dimension with the ID of '0f585685' does not exist in the database with the ID of '', or the user does not have permissions to access the object." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /> </Messages> </root> </return> '@ $xml.return.root.Messages.Error.Description
\_(ツ)_/
nice!
also, some outputs sometimes contain multiple errors/descriptions.
how would i handle that?
for example:
<return xmlns="urn:schemas-microsoft-com:xml-analysis"><root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"><Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" /><Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception"><Error ErrorCode="-1055784933" Description="[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" /><Error ErrorCode="-1055784860" Description="A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '." Source="Microsoft SQL Server 2017 Analysis Services" HelpFile="" />
can all descriptions be stored as part of
$xml
and sent? so in this case, it would be:[Teradata Database] [8017] The UserId, Password or Account is invalid.. The exception was raised by the IDbConnection interface.
A connection could not be made to the data source with the DataSourceID of '', Name of 'Teradata '.
If there are multiple error tags then they will be ab array.
$xml.return.root.Messages.Error[0].Description
\_(ツ)_/
Wednesday, March 13, 2019 7:55 AM