Solved

Need a Powershell Parse of some XML code

Posted on 2014-03-10
5
166 Views
Last Modified: 2014-08-25
Code below work fine i move the data to the folders listed below. What I need The Select Query has a Meta_Data Column that gets parsed by the for each code a row gets created to each data set. What I would Like is to add the ID value from Query to each line but don't know syntax to do it


add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue
cls 

$DetailLines =  Invoke-Sqlcmd -MaxCharLength 10000000 -ServerInstance $SQLInstance -Query "SELECT top 10 META_DATA,ID FROM CKOLTP.dbo.P_MEMBER_HRA WITH (NOLOCK) WHERE META_DATA IS NOT NULL"

Foreach ($Line in $DetailLines )
{

#Write-Host $Line.META_DATA

[xml]$xml = $Line.META_DATA
$xml.ResultsCache | export-csv –append -NoType -Force "C:\Users\ltorres\Desktop\DataDumps_PS\test5.csv"
$xml.ResultsCache.Page | % { $page = $_; $_.Question | select `
  @{n='PageID'        ; e = {$page.ID}},
  @{n='flush_concepts'; e = {$page.flush_concepts}},
  @{n='valid'         ; e = {$page.valid}},
  @{n='update_date'   ; e = {$page.update_date}},
  ID, 
  Score, 
  Value
  
} | export-csv –append -NoType -Force "C:\Users\ltorres\Desktop\DataDumps_PS\test51.csv"  

}

Open in new window

0
Comment
Question by:Leo Torres
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 39920132
Hi  ltorres321

Please can you provide a sample of your input data , and the result set , and then show the result you would like, as this is unclear how i can help you

Thanks
Joe
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 39920941
Here is a sample the current code parse that data into several rows I need each of the rows created by the Meta data need to have the "ID" returned by the select query.
Sample2.html
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40262016
Should you still be interested in a solution:

The output (of a single SQL row) is
PageID flush_concepts valid update_date          id  Score value
------ -------------- ----- -----------          --  ----- -----
1      0              1     7/25/2012 8:43:58 AM 1   0     1
1      0              1     7/25/2012 8:43:58 AM 2   0
1      0              1     7/25/2012 8:43:58 AM 3   0     3
1      0              1     7/25/2012 8:43:58 AM 4   0
1      0              1     7/25/2012 8:43:58 AM 5   0     2
1      0              1     7/25/2012 8:43:58 AM 6   0
1      0              1     7/25/2012 8:43:58 AM 7   0     1
1      0              1     7/25/2012 8:43:58 AM 8   0     jehovah's witness
1      0              1     7/25/2012 8:43:58 AM 9   0     65
1      0              1     7/25/2012 8:43:58 AM 10  0     2
1      0              1     7/25/2012 8:43:58 AM 11  0     210::505
1      0              1     7/25/2012 8:43:58 AM 12  0     70::365
1      0              1     7/25/2012 8:43:58 AM 13  0     2
1      0              1     7/25/2012 8:43:58 AM 14  0
1      0              1     7/25/2012 8:43:58 AM 15  0     1
2      0              1     7/25/2012 8:44:54 AM 16  0     30.1
2      0              1     7/25/2012 8:44:54 AM 17  2     3
2      0              1     7/25/2012 8:44:54 AM 18  0     1
2      0              1     7/25/2012 8:44:54 AM 19  0     2
2      0              1     7/25/2012 8:44:54 AM 20  0     1
2      0              1     7/25/2012 8:44:54 AM 21  0     1
2      0              1     7/25/2012 8:44:54 AM 22  0     1
2      0              1     7/25/2012 8:44:54 AM 23  0     2
2      0              1     7/25/2012 8:44:54 AM 24  0     2
3      0              1     7/25/2012 8:45:28 AM 25  0     4
3      0              1     7/25/2012 8:45:28 AM 26  0

Open in new window

which looks fine to me. The ID column is question.ID, Can you give an example of the desired output?
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40262021
0
 
LVL 8

Author Closing Comment

by:Leo Torres
ID: 40282506
Sorry thought this was closed. Solution was provided
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question