I am trying to parse through a set of directories to see what files are in them.
More specifically I have a directory that contains every letter of the alphabet and then some other directories. With in the letter directories there is another letter directory and some others. Within that letter directory there are user names. In the user name directory there are directories and files.
|---------------------------------------------
| root
| \
| S
| \
| S
| \
| Smith, John
| \
| file1, file2, file3, ...
|----------------------------------------------
This matches the structure that I was speaking about above. I am trying to get the names of the files in a CSV so that I can get the following information: User, File1, File2, File3, Path, LastModified, Created.
The ultimate goal for this is to go through every file and compare the file names to active users in AD, and to see what files each user has for auditing purposes. If there is a better way to do this I am all ears.
I have attempted to do this with the following code but continuously get stuck.
Also the M file is labled M1 while the others are letters, which is why I have the random IF/THEN statement in there.
1
function Get-AccessManagementUsersDocuments(){
$alph = @("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$Path = "...LOCATIONPATH...";
$savePath = "...SAVEPATH..."
foreach ($alph in $alph){
if($alph -ne "M"){
$filePath = Get-ChildItem -Path $Path/$alph/$alph | % { $_.FullName}
$fileName = Get-ChildItem -Path $Path/$alph/$alph | % { $_.Name}
} else {
$filePath = Get-ChildItem -Path $Path/M1/M | % { $_.FullName}
$fileName = Get-ChildItem -Path $Path/M1/M | % { $_.Name}
}
foreach ($filePath in $filePath){
Get-ChildItem $filePath | %{$_.Name}
}
}
}