Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -version 2
- # ==================================================================================================
- #
- # Microsoft PowerShell Source File
- #
- # NAME: List-Permissions v2.0
- #
- # AUTHOR: YellowOnline
- # DATE : 27/09/2011
- #
- # USAGE: List-Permissions.ps1 <local path or UNC>
- # ==================================================================================================
- ####################################################################################################
- # #region PARAMETERS
- Param([string]$ParamPath = $(Throw "ERROR: Parameter missing. Please provide a path or UNC."))
- If ($(Test-Path $ParamPath) -EQ $False) {Throw "ERROR: The provided path does not exist."}
- # #endregion
- # #region VARIABLES
- $ScriptVersion = "2.00"
- $ScriptPath = Split-Path -Parent $myInvocation.MyCommand.Definition
- $ScriptName = Split-Path -Leaf $myInvocation.MyCommand.Definition
- $LogFile = "$env:Public"+"\"+"YellowOnline\"+$($ScriptName.Replace(".ps1",""))+"\"+$($ScriptName.Replace(".ps1",""))+".log"
- $OutputFile = "$ScriptPath\List-Permissions.xlsx"
- $colOutput = @()
- # #endregion
- # #region FUNCTIONS
- Function Write-Log($LogMessage, $LogFile)
- {
- $LogPath = Split-Path -Path $LogFile -Parent
- $LogFile = Split-Path -Path $LogFile -Leaf
- $LogTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
- If (-NOT (Test-Path -Path $LogPath))
- {
- New-Item -Path $LogPath -ItemType Directory | Out-Null
- }
- If (-NOT (Test-Path -Path $LogPath/$LogFile))
- {
- New-Item -Path $LogPath/$LogFile -ItemType File | Out-Null
- }
- Write-Output "$LogTime $LogMessage" | Out-File -FilePath $LogPath/$LogFile -Append
- Write-Host "$LogTime $LogMessage"
- }
- Function Use-Culture ([System.Globalization.CultureInfo]$Culture,[ScriptBlock]$Script)
- {
- $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
- Trap
- {
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
- }
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $Culture
- Invoke-Command $Script
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
- }
- Function Get-Permissions ($InputPath)
- {
- #INPUT VALIDATION
- If ($($InputPath -Match "^\\\\[a-zA-Z0-9\.]+\\[a-zA-Z]\$\\") -EQ $True)
- {
- #Administrative share
- $ComputerName = $($InputPath.Split("\"))[2]
- $Win32_Shares = Get-WmiObject -Class Win32_Share -ComputerName $ComputerName
- $Win32_LogicalShareSecuritySettings = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $ComputerName
- $FolderPath = $($InputPath).Replace("$",":").Replace("$("\\"+$Computername+"\")","")
- }
- ElseIf ($($InputPath -Match "^[a-zA-Z]:\\") -EQ $True)
- {
- #Local Path
- $ComputerName = "."
- $Win32_Shares = Get-WmiObject -Class Win32_Share -ComputerName $ComputerName
- $Win32_LogicalShareSecuritySettings = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $ComputerName
- $FolderPath = $InputPath
- }
- ElseIf ($($InputPath -Match "^\\\\[a-zA-Z0-9\.]+\\") -EQ $True)
- {
- #Share
- $ComputerName = $($InputPath.Split("\"))[2]
- $Win32_Shares = Get-WmiObject -Class Win32_Share -ComputerName $ComputerName
- $Win32_LogicalShareSecuritySettings = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $ComputerName
- $FolderPath = $($Win32_Shares | Where-Object {$_.Path -EQ $($InputPath.Replace("$("\\"+$Computername+"\")",""))}).Name
- }
- Else
- {
- #Unknown
- Exit;
- }
- #NTFS
- $NTFSPermissions = @()
- $NTFSPermissions = Get-Acl $InputPath -ErrorAction SilentlyContinue | Select-Object Access
- $colNTFSPermissions = $NTFSPermissions.Access
- #SHARE
- $LocalShareName = $Win32_Shares | Where-Object {$_.Path -EQ $FolderPath}
- $colSharePermissions = @()
- If ($LocalShareName -NE $Null)
- {
- $ShareName = $Win32_LogicalShareSecuritySettings | Where-Object {$_.Name -EQ $LocalShareName.Name}
- $SecurityDescriptor = $ShareName.GetSecurityDescriptor()
- ForEach ($DACL in $SecurityDescriptor.Descriptor.DACL)
- {
- # #region Code from Hugo Peeters, http://www.peetersonline.nl/
- $objSharePermissions = "" | Select-Object Domain, ID, IdentityReference, AccessMask, AceType
- $objSharePermissions.Domain = $DACL.Trustee.Domain
- $objSharePermissions.ID = $DACL.Trustee.Name
- Switch ($DACL.AccessMask)
- {
- 2032127 {$AccessMask = "FullControl"}
- 1179785 {$AccessMask = "Read"}
- 1180063 {$AccessMask = "Read, Write"}
- 1179817 {$AccessMask = "ReadAndExecute"}
- -1610612736 {$AccessMask = "ReadAndExecuteExtended"}
- 1245631 {$AccessMask = "ReadAndExecute, Modify, Write"}
- 1180095 {$AccessMask = "ReadAndExecute, Write"}
- 268435456 {$AccessMask = "FullControl (Sub Only)"}
- Default {$AccessMask = $DACL.AccessMask}
- }
- $objSharePermissions.AccessMask = $AccessMask
- Switch ($DACL.AceType)
- {
- 0 {$AceType = "Allow"}
- 1 {$AceType = "Deny"}
- 2 {$AceType = "Audit"}
- }
- $objSharePermissions.AceType = $AceType
- # #endregion
- If ($objSharePermissions.Domain -EQ $Null)
- {
- $objSharePermissions.IdentityReference = $objSharePermissions.ID
- }
- Else
- {
- $objSharePermissions.IdentityReference = $objSharePermissions.Domain + "\" + $objSharePermissions.ID
- }
- $colSharePermissions += $objSharePermissions
- }
- }
- #MERGED
- $colPermissions = @()
- $colIdentities = @()
- ForEach ($objNTFSPermissions in $colNTFSPermissions)
- {
- $objPermissions = "" | Select-Object Path, Domain, ID, IdentityReference, FileSystemRights, AccessControlType, IsInherited, InheritanceFlags, PropagationFlags, AccessMask, AceType
- $objPermissions.Path = $InputPath
- Switch ($objNTFSPermissions.IdentityReference)
- {
- "Everyone" {$objPermissions.Domain = "";$objPermissions.ID = "Everyone"}
- "CREATOR OWNER" {$objPermissions.Domain = "";$objPermissions.ID = "CREATOR OWNER"}
- Default {$objPermissions.Domain = $($objNTFSPermissions.IdentityReference.Value.Split("\"))[0];$objPermissions.ID = $($objNTFSPermissions.IdentityReference.Value.Split("\"))[1]}
- }
- $objPermissions.IdentityReference = $objNTFSPermissions.IdentityReference
- $objPermissions.FileSystemRights = $objNTFSPermissions.FileSystemRights
- $objPermissions.AccessControlType = $objNTFSPermissions.AccessControlType
- $objPermissions.IsInherited = $objNTFSPermissions.IsInherited
- $objPermissions.InheritanceFlags = $objNTFSPermissions.InheritanceFlags
- $objPermissions.PropagationFlags = $objNTFSPermissions.PropagationFlags
- $objPermissions.AccessMask = $($colSharePermissions | Where-Object {$_.IdentityReference -EQ $objNTFSPermissions.IdentityReference}).AccessMask
- $objPermissions.AceType = $($colSharePermissions | Where-Object {$_.IdentityReference -EQ $objNTFSPermissions.IdentityReference}).AceType
- $colPermissions += $objPermissions
- $colIdentities += $objNTFSPermissions.IdentityReference
- }
- ForEach ($objSharePermissions in $colSharePermissions)
- {
- If ($colIdentities -NotContains $objSharePermissions.IdentityReference)
- {
- $objPermissions = "" | Select-Object Path, Domain, ID, IdentityReference, FileSystemRights, AccessControlType, IsInherited, InheritanceFlags, PropagationFlags, AccessMask, AceType
- $objPermissions.Path = $InputPath
- $objPermissions.Domain = $objSharePermissions.Domain
- $objPermissions.ID = $objSharePermissions.ID
- $objPermissions.IdentityReference = $objSharePermissions.IdentityReference
- $objPermissions.FileSystemRights = $Null
- $objPermissions.AccessControlType = $Null
- $objPermissions.IsInherited = $Null
- $objPermissions.InheritanceFlags = $Null
- $objPermissions.PropagationFlags = $Null
- $objPermissions.AccessMask = $objSharePermissions.AccessMask
- $objPermissions.AceType = $objSharePermissions.AceType
- $colPermissions += $objPermissions
- }
- }
- Return $colPermissions
- #EOF
- }
- Function Enumerate-Folders ()
- {
- Write-Log "Enumerating folders..." $LogFile
- $colFolders = @()
- Get-ChildItem $ParamPath -Recurse -ErrorAction SilentlyContinue| Where-Object {$_.PSisContainer -EQ $True}| ForEach-Object {$colFolders += $_.FullName}
- $colFolders += $ParamPath
- $colFolders = $colFolders | Sort-Object
- ForEach ($objFolders in $colFolders)
- {
- $script:colOutput += Get-Permissions $objFolders
- }
- Write-Log " Done!" $LogFile
- }
- Function Export-Excel ()
- {
- # #region CONSTANTS
- #Lines
- $xlAutomatic = -4105
- $xlBottom = -4107
- $xlCenter = -4108
- $xlContext = -5002
- $xlContinuous = 1
- $xlDiagonalDown = 5
- $xlDiagonalUp = 6
- $xlEdgeBottom = 9
- $xlEdgeLeft = 7
- $xlEdgeRight = 10
- $xlEdgeTop = 8
- $xlInsideHorizontal = 12
- $xlInsideVertical = 11
- $xlNone = -4142
- $xlAutomatic = -4105
- $xlThin = 2
- $xlMedium = -4138
- $xlThick = 4
- #VerticalAlignment
- $xlTop = -4160
- $xlCenter = -4108
- $xlBottom = -4107
- #HorizontalAlignment
- $xlLeft = -4131
- $xlCenter = -4108
- $xlRight = -4152
- # #endregion
- # #region INITIALIZATION
- Write-Log "Starting Excel..." $LogFile
- Try
- {
- $Excel = New-Object -ComObject Excel.Application
- $Workbook = $Excel.Workbooks.Add()
- $Excel.Visible = $False
- }
- Catch
- {
- Write-Log " ERROR: Could not start Excel! Error: $($error[0])" $LogFile
- Write-Log "Quitting." $LogFile
- Exit;
- }
- Write-Log " Done!" $LogFile
- # #endregion
- # #region GENERAL
- Write-Log "Creating worksheet GENERAL..." $LogFile
- $UserName = "$env:userdomain\$env:username"
- $Worksheet1 = $Workbook.Worksheets.Item(1)
- $Worksheet1.Name = "General"
- $Worksheet1.Columns.Item("A").ColumnWidth = 40
- $Worksheet1.Columns.Item("A").Font.Bold = $True
- $Worksheet1.Columns.Item("B").ColumnWidth = 15
- $Worksheet1.Columns.Item("B").Font.Bold = $True
- $Worksheet1.Columns.Item("C").ColumnWidth = 40
- $Worksheet1.Columns.Item("C").Font.Bold = $False
- $Worksheet1.Cells.Item(1,1) = "File Permission Report"
- $Worksheet1.Cells.Item(1,1).Font.Size = 20
- $Worksheet1.Cells.Item(5,2) = "Generated on:"
- $Worksheet1.Cells.Item(5,3) = "$(Get-Date -Format F)"
- $Worksheet1.Cells.Item(6,2) = "By:"
- $Worksheet1.Cells.Item(6,3) = "$UserName"
- $Worksheet1.Range("A1:C1").MergeCells = $True
- $Worksheet1.Range("A1:C1").BorderAround(1,4,1)
- $Worksheet1.Range("A1:C1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- Write-Log " Done!" $LogFile
- # #endregion
- # #region NTFS SIMPLIFIED
- # #region INIT
- Write-Log "Creating worksheet SIMPLIFIED..." $LogFile
- $Worksheet2 = $Workbook.Worksheets.Item(2)
- $Worksheet2.Name = "Simplified"
- # #endregion
- # #region DESIGN
- #Font
- $Worksheet2.Range("1:2").Font.Bold = $True
- #Width & Height
- $Worksheet2.Range("A:B").ColumnWidth = 45
- $Worksheet2.Range("C:C").ColumnWidth = 3
- $Worksheet2.Range("D:D").ColumnWidth = 25
- $Worksheet2.Range("E:E").ColumnWidth = 10
- $Worksheet2.Range("F:F").ColumnWidth = 3
- $Worksheet2.Range("G:G").ColumnWidth = 45
- $Worksheet2.Range("2:2").RowHeight = 125
- #Panes
- $Worksheet2.Select()
- $Worksheet2.Range("C3:C3").Select()
- $Excel.ActiveWindow.FreezePanes = $True
- #Lines
- $Worksheet2.Range("B:B").Borders.Item($xlEdgeLeft).LineStyle = $xlContinuous
- $Worksheet2.Range("B:B").Borders.Item($xlEdgeLeft).Color = 1
- $Worksheet2.Range("B:B").Borders.Item($xlEdgeLeft).Weight = $xlThin
- $Worksheet2.Range("E:E").Borders.Item($xlEdgeLeft).LineStyle = $xlContinuous
- $Worksheet2.Range("E:E").Borders.Item($xlEdgeLeft).Color = 1
- $Worksheet2.Range("E:E").Borders.Item($xlEdgeLeft).Weight = $xlThin
- $Worksheet2.Range("A:B").BorderAround(1,4,1)
- $Worksheet2.Range("D:E").BorderAround(1,4,1)
- $Worksheet2.Range("G:G").BorderAround(1,4,1)
- $Worksheet2.Range("A2:B2").Borders.Item($xlInsideVertical).LineStyle = $xlNone
- $Worksheet2.Range("A2:B2").BorderAround(1,4,1)
- $Worksheet2.Range("D2:E2").Borders.Item($xlInsideVertical).LineStyle = $xlNone
- $Worksheet2.Range("D2:E2").BorderAround(1,4,1)
- $Worksheet2.Range("G2:G2").BorderAround(1,4,1)
- #Colour
- $Worksheet2.Range("A1:B1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet2.Range("D1:E1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet2.Range("G1:G1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet2.Range("A2:B2").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet2.Range("D2:E2").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet2.Range("G2:G2").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- #Merging
- $Worksheet2.Range("A1:B1").MergeCells = $True
- $Worksheet2.Range("D1:E1").MergeCells = $True
- # #endregion
- # #region DATA
- $Row = 0
- $Row++
- $Worksheet2.Cells.Item($Row,1) = "System"
- $Worksheet2.Cells.Item($Row,4) = "Share"
- $Worksheet2.Cells.Item($Row,7) = "NTFS"
- $Row++
- $Worksheet2.Cells.Item($Row,1) = "Path"
- $Worksheet2.Cells.Item($Row,2) = "IdentityReference"
- $Worksheet2.Cells.Item($Row,4) = "AccessMask"
- $Worksheet2.Cells.Item($Row,5) = "AceType"
- $Worksheet2.Cells.Item($Row,7) = "FileSystemRights"
- $Row++
- ForEach ($objOutput in $colOutput)
- {
- $Worksheet2.Cells.Item($Row,1) = "$($objOutput.Path)"
- $Worksheet2.Cells.Item($Row,2) = "$($objOutput.IdentityReference)"
- $Worksheet2.Cells.Item($Row,4) = "$($objOutput.AccessMask)"
- $Worksheet2.Cells.Item($Row,5) = "$($objOutput.AceType)"
- $Worksheet2.Cells.Item($Row,7) = "$($objOutput.FileSystemRights)"
- $Row++
- }
- Write-Log " Done!" $LogFile
- # #endregion
- # #endregion
- # #region NTFS ADVANCED
- # #region INIT
- Write-Log "Creating worksheet ADVANCED..." $LogFile
- $Worksheet3 = $Workbook.Worksheets.Item(3)
- $Worksheet3.Name = "Advanced"
- # #endregion
- # #region DESIGN
- #Font
- $Worksheet3.Range("1:2").Font.Bold = $True
- #Width & Height
- $Worksheet3.Range("A:B").ColumnWidth = 45
- $Worksheet3.Range("C:C").ColumnWidth = 3
- $Worksheet3.Range("D:D").ColumnWidth = 25
- $Worksheet3.Range("E:E").ColumnWidth = 10
- $Worksheet3.Range("F:F").ColumnWidth = 3
- $Worksheet3.Range("G:G").ColumnWidth = 45
- $Worksheet3.Range("F:AL").ColumnWidth = 3
- $Worksheet3.Range("A:E").HorizontalAlignment = $xlLeft
- $Worksheet3.Range("2:2").RowHeight = 125
- $Worksheet3.Range("F2:AL2").Orientation = -90
- #Panes
- $Worksheet3.Select()
- $Worksheet3.Range("C3:C3").Select()
- $Excel.ActiveWindow.FreezePanes = $True
- #Lines
- $Worksheet3.Range("B:B").Borders.Item($xlEdgeLeft).LineStyle = $xlContinuous
- $Worksheet3.Range("B:B").Borders.Item($xlEdgeLeft).Color = 1
- $Worksheet3.Range("B:B").Borders.Item($xlEdgeLeft).Weight = $xlThin
- $Worksheet3.Range("E:E").Borders.Item($xlEdgeLeft).LineStyle = $xlContinuous
- $Worksheet3.Range("E:E").Borders.Item($xlEdgeLeft).Color = 1
- $Worksheet3.Range("E:E").Borders.Item($xlEdgeLeft).Weight = $xlThin
- $Worksheet3.Range("A:B").BorderAround(1,4,1)
- $Worksheet3.Range("D:E").BorderAround(1,4,1)
- $Worksheet3.Range("G:AL").BorderAround(1,4,1)
- $Worksheet3.Range("A2:B2").Borders.Item($xlInsideVertical).LineStyle = $xlNone
- $Worksheet3.Range("A2:B2").BorderAround(1,4,1)
- $Worksheet3.Range("D2:E2").Borders.Item($xlInsideVertical).LineStyle = $xlNone
- $Worksheet3.Range("D2:E2").BorderAround(1,4,1)
- $Worksheet3.Range("G2:AL2").BorderAround(1,4,1)
- #Colour
- $Worksheet3.Range("G:G").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("I:I").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("K:K").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("M:M").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("O:O").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("Q:Q").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("S:S").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("U:U").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("W:W").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("Y:Y").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AA:AA").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AC:AC").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AE:AE").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AG:AG").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AI:AI").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("AK:AK").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("A1:B1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("D1:E1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("G1:AL1").Interior.Color = 0x00538DD5 # RGB(83,141,213), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("A2:B2").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- $Worksheet3.Range("D2:E2").Interior.Color = 0x008DB4E2 # RGB (141,180,226), but not the proper colour. Excel messes up RGB.
- #Merging
- $Worksheet3.Range("A1:B1").MergeCells = $True
- $Worksheet3.Range("D1:E1").MergeCells = $True
- $Worksheet3.Range("G1:AL1").MergeCells = $True
- # #endregion
- # #region DATA
- $Row = 0
- $FolderIndex = 0
- $Row++
- $Worksheet3.Cells.Item($Row,1) = "System"
- $Worksheet3.Cells.Item($Row,4) = "Share"
- $Worksheet3.Cells.Item($Row,7) = "NTFS"
- $Row++
- $Worksheet3.Cells.Item($Row,1) = "Path"
- $Worksheet3.Cells.Item($Row,2) = "IdentityReference"
- $Worksheet3.Cells.Item($Row,3) = ""
- $Worksheet3.Cells.Item($Row,4) = "AccessMask"
- $Worksheet3.Cells.Item($Row,5) = "AceType"
- $Worksheet3.Cells.Item($Row,6) = ""
- $Worksheet3.Cells.Item($Row,7) = "GENERIC_READ"
- $Worksheet3.Cells.Item($Row,8) = "GENERIC_WRITE"
- $Worksheet3.Cells.Item($Row,9) = "GENERIC_EXECUTE"
- $Worksheet3.Cells.Item($Row,10) = "GENERIC_ALL"
- $Worksheet3.Cells.Item($Row,11) = "Reserved"
- $Worksheet3.Cells.Item($Row,12) = "Reserved"
- $Worksheet3.Cells.Item($Row,13) = "MAXIMUM_ALLOWED"
- $Worksheet3.Cells.Item($Row,14) = "READ_SETACL"
- $Worksheet3.Cells.Item($Row,15) = "Unused"
- $Worksheet3.Cells.Item($Row,16) = "Unused"
- $Worksheet3.Cells.Item($Row,17) = "Unused"
- $Worksheet3.Cells.Item($Row,18) = "SYNCHRONIZE"
- $Worksheet3.Cells.Item($Row,19) = "WRITE_OWNER"
- $Worksheet3.Cells.Item($Row,20) = "WRITE_DAC"
- $Worksheet3.Cells.Item($Row,21) = "READ_CONTROL"
- $Worksheet3.Cells.Item($Row,22) = "DELETE"
- $Worksheet3.Cells.Item($Row,23) = "Unused"
- $Worksheet3.Cells.Item($Row,24) = "Unused"
- $Worksheet3.Cells.Item($Row,25) = "Unused"
- $Worksheet3.Cells.Item($Row,26) = "Unused"
- $Worksheet3.Cells.Item($Row,27) = "Unused"
- $Worksheet3.Cells.Item($Row,28) = "Unused"
- $Worksheet3.Cells.Item($Row,29) = "Unused"
- $Worksheet3.Cells.Item($Row,30) = "FILE_WRITE_ATTRIBUTES"
- $Worksheet3.Cells.Item($Row,31) = "FILE_READ_ATTRIBUTES"
- $Worksheet3.Cells.Item($Row,32) = "FILE_DELETE_CHILD"
- $Worksheet3.Cells.Item($Row,33) = "FILE_EXECUTE"
- $Worksheet3.Cells.Item($Row,34) = "FILE_WRITE_EA"
- $Worksheet3.Cells.Item($Row,35) = "FILE_READ_EA"
- $Worksheet3.Cells.Item($Row,36) = "FILE_APPEND_DATA"
- $Worksheet3.Cells.Item($Row,37) = "FILE_WRITE_DATA"
- $Worksheet3.Cells.Item($Row,38) = "FILE_READ_DATA"
- $Row++
- ForEach ($objOutput in $colOutput)
- {
- $Columns = 38
- $BitsIndex = 1
- $Worksheet3.Cells.Item($Row,1) = "$($objOutput.Path)"
- $Worksheet3.Cells.Item($Row,2) = "$($objOutput.IdentityReference)"
- $Worksheet3.Cells.Item($Row,4) = "$($objOutput.AccessMask)"
- $Worksheet3.Cells.Item($Row,5) = "$($objOutput.AceType)"
- Do
- {
- [string]$Bits = [Convert]::ToString($($objOutput.FileSystemRights.value__), 2)
- If ($Bits[-$BitsIndex] -EQ "1") {$Worksheet3.Cells.Item($Row,$Columns) = "X"}
- $Columns--
- $BitsIndex++
- }
- While ($BitsIndex -NE 32)
- $Row++
- }
- Write-Log " Done!" $LogFile
- # #endregion
- # #region OUTPUT
- $Worksheet1.Select()
- Write-Log "Saving data to $OutputFile..." $LogFile
- $Workbook.SaveAs($OutputFile)
- Write-Log " Done!" $LogFile
- Write-Log "Quitting Excel..." $LogFile
- $Excel.Quit()
- Write-Log " Done!" $LogFile
- # #endregion
- }
- # #endregion
- # #region MAIN
- Write-Log "" $logFile
- Write-Log "============================================================" $logFile
- Write-Log "$env:userdomain\$env:username logged on from $env:computername." $logFile
- Write-Log "Running $ScriptName v$ScriptVersion from $ScriptPath" $logFile
- Write-Log "" $LogFile
- Use-Culture en-us {Enumerate-Folders;Export-Excel}
- #For debugging, run functions outside of Use-Culture on a US-EN configured system
- #When running through Use-Culture, any error will point simply to the Use-Culture function
- #When run on a non US-EN system without this function, Excel will fail due to bad internalization from Microsoft
- #Enumerate-Folders
- #Export-Excel
- Write-Log "" $logFile
- Write-Log "============================================================" $logFile
- # #endregion
- #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement