Solved

List Folder Owners

Posted on 2013-12-18
2
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

697 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