Showing Hidden Files in File Explorer

by Sep 20, 2013

PowerShell can easily read and write to the Registry, the central store for Windows settings.

Here's a function that can turn the display of hidden files in File Explorer on and off. The clever part is not necessarily writing new values to the Registry. It is rather how the script manages to make sure that File Explorer windows recognize the changes and update their content:

function Show-HiddenFile
{
    param([Switch]$Off)
    
    $value = -not $Off.IsPresent
    Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced `
-Name Hidden -Value $value -type DWORD $shell = New-Object -ComObject Shell.Application $shell.Windows() | Where-Object { $_.document.url -eq $null } | ForEach-Object { $_.Refresh() } }

Show-HiddenFile makes hidden files visible, and Show-HiddenFile -Off turns hidden files off, again. Results are effective almost instantaneously in all open File Explorer windows. If you do the change while no File Explorer window is open, the change will not take effect immediately, though, because then there is no window to call Refresh() on.

Twitter This Tip! ReTweet this Tip!