HowTo: Reading / Searching through XML Files

Author Message
turranx

  • Total Posts : 57
  • Scores: 0
  • Reward points : 0
  • Joined: 2/7/2006
  • Location: Cincinnati, OH
  • Status: offline
HowTo: Reading / Searching through XML Files - Friday, July 18, 2008 12:46 PM ( #1 )
The code on this page processes the output file generated by the code located here: http://www.visualbasicscript.com/m_62022/tm.htm

#--------------------==--------------------#
 #--------------  Description --------------#
 #
 # This script takes an input file (example shown below) and looks
 # for any Public Folders where the items counts for all the
 # replicas are not identical.
 
 #--------------- Input File ---------------#
 # 
 # The input file is generated from the output of my PowerShell script
 # Compare_Public_Folders_Between_Ex2000_and_Ex2007.ps1.  An excerpt of
 # this file is shown below.
 # <?xml version="1.0" encoding="ISO-8859-1"?>
 # <Public_Folders>
 #   <x />
 #   <Run_Details>
 #     <Start>
 #       <TimeStamp>
 #         <Year>2008</Year>
 #         <Month>7</Month>
 #         <Day>15</Day>
 #         <Time>13:28:23</Time>
 #       </TimeStamp>
 #     </Start>
 #     <Finish>
 #       <TimeStamp>
 #         <Year>2008</Year>
 #         <Month>7</Month>
 #         <Day>15</Day>
 #         <Time>15:23:26</Time>
 #       </TimeStamp>
 #     </Finish>
 #     <Parameters>
 #       <Connect_As_Identiy>UserID</Connect_As_Identiy>
 #       <New_Server>NewMailServer</New_Server>
 #       <Old_Server>OldMailServer</Old_Server>
 #       <Security_Permission_Mode>Add</Security_Permission_Mode>
 #     </Parameters>
 #   </Run_Details>
 #   <Public_Folder ID="3">
 #     <Name>Access Issues</Name>
 #     <Path>\Access\Access Issues</Path>
 #     <Friendly_Web_Address>HTTP://OldMailServer/public/Access/Access Issues</Friendly_Web_Address>
 #     <Proper_Web_Address>HTTP://OldMailServer/public/Access/Access%20Issues</Proper_Web_Address>
 #     <Replica>
 #       <Server_Name>cocsxchng01</Server_Name>
 #       <Web_Address_Header>http://OldMailServer</Web_Address_Header>
 #     </Replica>
 #     <Replica>
 #       <Server_Name>NewMailServer</Server_Name>
 #       <Web_Address_Header>https://NewMailServer</Web_Address_Header>
 #       <Item_Count>26</Item_Count>
 #       <Byte_Count>540999</Byte_Count>
 #     </Replica>
 #   </Public_Folder>
 
 
 #----------------- Output -----------------#
 #
 # This is an example of the output that is displayed on screen.
 #
 # Item Count mismatch for folder 
 #     \Finance\Conference Call Calendar
 #     OldMailServer :  71
 #     NewMailServer :  55
 # Item Count mismatch for folder
 #     \Marketing\Administration\Team A
 #     OldMailServer :  2655
 #     NewMailServer :  2653
 # Done.
 
 
 set-psdebug –strict;    # Require declaration of powershell variables
 # Set-PSDebug -Off;        # Do not require declaration of variables
 $strPathToFile         = "U:\Development";
 $strFileName         = "XMLDoc.old.txt";
 $xmlLog             = [xml]( Get-Content (join-path -path $strPathToFile $strFileName));
 $colPublicFolders     = $xmlLog.Public_Folders.Public_Folder;
 
 foreach ($objPublicFolder in $colPublicFolders) {
     # If there was only one replica for a folder, then 
     # ($objPublicFolder.Replica -is [array]) would return false
     if ($objPublicFolder.Replica -is [array]) {
         $Item_Count_for_First_Replica = $objPublicFolder.Replica[0].Item_Count;
         $colReplicas = $objPublicFolder.Replica;
         $mismatch = $False;
         # Compare the item count for each replica against
         # the first replica item count.
         foreach ($objReplica in $colReplicas) {
             If ($objReplica.Item_Count -ne $Item_Count_for_First_Replica) {
                 $mismatch = $True;
             }
         }
         if ($mismatch -eq $True) {
             Write-Host "Item Count mismatch for folder`n`t" $objPublicFolder.Path;
             foreach ($objReplica in $colReplicas) {
                 Write-Host "`t" $objReplica.Server_Name ": " $objReplica.Item_Count;}
         }
     }
     $colReplicas = $Null;
     $Item_Count_for_First_Replica = $Null;
     $objReplica = $Null;
 }
 $strPathToFile = $Null
 $strFileName = $Null
 $objPublicFolder = $Null;
 $colPublicFolders = $Null;
 $xmlLog = $Null;
 Write-Host "Done.";
 
Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord

After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.
Jump to:

Current active users
There are 0 members and 1 guests.
Icon Legend and Permission
  • New Messages
  • No New Messages
  • Hot Topic w/ New Messages
  • Hot Topic w/o New Messages
  • Locked w/ New Messages
  • Locked w/o New Messages
  • Read Message
  • Post New Thread
  • Reply to message
  • Post New Poll
  • Submit Vote
  • Post reward post
  • Delete my own posts
  • Delete my own threads
  • Rate post

© 2000-2009 ASPPlayground.NET Forum Version 3.6