When I run that code I end up with an empty results CSV. When I run this:
$alResults = New-Object System.Collections.ArrayList
foreach ($record in (Import-CSV c:\csv\LT24920.csv)) # $file))
{
if ($record."Product Name" -match "Microsoft Office*")
{
$alResults.Add($($record | Select-Object "PC Name", "Product Name", "Key/Serial", "Other 1"))
}
}
echo $alResults
I get this output:
PS C:\csv> & C:\csv\MS_Office_v1.ps1
0
1
2
PC Name Product Name Key/Serial Other 1
------- ------------ ---------- -------
LT24920 Microsoft Office Standard ... <correct key> OPEN [Volume License Key] ...
LT24920 Microsoft Office Visio Pro... <correct key> Unknown media Key
LT24920 Microsoft Office Standard ... <correct key> Office XP or Open License ...
So that part of the code is working but something isn't working either with the <foreach ($file in (Get-ChildItem C:\csv -Include "*.csv")> or <$alResults | Export-CSV C:\CSV\Results\MS_Office.csv -NoType>. Any suggestions?
Edit: Okay, the problem is with <foreach ($file in (Get-ChildItem C:\csv -Include "*.csv")>. I added the Export-CSV part back in and it gives me a results CSV with the header and the three "Microsoft Office*" records from LT24920.csv just like it should.
$alResults = New-Object System.Collections.ArrayList
foreach ($record in (Import-CSV c:\csv\LT24920.csv)) # $file))
{
if ($record."Product Name" -match "Microsoft Office*")
{
$alResults.Add($($record | Select-Object "PC Name", "Product Name", "Key/Serial", "Other 1"))
}
}
echo $alResults
$alResults | Export-CSV C:\csv\results\MS_Office.csv -NoType
<message edited by grazapin on Friday, January 22, 2010 6:53 AM>