I'm trying to get a listing of files and their sizes, if their creation date was greater than 3 years ago. This is fine, up until the point I try to output to a CSV file - it seems the part where I'm trying to append to a list is not working correctly. I get the "Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null." error.
Any illumination about what I'm missing in this script would be helpful. It's the first PS script I've written that isn't a one-liner. The one-liner where I output all the files in a directory on screen with the specified fields works fine!
Any illumination about what I'm missing in this script would be helpful. It's the first PS script I've written that isn't a one-liner. The one-liner where I output all the files in a directory on screen with the specified fields works fine!
Code:
$list = @()
foreach ($i in Get-ChildItem T:\ad* -recurse)
{
if ($i.CreationTime -gt ($(Get-Date).AddYears(-3)))
{
$list += select fullname, CreationTime, LastWriteTime, @{Name="Mbytes";Expression={$_.Length / 1Mb}}
}
}
$list | export-csv c:\scripts\gdrive-a.csv