Somewhat confused as what I need to use to acheive my goal. Here is what I need to do:
- Recursively, get a list of files
- Get the filename, lastwritedate, owner and append to an array
- When the array reaches 500, output it to a csv filename.csv. Have a file for each 500 line output
- Continue on, outputting files with details (500 lines) until end
I'm not conceptually grasping if I need a recursive function or can do some tricky while/do/for loop work.
Here is what I have so far:
$array = @()
$files = ls c:\users –recurse
$counter = 0
$filename = 0
foreach ($file in $files){
if($counter -ne 500){
write-host "Doing loop, counter is " $counter
$owner = Get-Acl $file.FullName
$data = new-object -type PSObject
$data | add-member -membertype noteproperty -name "File" -value $file.FullName
$data | add-member -membertype noteproperty -name "LastWriteTime" -value $file.LastWriteTime
$data | add-member -membertype noteproperty -name "Created" -value $file.CreationTime
$data | add-member -membertype noteproperty -name "Owner" -value $file.Owner
$array += $data
$counter ++
else($counter -eq 500){
$counter = 0
$array = @()
$array | export-csv "c:\temp\filelist\file-$filename.csv"
$filename ++
}
}
}
I've actually tried a bunch of different things, loop types etc. I just cant quiet figure out how to get the script to "goto start of for loop" as my understanding isn't there yet.
The reason I'm limiting to 500 lines is because this will run on a fileserver with millions of files, and a simple get-childitem wasn't quiet handling it gracefully.
I'm happy to not be given the direct answer, but given some hints as to what I need to do would be great (this isn't homework, I like learning powershell ha :))