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

Install Microsoft .NET Core SDK

.NET Core Software Development Kit (SDK) is a set of libraries and tools that allow developers to create .NET Core applications and libraries.

Google Credential Provider for Windows: Notes

Google Credential Provider for Windows® (GCPW) lets users sign in to Windows® devices with the Google Account they use for work. GCPW provides users with a single sign-on experience to Google services and all the security features available with their Google Account.

IBM Domino: Enable SMTPClientDebug, SMTPDebug

Add parameters to NOTES.ini SMTPClientDebug=1 SMTPDebug=2 Option 1: Add parameters via GUI IBM Domino: Enable SMTPDebug in NOTES.ini Option 2: Add parameters via command SET CONFIG "SMTPClientDebug=1" update Run command to update router configuration tell router update config IBM Domino: tell router update config to update configuration and reload routing table Send an email to @gmail.com to check result IBM Domino: Log file after enabling SMTPClientDebug parameter in NOTES.ini file