I have a PowerShell script I am trying to write. Basically I am trying to find folders that have a specific name within a shared volume, there are multiple instances of these folders at various DIR levels all throughout the share all with the same name. I need too list both the folder path and the contents and output to CSV. I have been able list the folder paths with the following script:
gci -Filter "foldername" -Recurse -Path "X:\DIR" -Directory | select-object FullName | Export-Csv C:\Output\folderlist.csv
That's all well and good, but now I would like to list the file contents of each folder named "Foldername". This is where it get's tricky, some of the folders have contents, some are empty. I always need to output the folder path, even if it's empty, and also list the folder contents, if it has contents.
The following script will list all folders named "foldername", but it only outputs the folders that have contents, if the folder is empty, then the path listing does not get included.
gci -Path X:\DIR -Filter *foldername* | where { $_.psiscontainer } | gci | Export-Csv C:\Output\folderlist.csv
I am also running into a 260 character limit on PowerShell now. It's fine when only listing the folders, but then when it get's to the file level, it bombs out on some folders because either the folder path, or file name are then too long.
I read an article about someone using robocopy through PowerShell to get around the 260/248 char limit.
Any suggestions would be fantastic.