Solved

List Folder Owners

Posted on 2013-12-18
2
391 Views
Last Modified: 2013-12-18
Hi everyone,

I am reading in a text file, folder.txt, which has 2 folder names entered.  This is then read into a variable called $Homefolders.

I have tried the below, but for some reason it reads the second folder in and I get something like :

Get-Item : Cannot find path '\\nas01\personal$\folder1 folder2' because it does not exist.


All I need to do is list the folder owners and find out which folders have an owner of 'BUILTIN\Administrators. Below is the script I am trying to work on...

$HomeFolders = get-content 'C:\_PSScripts\FindFolderOwner\Folder.txt'

$Path =  "\\nas01\personal$\" + $HomeFolders

Foreach ($homefolder in $Path)
{

    Get-Item $Path | foreach-object {Get-Acl $_.Fullname}

    if ($homefolder -ne 'BUILTIN\Administrators')
    {
        $df = $Path

    }

}
0
Comment
Question by:CaussyR
2 Comments
 
LVL 5

Accepted Solution

by:
Recept earned 500 total points
ID: 39728008
If I've understood you correctly you want to identify all folders which are owned by the 'BUILTIN\Administrators' local group. This script will output the identified folders to a text file.

$HomeFolders = get-content 'C:\_PSScripts\FindFolderOwner\Folder.txt'
Foreach ($Folder in $HomeFolders)

{
    $Path =  "\\nas01\personal$\" + $Folder
    $owner = (Get-Acl $Path).owner
    if ($owner -eq 'BUILTIN\Administrators')
        {
        $path | Out-File .\ownedbyadministrator.txt -Append
        }

}

Open in new window

0
 

Author Closing Comment

by:CaussyR
ID: 39728101
Thanks PeterRecz, that's exactly what I wanted....
0

Featured Post

Do email signature updates give you a headache?

Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Join & Write a Comment

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now