Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

can powershell search xml?

Posted on 2014-08-15
7
Medium Priority
?
350 Views
Last Modified: 2014-08-25
can you suggest syntax for powershell to search for a particular phrase inside an xml file ?
0
Comment
Question by:25112
  • 3
  • 3
7 Comments
 
LVL 14

Assisted Solution

by:Brad Groux
Brad Groux earned 400 total points
ID: 40263767
Yes, PowerShell can search XML using the Import-Clixml CmdLet - http://technet.microsoft.com/en-us/library/ee176873.aspx

Example:
PS C:\> Import-Clixml .\proc_baseline.xml | sort -property pm -Descending |

 select -first 10

Handles  NPM(K)    PM(K)     WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----     ----- -----   ------     -- -----------
    783      77   336420    285772   819    43.69   2204 powershell
    544      41   196500    166980   652    13.41   2660 powershell
    348      24    91156     39032   600     1.28     92 wsmprovhost
    186      18    52024     35472   170     5.56    716 dwm
    329      28    24628     24844   213     0.30   2316 iexplore
    311      26    24276     22308   213     0.30    108 iexplore
    210      14    20628     26228    69     5.95   1828 WmiPrvSE
   1327      41    19608     33164   126    49.45    764 svchost
    398      15    19164     21120    56     3.95    728 svchost
    722      47    17992     23080  1394    13.45    924 svchost

Open in new window

The Script Guy blog explains it fully - http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/01/working-with-xml.aspx
0
 
LVL 41

Expert Comment

by:footech
ID: 40264299
There are various ways you can work with .XML files.  If you provide a sample and say exactly what you are trying to do more specific guidance can be given.
0
 
LVL 5

Author Comment

by:25112
ID: 40274414
the file has extenstion .dtsconfig

the code is
---
<?xml version="1.0"?><DTSConfiguration><DTSConfigurationHeading><DTSConfigurationFileInfo GeneratedBy="SBret-PC\SBret" GeneratedFromPackageName="DownloadHeaderInfo" GeneratedFromPackageID="{76F224FA-D4D1-4CAA-8FA8-9YFDCC946EAB}" GeneratedDate="8/12/2014 3:13:03 PM"/></DTSConfigurationHeading><Configuration ConfiguredType="Property" Path="\Package.Connections[Dashboard].Properties[ConnectionString]" ValueType="String"><ConfiguredValue>Data Source=POS16\POSBoard;Initial Catalog=AMP;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-DownloadHeaderInfo;</ConfiguredValue></Configuration></DTSConfiguration>
---

can you please copy the above and then save in a text as DownloadHeaderInfo.dtsconfig .. this is what we need to search inside of.. for example, we may search for a string of 'POS16'..

thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 41

Expert Comment

by:footech
ID: 40274546
OK, so you're seaching for the string "POS16".  Does it have to be in a certain field or anywhere in the file?  What do you need returned if it is found?
0
 
LVL 5

Author Comment

by:25112
ID: 40283417
anywhere in the file.

we will searching so many dtsconfig files.. so just return a list of the files that contain this string, please?
0
 
LVL 41

Accepted Solution

by:
footech earned 1600 total points
ID: 40283853
In that case, you don't need to treat the file as XML, you can just treat it like any text file.
$searchPath = "C:\path"
$searchString = "POS16"
Get-ChildItem $searchpath -filter *.dtsconfig | Select-String $searchString | Select Filename

Open in new window

0
 
LVL 5

Author Comment

by:25112
ID: 40283863
thank you very much- it worked.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
Screencast - Getting to Know the Pipeline

810 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