My question is almost answered by this question answer, but the command suggested there spits out many error messages re: the inaccessibility of certain system folders when searching the entire system drive.
So, is there any way to make gci -Path "C:\" -Recurse | where {$_.Name -like '*.txt'} return all txt files on C:, ignoring inaccessible folders?
I would also accept any answer that points to an alternative cmd or powershell command that effectively does the same thing. MTIA! :-)
UPDATE: Apologies for the negative comments guys, I obviously didn't test out this exact scenario properly, nor did I explain what I really want (see Mael's comment below and my replies to it).
I am trying to automate the process of setting up an SSH client, and want to search for any/all public keys that already exist on the system before I go unnecessarily creating new ones. So the extension that I'm actually searching for is .pub, not .txt!
I originally said .txt coz I thought it would be clearer and easier to test, without effecting the results...obviously I was wrong! But why?? Ideally, the command that I'm searching for would work with any file extension (i.e. *.ext, not *.ext*), and not produce false positives like <left part of file or folder name><extension><right part of name>.
Thanks again everyone! :-)