none
get-childitem, cant exclude directory RRS feed

  • Question

  • i am trying to search the hdd for a .url shortcut, my script is pretty simple, but I am trying to recursively search the drive and exclude the windows folder. I have tried exclude, I have tried piping it to a object and using where -nomatch. but every single time it keeps looking in the windows folder.

    get-childitem -Path C:\*\"CDS.url" -r -Exclude "Windows"

    thank you.



    Thursday, August 21, 2014 11:43 PM

Answers

  • get-childitem c:\ -Directory |
         ?{$_.Name -ne 'windows'} |
         Get-ChildItem -include cds.url -recurse -ea 0

    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 22, 2014 1:04 AM
    • Marked as answer by justin rassi Friday, August 22, 2014 1:42 AM
    Friday, August 22, 2014 1:04 AM

All replies

  • get-childitem c:\ -Directory |
         ?{$_.Name -ne 'windows'} |
         Get-ChildItem -include cds.url -recurse -ea 0

    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 22, 2014 1:04 AM
    • Marked as answer by justin rassi Friday, August 22, 2014 1:42 AM
    Friday, August 22, 2014 1:04 AM
  • wow thanks. ill try it out tomorrow and let you know.
    Friday, August 22, 2014 1:19 AM
  • wow thanks a lot, I was able to adapt with with the rest of my code perfectly. but I do have a question though? why include -ea 0 if it does not throw any error's/warnings, the code works flawlessly?
    Friday, August 22, 2014 1:42 AM
  • On Windows 8 it will throe errors due to protected folders.

    ¯\_(ツ)_/¯

    Friday, August 22, 2014 1:47 AM
  • oh I see, ok. I have one more question. I understand the code, however I have never seen that -directory before in documentation, obviously I can understand its function, but do you perhaps have a link to documentation for it? thank you.
    Friday, August 22, 2014 1:39 PM
  • oh I see, ok. I have one more question. I understand the code, however I have never seen that -directory before in documentation, obviously I can understand its function, but do you perhaps have a link to documentation for it? thank you.

    All documentation for PowerShell is stored in PowerShell.

    The first thing any user of any technology needs to learn is how to type "HELP" and learn the help system.


    ¯\_(ツ)_/¯

    Friday, August 22, 2014 1:46 PM
  • yeah I know the help system, its just that when I did help for gci, or get members, -directory didn't come up. ill try again though, perhaps I missed it. thank you again.
    Friday, August 22, 2014 2:04 PM
  • First just type help and read how to use help.  You are not using it correctly to find what you are looking for.


    ¯\_(ツ)_/¯

    Friday, August 22, 2014 2:13 PM