Recursively Setting Directory Attributes in PowerShell

As I found out the (excellent) Egnyte Desktop Sync client for Windows ignores directories that have the system attribute set. For some reason some of the directories I wanted to sync did have this attribute set. Getting rid of the system attribute on (many) directories is harder than it seems.

Explorer

While you can get Explorer to display a directory’s attributes…

Explorer showing directory with system attribute set

…it does not let you change all of them. Specifically not the system attribute:

Explorer directory properties

Command Line

The good old attrib command lets you remove the system attribute, of course. It even has an option to work recursively. Unfortunately this applies to files only, not directories:

attrib -s /d /s d:\test1

PowerShell

PowerShell to the rescue! The following command removes the system attribute recursively from all directories, starting at D:\test1:

Get-ChildItem D:\test1 -Recurse -Force -ErrorAction SilentlyContinue | Where-Object {$_.PSIsContainer -and $_.Attributes -match "System"} | foreach {$_.Attributes = ""}

If you only want to list directories with the system attribute use this instead:

Get-ChildItem d:\test1 -Recurse -Force -ErrorAction SilentlyContinue | Where-Object {$_.PSIsContainer -and $_.Attributes -match "System"} | Select-Object FullName

Comments

Related Posts

Creating Realistic Test User Accounts in Active Directory

Creating Realistic Test User Accounts in Active Directory
When you need to simulate a real Active Directory with thousands of users you quickly find that creating realistic test accounts is not trivial. Sure enough, you can whip up a quick PowerShell one-liner that creates any number of accounts, but what if you need real first and last names? Real (existing) addresses? Postal codes matching phone area codes? I could go on. The point is that you need two things: input files with names, addresses etc. And script logic that creates user accounts from that data. This blog post provides both.
Scripting

PowerShell Script: Test Chrome, Firefox & IE Browser Performance

PowerShell Script: Test Chrome, Firefox & IE Browser Performance
There is more than one way to test the performance of web browsers like Chrome, Firefox, or IE, but regardless of how you do it, you need a consistent workload that makes the browsers comparable. Unless you are testing with synthetic benchmarks (which come with a plethora of problems of their own) you need a way to automate browsers opening tabs and loading URLs. This article presents a simple solution to do just that.
Scripting

Latest Posts