PoshCode Archive  Artifact [0373a9ade6]

Artifact 0373a9ade656ce1df60eaa86db02acd197e5e257f57dbbded05e7a519c3e5327:

  • File Audit-NTFS-on-Shares.ps1 — part of check-in [eb7c103e37] at 2018-06-10 13:05:26 on branch trunk — Audit Folders/Shares and Export to Excel (user: DigitalAsylum size: 1433)

# encoding: ascii
# api: powershell
# title: Audit NTFS on Shares
# description: Audit Folders/Shares and Export to Excel
# version: 0.1
# author: DigitalAsylum
# license: CC0
# x-poshcode-id: 2125
# x-archived: 2016-06-20T19:10:09
# x-published: 2011-09-08T19:53:00
#
#
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

$wSheet = $Excel.Worksheets.Item(1)
$wSheet.Cells.item(1,1) = "Folder Path:" 
$wSheet.Cells.Item(1,2) = "Users/Groups:"
$wSheet.Cells.Item(1,3) = "Permissions:"
$wSheet.Cells.Item(1,4) = "Permissions Inherited:"

$WorkBook = $wSheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

####Change the path to the folder or share you want NTFS perms on####
$dirToAudit = Get-ChildItem -Path "c:\inetpub" -recurse | Where {$_.psIsContainer -eq $true}

$intRow = 1
foreach ($dir in $dirToAudit)
{
	$colACL = Get-Acl -Path $dir.FullName

	foreach ($acl in $colACL)
		{
			$intRow++
			$wSheet.Cells.Item($intRow,1) = $dir.FullName
			
				foreach ($accessRight in $acl.Access)
					{
						$wSheet.Cells.Item($intRow,2) = "$($AccessRight.IdentityReference)"
				    	$wSheet.Cells.Item($intRow,3) = "$($AccessRight.FileSystemRights)"
						$wSheet.Cells.Item($intRow,4) = $acl.AreAccessRulesProtected
						$intRow++
					}
		}
	
}
$WorkBook.EntireColumn.AutoFit()