Home » PowerShell » PowerShell Show Hidden Files

PowerShell Show Hidden Files

Use the Get-ChildItem (or its alias ls) command in PowerShell to get a list of hidden files from directories. Both commands can be used with the -Hidden parameter to show hidden files or the -Force parameter to display hidden files, as well as system files in the specified folder.

PowerShell Show Hidden Files
PowerShell Show Hidden Files

The Hidden attribute on a file means that the file is hidden and not visible in the Windows file explorer or command prompt.

In this article, we will discuss how to show hidden files using the Get-ChildItem cmdlet and ls hidden files using the ls command.

PowerShell Show Hidden Files Using Get-ChildItem

Use the Get-ChildItem cmdlet in PowerShell with the -Hidden or -Force parameter to show hidden files and displays them on the console.

To list hidden files in the directory, use the following script.

Get-ChildItem -Path "D:\PS\temp\" -Hidden 

In the above PowerShell script, the Get-ChildItem cmdlet uses the –Hidden parameter to retrieve the list of hidden files in the specified directory path.

The output of the above script displays the hidden files.

PS C:\> Get-ChildItem -Path "D:\PS\temp\" -Hidden                                                                       

    Directory: D:\PS\temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a-h--       26-02-2023     16:10             87 comp.txt
-a-h--       02-04-2023     19:44              0 rabbitmq_02042023.log


PS C:\>                                                                                                                             

PowerShell ls Hidden Files

The Unix command ls which is an alias of Get-ChildItem in PowerShell can be used to list hidden files with the -Hidden or -Force parameter.

To list and view the hidden files, use the following script.

ls -Path "D:\PS\temp\" -Hidden 

In the above PowerShell script, the ls command uses the -Path parameter to specify the directory path and the -Hidden parameter to list hidden files from the specified directory.

The output of the above PowerShell script to ls hidden files is:

PowerShell ls Hidden Files
PowerShell ls Hidden Files

Display Hidden Files and System Files in PowerShell

Use the Get-ChildItem or its alias ls command with the -Force parameter to display hidden files as well as system files in the specified directory.

To view the hidden files and system files in PowerShell, follow the below script.

# Using the Get-ChildItem -Force

Get-ChildItem -Path "D:\" -Force 
# Using the ls -Force
 ls -Path 'D:\' -Force 

In the above PowerShell script, the Get-ChildItem and ls command uses the -Force parameter to get hidden files and system files as well like $RECYCLE.BIN, System Volume Information, etc.

The output of the above PowerShell script to view hidden files and system files is:

PS C:\> ls -Path 'D:\' -Force

    Directory: D:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d--hs-       04-03-2022     14:58                $RECYCLE.BIN
d-----       20-03-2023     14:16                Projects
d-----       10-04-2023     22:17                PS
d--hs-       16-02-2021     20:50                System Volume Information
d-----       14-02-2023     13:07                Temp



PS C:\> Get-ChildItem -Path "D:\" -Force

    Directory: D:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d--hs-       04-03-2022     14:58                $RECYCLE.BIN
d-----       20-03-2023     14:16                Projects
d-----       10-04-2023     22:17                PS
d--hs-       16-02-2021     20:50                System Volume Information
d-----       14-02-2023     13:07                Temp


PS C:\>

Conclusion

I hope the above article on how to show hidden files using the Get-ChildItem and ls command with the -Hidden parameter is helpful to you.

Using the -Force parameter, it displays the hidden files and system files as well.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.