1

I'm trying to get The Folder Info and Security Info for all the folders on our server. But I'm not to familiar with Powershell here. Mind helping a newbie?

How to do I get the Security acl piped into the Text file? Along with just the member objects of Folder Name, Size, sub folder count?

# Step 1 Get Folder Path 
function Select-Folder($message='Select a folder', $path = 0) { 
    $object = New-Object -comObject Shell.Application  

    $folder = $object.BrowseForFolder(0, $message, 0, $path) 
    if ($folder -ne $null) { 
        $folder.self.Path 
    } 
} 


#Step 2:Search For Directories
$dirToAudit = Get-ChildItem -Path (Select-Folder  'Select some folder!') -recurse | Where {$_.psIsContainer -eq $true}

foreach ($dir in $dirToAudit)
{

#Step 3: Output: [Folder Path, Name, Security Owner, Size, Folder Count]
#Pipe To CSV Text File
    Get-Acl -Path $dir.FullName | Select-Object PSPath, Path,Owner | export-csv C:\temp\SecurityData.csv
    #I also want the Folder path, Size and SubFolder Count
}


#Step 4: Open in Excel 
invoke-item -path C:\temp\SecurityData.csv

Here's some sites that I found useful on the subject: http://blogs.msdn.com/b/powershell/archive/2007/03/07/why-can-t-i-pipe-format-table-to-export-csv-and-get-something-useful.aspx

http://www.maxtblog.com/2010/09/to-use-psobject-add-member-or-not/

1 Answer 1

2

This task isn't particularly easy. First you will want to create a custom object that contains the properties you want. These properties will be added via different commands e.g.:

$objs = Get-ChildItem . -r | 
            Where {$_.PSIsContainer} | 
            Foreach {new-object psobject -prop @{Path=$_.FullName;Name=$_.Name;FolderCount=$_.GetDirectories().Length}}
$objs = $objs | Foreach { Add-Member NoteProperty Owner ((Get-Acl $_.Path).Owner) -Inp $_ -PassThru}

$objs | Export-Csv C:\temp\data.csv

Getting the folder size will take some extra work to compute.

Sign up to request clarification or add additional context in comments.

2 Comments

So is the PSobject a Hash Table data type then?
PSObject can be used to create custom objects i.e. where you can add properties and methods to the object. You could also think of it as a way of creating a record or struct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.