Check Folder Persmissions

Posted on 2013-10-13
Medium Priority
Last Modified: 2013-10-21

I have a list of folders and owners as follows :

Test01                       Test01          Administrator
Test02                       Test02          Test02
Test03                       Test03         Administrator

Therefore, how do I check that the AD account is the owner of the folder and if not change the owner to the AD account.

In reality, I have more that 500+ folders, so I just need to know how I can read a list of folders in to a variable and check each owner compared to the AD account.

I already have a script that changes the owner of a folder, just need to know how to read all those folders into a variable and check each one, I am looking at For-each ....
Question by:CaussyR
  • 4
  • 3
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39570445
Where are the folders and how are they setup?

Author Comment

ID: 39570598
These folders would be on a share, and over time Administrators have taken ownership but have not changed the permissions back
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39570623
If you could give one example that would be great. (reason is you said you already have the script to change the ownership of a folder). I guess its the same which will work here.
WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!


Author Comment

ID: 39571337
Apologies what I meant was, how do I read in a list of folders and change the owner of the folder.

I have a script that changes the folder owner for one person but how do I read in a number of folders to check ?
LVL 19

Accepted Solution

Raheman M. Abdul earned 2000 total points
ID: 39572332
$folders = Get-childItem c:\users | where-object { $_.PSIsContainer -eq $True }
foreach ($folder in $folders)
// your code

Author Comment

ID: 39585254
Thanks for putting me on the right tracks.

At the moment I have the following :

# Use SAM account and take ownership of user folder

$ADUser = Get-Content 'C:\Temp\SecTest\AdUsers.txt'

$HomeFolders = Get-ChildItem 'C:\temp\SecTest' | Where-Object { $_.PSIsContainer -eq $true }

foreach ($HomeFolder in $Homefolders)


    $User = Get-ADUser $ADUser | Select SID
    get-item $ADUser | set-owner -account $User.SID


When I run the above I get the following error :

 Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified
method is not supported.

I am new to Powershell, but I think I may need to convert this to a string ??

Author Comment

ID: 39586277
Could anyone assist me, please ?

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Just after setting up Cloud PBX connectivity and migrated Skype users to SFBO, we noticed inbound calls not working but outbound calls would work.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question