none
Strange with Get-childitem result RRS feed

  • Question

  • Hi, I was using Get-childitem to get all the DLL files inside C:\Windows\System32 folder.

    But when I am using below command I am getting nothing,

     
    get-childitem -path "C:\Windows\System32" -Include *.dll 

    but when I am filtering the files using Select, I am getting the require result.

    get-childitem -path "C:\Windows\System32" | where { $_.name -like "*.dll" }
    Anyone help, why this is happening

    Friday, November 9, 2018 6:13 PM

All replies

  • Like this:

    get-childitem -path C:\Windows\System32\* -Include *.dll


    \_(ツ)_/

    Friday, November 9, 2018 6:30 PM
  • From my notes:

    # Powershell (Get-ChildItem) appears to have a quirk when you specify an include pattern
     
    # Get-ChildItem  foldername      will return all items in the folder
    # Get-ChildItem  foldername\      will return all items in the folder 
    # Get-ChildItem  foldername\*      will return all items in the folder
     
    # Get-ChildItem  foldername -inc *.log   will NOT return all .log items in the folder
    # Get-ChildItem  foldername\ -inc *.log  will NOT return all .log items in the folder
    # Get-ChildItem  foldername\* -inc *.log  WILL return all .log items in the folder

    You want to use: get-childitem -path "C:\Windows\System32\*" -Include *.dll

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6

    Example 3: Get all child items using an inclusion and exclusion

    This command lists the ".txt" files in the "Logs" subdirectory, except for those whose names start with the letter 'A'. It uses the wildcard character (*) toindicate the contents of the "Logs" subdirectory, not the directory container. Because the command does not include the -Recurse parameter, Get-ChildItem does not include the content of directory automatically; you need to specify it.

    Get-ChildItem -Path C:\Windows\Logs\* -Include *.txt -Exclude A*



    • Edited by MotoX80 Friday, November 9, 2018 6:42 PM
    Friday, November 9, 2018 6:41 PM
  • Thanks, but why below is working.

    dir -Path "$env:CommonProgramFiles" -in *.dll -Recurse

    Friday, November 9, 2018 6:41 PM
  • Thanks, but why below is working.

    dir -Path "$env:CommonProgramFiles" -in *.dll -Recurse

    Because you added "Recurse".

    This also will work:

    get-childitem -path C:\Windows\System32 -Include *.dll  -Recurse

    Adding "Recurse" does not give you what you are asking for.  It is fooling you.


    \_(ツ)_/


    • Edited by jrv Friday, November 9, 2018 6:44 PM
    Friday, November 9, 2018 6:44 PM