HALP - PowerShell and XML
I'm trying to modify an InstallShield script (*.ism) with PowerShell. These are XML files. Specifically I want to set the product version number of the software. In the UI, located in the Installation Information -> General Information section.
This is the XML representation of it:
Code:
<table name="Property">
<row>
<td>ARPNOMODIFY</td>
<td>1</td>
<td />
</row>
<row>
<td>ARPNOREMOVE</td>
<td>1</td>
<td />
</row>
<row>
<td>ARPURLINFOABOUT</td>
<td />
<td />
</row>
<!-- tons more of these /row nodes, before finally at the end we find this -->
<row>
<td>ProductName</td>
<td>MyAwesomeApp</td>
<td />
</row>
<row>
<td>ProductVersion</td>
<td>1.2.3.0</td>
<td />
</row>
</table>
In summary we're looking at/for
Code:
<table name="Property">
<row>
<td>ProductVersion</td>
<td>1.2.3.0</td>
<td />
</row>
</table>
As you can see, there's no id/name to directly address the version number /td node. So I iterate thru the nodes and look for "ProductVersion", knowing the next /td node is where I need to change it. So far, so good - that works.
But how do I change the value "1.2.3.0"?
Code:
# Load it into an XML object
$xmlDoc = New-Object -TypeName XML
$xmlDoc.Load($temp)
#
# //msi/table[@name="Property"]/row/td[text()="ProductVersion"]
[bool]$foundVersion = $False
foreach ($xmlItem in (Select-XML -Xml $xmlDoc -XPath '//msi/table[@name="Property"]/row/td'))
{
# The previos node was 'ProductVersion', this one is the actual version number then
If ($foundVersion) {
Write-Host " - (Before) xmlItem.ToString()" $xmlItem.ToString()
$xmlItem = $versionSoftware
Write-Host " - (After) xmlItem.ToString()" $xmlItem.ToString()
$foundVersion = $False
}
If ($xmlItem.ToString() -eq "ProductVersion") {
Write-Host "- !!! Found it:" $xmlItem.ToString()
$foundVersion = $True
}
}
$xmlDoc.Save($temp)
Here's the output of that snippet
Code:
- !!! Found it: ProductVersion
- (Before) xmlItem.ToString() 1.2.3.0
- (After) xmlItem.ToString() 1.2.3.4
However, although the time stamp of the file is updated, indicating a successful save, the version number hasn't changed. What am I overlooking here?
Bookmarks