Check Folder Persmissions

Anyone,

I have a list of folders and owners as follows :

AD ACCOUNT      FOLDER          OWNER
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 ....
CaussyRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Where are the folders and how are they setup?
0
CaussyRAuthor Commented:
These folders would be on a share, and over time Administrators have taken ownership but have not changed the permissions back
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

CaussyRAuthor Commented:
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 ?
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
$folders = Get-childItem c:\users | where-object { $_.PSIsContainer -eq $True }
foreach ($folder in $folders)
{
// your code
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CaussyRAuthor Commented:
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 ??
0
CaussyRAuthor Commented:
Could anyone assist me, please ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.