Difference between revisions of "Files and Folders (PowerShell)"

From vwiki
Jump to navigation Jump to search
(Initial creation)
 
m (Added Get-Acl)
 
Line 1: Line 1:
== <code> Get-Acl </code> ==
=== Troubleshooting ===
* '''Set-Acl : The security identifier is not allowed to be the owner of this object.'''
** Normally caused by the owner no longer having rights over the object in the new ACL despite still being the owner.  Either change the owner of the object before attempting to apply the new ACL, or add the current owner into the new ACL.
== Directory Walker ==
== Directory Walker ==
A basic recursive function to walk through a directory tree
A basic recursive function to walk through a directory tree

Latest revision as of 21:19, 24 April 2013

Get-Acl

Troubleshooting

  • Set-Acl : The security identifier is not allowed to be the owner of this object.
    • Normally caused by the owner no longer having rights over the object in the new ACL despite still being the owner. Either change the owner of the object before attempting to apply the new ACL, or add the current owner into the new ACL.

Directory Walker

A basic recursive function to walk through a directory tree

function Walk-Directory ($path = $pwd) {
    # Get files/folders in current path
    $items = Get-ChildItem $path

    # Go through each file/folder in current path
    foreach ($item in $items) {
        if ($item.Attributes -contains "Directory") {
            # Do something to every folder here (if you need to)
            Walk-Directory $item.FullName          # Drill down into directory 
        }
        # Do something to every file here (if you need to)
        $item.FullName
    }
}

Walk-Directory "C:\Intel"