I have a csv ($HomeDir) file like this:
Users,Comments,HomeDir
user1,account1,c:folder1
user2,account2,c:folder2
user3,account3,c:folder3
I get succesfully LastAccessTime for each subfolder in 'HomeDir' column with this code:
$csv = Import-Csv $HomeDir
foreach ($folder in $csv.HomeDir) {
Get-ChildItem $folder -ErrorAction SilentlyContinue |
? {$_.PSIsContainer -eq "True"} |
Select-Object FullName, @{Name='LastAccessTime'; Expression={$_.LastAccessTime.ToString('yyyyMMdd')}} |
Sort-Object -Descending -Property LastAccessTime |
Export-Csv $newcsv -NoTypeInformation -Append
}
The result of $newcsv is:
"FullName","LastAccessTime"
"c:folder1Sub1","20201223"
"c:folder1Sub1a","20201223"
"c:folder1Sub1b","20201223"
"c:folder2Sub2","20201218"
"c:folder2Sub2a","20201218"
"c:folder3Sub3","20201212"
"c:folder3Sub3a","20201215"
"c:folder3Sub3b","20181215"
"c:folder3Sub3c","20201011"
The questions is: is there a way to assign the related User based on corresponding 'Users' column?
It would also be enough for me to get an output like this
"Users","FullName","LastAccessTime"
"user1","c:felder1Sub1","20201223"
"user1","c:folder1Sub1a","20201223"
"user1","c:folder1Sub1b","20201223"
"user2","c:folder2Sub2","20201218"
"user2","c:folder2Sub2a","20201218"
"user3","c:folder3Sub3","20201212"
"user3","c:folder3Sub3a","20201215"
"user3","c:folder3Sub3b","20181215"
"user3","c:folder3Sub3c","20201011"
Thanks in advance