Category filter

Script to view files and folders on Windows devices

Managing files and folders on devices becomes easier if they are sorted and easily retrievable. Hexnode UEM allows you to view and list all files and folders on Windows devices using custom scripting feature.


The sample scripts provided below are adapted from third-party open-source sites.

PowerShell Commands

1. List of Files and folders

The Get-ChildItem returns a list of all files/folders present in the specified path.

E.g., Get-ChildItem –Path “C:\Users\QA\Program Files”.

This command lists all the unhidden files and directories present in the “Program Files” folder.

2. List of hidden files and folders

The –Force parameter returns a list of all files/folders present in the specified path, including the hidden files.

E.g., Get-ChildItem –Path‘C:\User\QA’ -Force.

This command returns all the files and directories in the folder “QA”, including hidden files, if any.

3. List of all folders, sub-folders, files in a folder

The Get-ChildItem -Recurse returns a list of all files and directories present in the specified folder. The –Recurse parameter does not return hidden files. Use the -Depth parameter to control the level to which subfolders must be displayed.

E.g., Get-ChildItem –Path’C:\User\QA’-Recurse -Depth 1

As the –Depth parameter is 1, the command will display the content of the parent folder (QA) and immediate subfolders.


  • The output produced with the –Recurse parameter is time-consuming if the -Depth parameter is not used.

4. List of all empty files

The script mentioned above fetches all the files from the specified location. The Get-Content cmdlet scans the contents of each file and lists the empty files.

You can also fetch the list of empty files using length parameter. It counts the length of the file. If it’s 0, the file is considered empty and displayed in the output.

Batch Commands

    1. List of all files and folders

    Parameter Description
    [drive:][path] Specify the drive and path of the folder.
    [filename] Specify filename.
    /q Specify file ownership.

    E.g., dir “C:\Users\QA\Program files” /q

    /w Display output in wide format, as many as five file names or directory names on each line.

    E.g., dir “C:\Users\QA\Program files” /w

    /d Display output with column-based sorting.

    E.g., dir “C:\Users\QA\Program files” /d

    /a[[:]attributes] Display the names of directories files according to the specified attributes.
    • d – Directories
    • h – Hidden files
    • s – System files
    • l – Reparse points
    • r – Read-only files
    • a – Files ready for archiving
    • i – Not content indexed files

    Use a colon (:) as a separator, and use hyphen (-) as a prefix to mean “not”. For example, the -r attribute won’t show the read-only files.
    if a parameter is used without specifying any attributes, the command displays the names of all files, including hidden and system files.

    E.g., dir “C:\Users\QA\Program files” /a:h

    /o[[:]sortorder] Display output according to sortorder :
    • n – Alphabetically by name
    • e – Alphabetically by extension
    • g – Group directories first
    • s – By size, smallest first
    • d – By date/time, oldest first

    Use “-” prefix to reverse the sort order.Use colon( : ) to separate multiple values. If the sort order isn’t specified, dir /o lists the directories alphabetically, followed by the files, which are also sorted alphabetically.

    E.g., dir “C:\Users\QA\Program files” /o:n

    /t[[:]time field] Specify which time field to display or to use for sorting. The available time field values are:
    • c – Creation
    • a – Last accessed
    • w – Last written

    E.g., dir “C:\Users\QA\Program files” /t:c

    /s Specify all the occurrences of the file name within the directories & subdirectories in the provided path.

    E.g., dir “C:\Users\QA\Program files\sys.log” /s

    /b Display the name of directories and files in the form of a list. No added information such as its read or write permissions or created time will be displayed along with the filename. The /b parameter overrides /w.

    E.g., dir “C:\Users\QA\Program files” /b

    /l Produce unsorted lowercase directory and file names.

    E.g., dir “C:\Users\QA\Program files” /l

    /n Produce a long list format of all files and folders present in the path.

    E.g., dir “C:\Users\QA\Program files” /n

    /x Display short names generated for non-8dot3 files.

    E.g., dir “C:\Users\QA\Program files” /x

    /c Display a thousand separators in file sizes. This is the default behavior. Use /-c to hide separators.

    E.g., dir “C:\Users\QA\Program files” /c

    /4 Display year in 4-digit format.

    E.g., dir “C:\Users\QA\Program files” /4


    • It is recommended to manually validate the script execution on a system before executing the action in bulk.
    • Hexnode UEM will not be responsible for any damage/loss to the system on the behaviour of the script.

  • Sample Script Repository