Currently, I’m building several arrays in Powershell, but to make the code more portable, I’d like to use XML files as a simpler (read more foolproof) way of managing how each array serves its purpose.
Array 1 is a master list of information – containing a rownumber, Name, retention, and Type. I would like for the XML to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<ZipList>
<Backup RowID="1">
<RowNbr>1</RowNbr>
<NameType>TargetBackup</NameType>
<Retention>10</Retention>
<FileType>Folder</FileType>
</Backup>
<Backup RowID="2">
<RowNbr>2</RowNbr>
<NameType>SourceBackup</NameType>
<Retention>7</Retention>
<FileType>Folder</FileType>
</Backup>
<Backup RowID="3">
<RowNbr>3</RowNbr>
<NameType>XMLBackup</NameType>
<Retention>21</Retention>
<FileType>File</FileType>
</Backup>
</ZipList>
The array I currently build I use to loop thru it later on, and to build hash tables from as well. So, I don’t really want to re-engineer the rest of the powershell script.
However, since it’s easier to make changes to an XML file (as opposed to changing the array inside the script), all I want to do is to duplicate this array in an XML file that would be a little more straightforward & self-documenting to make changes to, read this xml file in and then store it in the array I’m currently creating.
I can get the xml file read in, but I’m having trouble getting the xml data into an array. For the above XML example, the array would look like this:
counter ++
arr1 += ,@(counter,1,"TargetBackup",10,"Folder")
counter ++
arr1 += ,@(counter,2,"SourceBackup",7,"Folder")
counter ++
arr1 += ,@(counter,3,"XMLBackup",21,"File")
and so on….
The issue I am having is that the xml data is in, but it’s a string that I can’t do anything with other than grab it all at once. Any help, suggestions appreciated.
Why not just export that array as clixml. Then its portable, and when you want to use it in your script, just re-import it and you have your array back.