1

I would like to create a txt file report about installed products. I get these information from an XML document with the following structure:

<xmlroot>
 <product definitionName="ProductName" versionMajor="1" versionMinor="1" versionBuild="111">
 </product>

Now, after I filtered by definitionName, I want to write a file with two colomns "ProductName" and "Version" by concatenating the versions like this "1.1.111".

When I do this:

$ProductVersions.xmlroot.product | Select-Object -Property definitionName, versionMajor,     versionMinor, versionBuild

I get a list like this:

definitionName                                  versionMajor                                   versionMinor                                    versionBuild                                  
--------------                                  ------------                                   ------------                                    ------------                                  
ProductName                                     1                                               1                                               111      

What I want is a list like this:

ProductName                                   Version                          
--------------                                ------------                              
ProductName                                   1.1.111

Please help me to find a way. Thank you.

1 Answer 1

2

Try this:

PS C:\> $ProductVersions.xmlroot.product |
 Select-Object -Property @{n='ProductName';e={$_.definitionName}}, @{n='Version';e={"$($_.versionMajor).$($_.versionMinor).$($_.versionBuild)"}}

ProductName                                                               Version                                                                 
-----------                                                               -------                                                                 
ProductName                                                               1.1.111                   

Slightly cleaner version suggested by @Ansgar Wiechars:

PS C:\> $ProductVersions.xmlroot.product |
 Select-Object -Property @{n='ProductName';e={$_.definitionName}},
  @{n='Version';e={"{0}.{1}.{2}" -f $_.versionMajor, $_.versionMinor, $_.versionBuild}}

ProductName                                                               Version                                                                 
-----------                                                               -------                                                                 
ProductName                                                               1.1.111                                                                 
Sign up to request clarification or add additional context in comments.

2 Comments

You could also use the format operator instead of subexpressions: "{0}.{1}.{2}" -f $_.versionMajor, $_.versionMinor, $_.versionBuild
@AnsgarWiechers, I've added that version to my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.