我创建了一个脚本,以编制共享文件夹上的NTFS权限清单。该脚本几乎可以完成其所需的工作,除了在最后两个Excel列中放置“成员”及其特权。
如果您能帮助我完成脚本的最后一部分,那将是很棒的。我删除了所有可能泄露公司信息的代码(路径),因为与此无关。
在此先感谢您的帮助:-)
这是给我带来麻烦的部分:
Foreach ($Share in $Shares){
$excel.cells.item($i,3) = $Shares.Access.IdentityReference
$excel.cells.item($i,4) = $Shares.Access.FileSystemRights
$i++
}
Set-Culture -CultureInfo nl-NL
$Date = Get-Date -Format "dd-MM-yyyy"
If(Test-Path -Path "<removed>"){
}
Else{
New-Item -ItemType Directory -Path "<removed>"
}
$FileServer = '<removed>'
$FilePath = "<removed>"
$ErrorActionPreference= 'silentlycontinue'
$excel = New-Object -ComObject excel.application
$excel.visible = $True
$workbook = $excel.Workbooks.Add()
$Worksheet= $workbook.Worksheets.Item(1)
$Worksheet.Name = $Date
$Worksheet.Application.ActiveWindow.SplitRow = 1
$Worksheet.Application.ActiveWindow.FreezePanes = $true
$Worksheet.Cells.Item(1,1) = 'Folder'
$Worksheet.Cells.Item(1,2) = 'Owner'
$Worksheet.Cells.Item(1,3) = 'Member'
$Worksheet.Cells.Item(1,4) = 'Access Type'
$headerRange = $Worksheet.Range("A1","D1")
$headerRange.AutoFilter() | Out-Null
$Worksheet.Cells.Item(1,1).Font.Bold=$True
$Worksheet.Cells.Item(1,2).Font.Bold=$True
$Worksheet.Cells.Item(1,3).Font.Bold=$True
$Worksheet.Cells.Item(1,4).Font.Bold=$True
$Worksheet.Cells.Item(1,1).Interior.ColorIndex = 15
$Worksheet.Cells.Item(1,2).Interior.ColorIndex = 15
$Worksheet.Cells.Item(1,3).Interior.ColorIndex = 15
$Worksheet.Cells.Item(1,4).Interior.ColorIndex = 15
$Worksheet.Cells(1,1).HorizontalAlignment = -4108
$Worksheet.Cells(1,2).HorizontalAlignment = -4108
$Worksheet.Cells(1,3).HorizontalAlignment = -4108
$Worksheet.Cells(1,4).HorizontalAlignment = -4108
$Worksheet.Cells(1,1).VerticalAlignment = -4108
$Worksheet.Cells(1,2).VerticalAlignment = -4108
$Worksheet.Cells(1,3).VerticalAlignment = -4108
$Worksheet.Cells(1,4).VerticalAlignment = -4108
$i = 2
$Directories = @()
$Directories += Get-ChildItem -Depth 3 -Directory "\<removed>" | Select FullName
Foreach ($Directory in $Directories.FullName){
$Shares = @()
$Shares += Get-ChildItem -LiteralPath "$Directory" | Get-Acl
$excel.cells.item($i,1) = $Directory
$excel.cells.item($i,2) = $Share.Owner
Foreach ($Share in $Shares){
$excel.cells.item($i,3) = $Shares.Access.IdentityReference
$excel.cells.item($i,4) = $Shares.Access.FileSystemRights
$i++
}
$i++
}
$usedRange = $Worksheet.UsedRange
$usedRange.EntireColumn.AutoFit() | Out-Null
#$workbook.SaveAs($FilePath)
#$excel.Quit()