I'm very new to PowerShell and have basically zero knowledge about PowerShell scripting, which is why I need some help.
I have folder structure with subfolders (as shown below) for which I want to generate a filelist.txt in every 1st level subfolder using Get-ChildItem -Recurse.
Main Folder
├───Sub 1
│ │ file.ext
│ └───Sub A
│ file.ext
└───Sub 2
| | file.ext
| └───Sub B
└─── etc.
So far, I experimented with some code I found online but either I'm getting errors or absolutely nothing happens. This is the closest thing to what I want, as it creates filelist.txt files in the correct directories, but unfortunately those files are empty. In addition, a filelist.txt is created in the main folder which I don't want.
Get-ChildItem -Recurse -Directory |
ForEach-Object {
New-Item -ItemType file -Path "$($_.FullName)" -Name "filelist.txt"
Get-ChildItem $_ -Recurse > filelist.txt
}
Any help or suggestions are very appreciated!