Hidden files

If you suspect there are hidden files in a folder you can use the Attributes parameter to discover them:

PS> Get-ChildItem -Path c:\test -Attributes H


PS> Get-ChildItem -Path c:\test -Attributes h


PS> Get-ChildItem -Path c:\test -Hidden

If you want to see all files irrespective of them being hidden use Force

PS> Get-ChildItem -Path c:\test –Force

which will also show system files.

There are a number of ways to make a file hidden but the most generic is:

PS> Get-ChildItem -Path C:\test\Newoutdata03.txt  | ForEach-Object {$_.Attributes += ‘Hidden’}

You can modify the criteria used to define the files passed into Foreach-Object by using the path,  filter, exclude or include parameters of Get-ChildItem. The Hidden attribute is set while preserving the other attributes.

To remove the Hidden attribute:

PS> Get-ChildItem -Path C:\test\ -Hidden | ForEach-Object {$_.Attributes -= ‘Hidden’}

The Hidden attribute is removed whilst preserving other attributes. The files passed into ForEach-Object can again be filtered with the Get-ChildItem parameters.

This entry was posted in Powershell. Bookmark the permalink.

1 Response to Hidden files

  1. Pingback: PowerShell Schnipseljagd 49/2019 – PowerShell Usergroup Austria

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s