0

I'm using the command:

Get-ChildItem -Path "C:\*" "*.ps1" -Name -Recurse

To return a list of PowerShell scripts on my drive. However, it's returning .pdf, .docx, and .py (among others), as well as the .ps1 files. The list isn't the full list of files on the drive, so it has filtered some. The files that it returned that it shouldn't have, have no connection to PowerShell, even in the body of the document.

Does anyone know what's gong wrong?

  • gci C:\ -filter *.ps1 -recurse -name – SimonS Dec 9 '16 at 12:26
  • That works, thanks. I'll read around further about the commands you've included to see if I can figure out what went wrong. Can you put this as an answer so that I can close the question, please? – Josh Dec 9 '16 at 12:44
  • @Joshcollins Don't forget to use Get-Help for extended information and examples, Get-Help Get-ChildItem -full. – root Dec 9 '16 at 12:59
1

Your only error was the wildcard symbol after C:\ - when you want to run the command and include the subfolders, you just have to add the -recurse switch, this switch will handle everything for you.

gci C:\ *.ps1 -recurse -name
  • Ah, I see now. gci is just an alias. Thanks @SimonS :) – Josh Dec 9 '16 at 13:15
  • @Joshcollins yes. i got tired of writing get-childitem ;-). you're welcome. run get-alias -definition get-childitem to see all its aliases – SimonS Dec 9 '16 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.