Am trying to output a list of array objects to a CSV file. However, I would like to have the directory, name, lastwritetime and owner in separate columns instead of joining them in one column. Not sure, how to workaround this situation. please see the current code below. The output to gridview and text works fine, but not the csv output.
thx.
$Path = "A:\Test"
$PathArray = @()
$Results = "A:\Test\test_results_7.csv"
$extension = "xml"
# This code snippet gets all the files in $Path that end in extension parameter.
# where the file update was made in the last 30 days
Get-ChildItem $Path -Filter "*.$extension" -recurse |
Where-object { $_.LastWriteTime -ge (Get-Date).AddDays(-30)} |
ForEach-Object {
$PathArray += -join ($_.Directory , " , " , $_.Name , " , " , $_.LastWriteTime , " , " , ((Get-ACL $_.Fullname).Owner) )
}
$PathArray += -join ("Path Location" , " , " , "File name" , " , " , "Last Write Time" , " , " , "Owner" )
#$PathArray | Out-GridView
$PathArray | select-object $PathArray | ForEach-Object {$_} | Export-csv $Results