Writing a function to find an item in my C drive

Get-ChildItem -Path C:\ -Recurse -Force -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq “Fuad”}

When I run this code, it just keeps running without any error or output. What I expect was the code to fetch me any file /folder/ directory on my PC that has Fuad.

Do help with guidance,thank you

Welcome to the forum. :wave:t4:

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

Your explanation is insufficient or at least somewhat unclear. Are you looking for files AND folders? Should the name be EXACTLY “Fuad” or should it have the search pattern anywhere in its name? :wink:

You may start with something like this:

Get-ChildItem -Path 'C:\' -Filter "*fuad*" -Recurse -Force -ErrorAction SilentlyContinue

Thanks for your response. I was given a task to write a function that could fetch an item on a PC. I used Fuad as an example in the code above because I have many items with Fuad on my PC. I have used the wildcard to find all the items that contains Fuad on my PC. The challenge I have now is that when I created my function, I created a parameter. That would take in the string that is been searched for. Whenever I pass in my parameter the code runs without any error or output

Your original code example would only find files or folders that have the exact name Fuad.

What function? What parameter? How did you call it?

Please keep in mind most, if not all of us, are unable to read your mind or remotely view your screen. Please help us help you by sharing the code you’re actually running (sensitive data replaced by dummy data if appropriate) so we may actually provide meaningful help.

1 Like