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_Product | PassFail |
| Smileys 6 on Host? | YES |
| Smileys 6 on Host? | YES |
SHould Be:
| COTS_Product | PassFail |
| JRE 7 on Host? | YES |
| Smileys 6 on Host? | YES |
| Please Help. | |