Skip to main content

Powershell: Get-ChildItem

List, search/find files and directories with Get-ChildItem cmdlet.

Using Powershell Get-ChildItem cmdlet to get files and folder
Using Powershell Get-ChildItem cmdlet to get files and folder

Get hidden files and folders

Get-ChildItem -Force

Using Powershell 'Get-ChildItem -Force' to get hidden files and folders
Using Powershell 'Get-ChildItem -Force' to get hidden files and folders
NAME
    Get-ChildItem

SYNOPSIS
    Gets the files and folders in a file system drive.


    -------------------------- EXAMPLE 1 --------------------------

    C:\PS>Get-ChildItem

    Description

    -----------

    This command gets the files and subdirectories in the current directory. If the current directory does
    not have child items, the command does not return any results.




    -------------------------- EXAMPLE 2 --------------------------

    C:\PS>Get-Childitem -System -File -Recurse

    Description

    -----------

    This command gets system files in the current directory and its subdirectories.




    -------------------------- EXAMPLE 3 --------------------------

    C:\PS>Get-ChildItem -Attributes !Directory,!Directory+Hidden

    C:\PS> dir -att !d,!d+h

    Description

    -----------

    These command get all files, including hidden files, in the current directory, but exclude
    subdirectories. The second command uses aliases and abbreviations, but has the same effect as the first.




    -------------------------- EXAMPLE 4 --------------------------

    C:\PS>dir -ad

    Description

    -----------

    This command gets the subdirectories in the current directory. It uses the "dir" alias of the
    Get-ChildItem cmdlet and the "ad" alias of the Directory parameter.




    -------------------------- EXAMPLE 5 --------------------------

    C:\PS>Get-ChildItem -File -Attributes !ReadOnly -path C:\ps-test

    Description

    -----------

    This command gets read-write files in the C:\ps-test directory.




    -------------------------- EXAMPLE 6 --------------------------

    C:\PS>get-childitem . -include *.txt -recurse -force

    Description

    -----------

    This command gets all of the .txt files in the current directory and its subdirectories.

    The dot (.) represents the current directory. The Include parameter specifies the file name extension.
    The Recurse parameter directs Windows PowerShell to search for objects recursively, and it indicates that
    the subject of the command is the specified directory and its contents. The Force parameter adds hidden
    files to the display.




    -------------------------- EXAMPLE 7 --------------------------

    C:\PS>get-childitem c:\windows\logs\* -include *.txt -exclude A*

    Description

    -----------

    This command gets the .txt files in the Logs subdirectory, except for those whose names start with the
    letter A. It uses the wildcard character (*) to indicate 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 contents of the current directory automatically; you need to specify it.




    -------------------------- EXAMPLE 8 --------------------------

    C:\PS>get-childitem -name

    Description

    -----------

    This command retrieves only the names of items in the current directory.

PS D:\>

Get hidden files in current folder

Get-ChildItem -File -Hidden -ErrorAction SilentlyContinue
gci -Re -Dir -Hid -Filter '*3*' -ErrorAction SilentlyContinue

Practice

>>> THM | 25 Days of Cyber Security - Day 21

Related articles

Linux command: ls

Popular posts from this blog

Microsoft Windows Server 2012 R2 Standard Evaluation Product Key

Microsoft Windows Server 2012 R2 Standard Evaluation D2N9P-3P6X9-2R39C-7RTCD-MDVJX DBGBW-NPF86-BJVTX-K3WKJ-MTB6V

ManageEngine ServiceDesk Plus - Reset password

Let's reset the default administrator's password to 'admin'

hmailserver: Notes from the field

hmailserver is one of free open source mail servers running on Microsoft Windows operating system.