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

Demistify Buffer Overflow Vulnerability

Collection of articles, blog posts, lectures, tutorials... about Buffer Overflow Vulnerability.

Check and install php7.0-mbstring extention on Ubuntu 16.04 and Microsoft Windows

While learning Facebook SDK for PHP I overlooked one of system requirements preventing my code from running on my host. That is The mbstring extension. Facebook SDK for PHP's system requirements Check if mbstring is enabled root@ubuntu001:~# php -a Interactive mode enabled php > echo extension_loaded('mbstring'); php >exit root@ubuntu001:~# apt-cache search php7 | grep mbstring php7.0-mbstring - MBSTRING module for PHP root@ubuntu001:~# Install php7.0-mbstring root@ubuntu001:~# apt-get install php7.0-mbstring Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required:   fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0   libjpeg-turbo8 libjpeg8 libmcrypt4 libtiff5 libvpx3 libxpm4 Use 'apt autoremove' to remove them. The following additional packages will be installed:   libapache2-mod-php7.0 php7.0-cli ph...

DNS: Notes

D omain N ame S ystem