can powershell search xml?

can you suggest syntax for powershell to search for a particular phrase inside an xml file ?
LVL 5
25112Asked:
Who is Participating?
 
footechCommented:
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
 
Brad GrouxSenior Manager (Wintel Engineering)Commented:
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
 
footechCommented:
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
25112Author Commented:
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
 
footechCommented:
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
 
25112Author Commented:
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
 
25112Author Commented:
thank you very much- it worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.