PoshCode Logo PowerShell Code Repository

Audit NTFS on Shares by ission 17 months ago (modification of post by DigitalAsylum view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2125"></script>download | new post

Audit Folders/Shares and Export to Excel

  1. $Excel = New-Object -Com Excel.Application
  2. $Excel.visible = $True
  3. $Excel = $Excel.Workbooks.Add()
  4.  
  5. $wSheet = $Excel.Worksheets.Item(1)
  6. $wSheet.Cells.item(1,1) = "Folder Path:"
  7. $wSheet.Cells.Item(1,2) = "Users/Groups:"
  8. $wSheet.Cells.Item(1,3) = "Permissions:"
  9. $wSheet.Cells.Item(1,4) = "Permissions Inherited:"
  10.  
  11. $WorkBook = $wSheet.UsedRange
  12. $WorkBook.Interior.ColorIndex = 8
  13. $WorkBook.Font.ColorIndex = 11
  14. $WorkBook.Font.Bold = $True
  15.  
  16. ####Change the path to the folder or share you want NTFS perms on####
  17. $dirToAudit = Get-ChildItem -Path "c:\inetpub" -recurse | Where {$_.psIsContainer -eq $true}
  18.  
  19. $intRow = 1
  20. foreach ($dir in $dirToAudit)
  21. {
  22.         $colACL = Get-Acl -Path $dir.FullName
  23.  
  24.         foreach ($acl in $colACL)
  25.                 {
  26.                         $intRow++
  27.                         $wSheet.Cells.Item($intRow,1) = $dir.FullName
  28.                        
  29.                                 foreach ($accessRight in $acl.Access)
  30.                                         {
  31.                                                 $wSheet.Cells.Item($intRow,2) = "$($AccessRight.IdentityReference)"
  32.                                         $wSheet.Cells.Item($intRow,3) = "$($AccessRight.FileSystemRights)"
  33.                                                 $wSheet.Cells.Item($intRow,4) = $acl.AreAccessRulesProtected
  34.                                                 $intRow++
  35.                                         }
  36.                 }
  37.        
  38. }
  39. $WorkBook.EntireColumn.AutoFit()

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me