Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

writing an array of custom objects to CSV

$
0
0

I am brand new to PS. I have been reading many, many forums and am stuck on something I think you all will find very easy.

Essentially all I want to do is use the test-path method to determine if a file and track yes or no. Repeat for several products. And finally export to a CSV.  So far I have cobbled together the If statement that will return a Yes Or No with the product name.  Able to put it into an array of custom objects so I can export-csv without just getting the just the name lengths.  The problem is that I only get the last value of the custom objects over and over again.  Here's my simple code:

$hostname = hostname
$Products = @()
$myobj = "" | select COTS_Product, PassFail

 

If(test-Path -Path C:\"Program Files"\Java\jre7\THIRDPARTYLICENSEREADME.txt)
{
$myobj.COTS_Product = "JRE 7 on Host?"
$myobj.PassFail = "YES"
$Products += $myobj
}
else
{
$myobj.COTS_Product = "JRE 7 on Host?"
$myobj.PassFail = "NO"
$Products += $myobj
}

##Product 2
If(test-Path -Path H:\Smileys\6.gif)
{
$myobj.COTS_Product = "Smileys 6 on Host?"
$myobj.PassFail = "YES"
$Products += $myobj
}
else
{
$myobj.COTS_Product = "Smileys 6 on Host?"
$myobj.PassFail = "NO"
$Products += $myobj
}

$Products | Export-Csv H:\$hostname.csv -NoTypeInformation

Here's my output:

COTS_ProductPassFail
Smileys 6 on Host?YES
Smileys 6 on Host?

YES

SHould Be:

COTS_ProductPassFail
JRE 7 on Host?YES
Smileys 6 on Host?YES
Please Help.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>