如何检测指定账户拥有权限的文件夹

以下是使用 Windows PowerShell 和 ADManager Plus 获取账户可访问文件夹报告的比较。

VBScript

使用 VBScript 获取账户可访问文件夹的步骤:

  • 确定要从中检索报告的域。
  • 确定需要获取报告的 LDAP 属性。
  • 确定用于检索报告的主 DC。
  • 编写脚本。
  • 在命令提示符下执行它。
  • 将生成所需的报告

VBScript 脚本示例:

 已复制
strComputer = "." 
sParentFolder = InputBox("Please Enter folder to gather information on", "Parent Folder") 
sUserName = InputBox("Please enter the user name")
MsgBox sUserName
SParentFoldern=replace(sParentFolder,"\","") 
SParentFoldern=replace(sParentFoldern,":","") 
Set fso = CreateObject("Scripting.FileSystemObject") 
'File name Same As Folder Name without special Characters  
fullfilename=SParentFoldern&".html" 
'WScript.echo fullfilename 
Set fsOut = fso.OpenTextFile(fullfilename, ForAppending, True) 
On Error Resume Next 
fsOut.Writeline ("<html>"&vbCr&"<head>"&vbCr&"<title>File Permission For Folder under &"& SParentFoldern&"</title>"&vbCr&"</head>") 
strTableHead = "<table border=2 bordercolor='#000010' width='90%' id='Table1'>" 
fsOut.Writeline strTableHead 
fsOut.Writeline "<tr><td width='50%'>Folder</td>" & _ 
"<td width='50%'>User Name</td>"&_ 
"<td width='50%'>Permission</td></tr>" 
strTableFoot = "</table>" 
fsOut.Close 
ShowSubFolders FSO.GetFolder(sParentFolder),fullfilename 
OutputFolderInfo sParentFolder, fullfilename 
Set fsOut = fso.OpenTextFile(fullfilename, ForAppending, True) 
fsOut.Writeline strTableFoot  
fsOut.Close 
MsgBox "Done " 
WScript.Quit 
Public Sub OutputFolderInfo(FolderName , sOutfile) 
Const FullAccessMask = 2032127, ModifyAccessMask = 1245631, WriteAccessMask = 1180095 
Const ROAccessMask = 1179817 
Const ForReading = 1, ForWriting = 2, ForAppending = 8 
strComputer = "." 
'Build the path to the folder because it requites 2 backslashes 
folderpath = Replace(FolderName, "\", "\\") 
objectpath = "winmgmts:Win32_LogicalFileSecuritySetting.path='" & folderpath & "'" 
'Get the security set for the object 
Set wmiFileSecSetting = GetObject(objectpath) 
'verify that the get was successful 
RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor) 
If Err Then 
MsgBox ("GetSecurityDescriptor failed" & vbCrLf & Err.Number & vbCrLf & Err.Description) 
Err.Clear 
End If 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _ 
strComputer & "\root\cimv2") 
Set colFolders = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name ='" & _ 
folderpath & "'") 
For Each objFolder In colFolders 
' Retrieve the DACL array of Win32_ACE objects. 
DACL = wmiSecurityDescriptor.DACL 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set fsOut = fso.OpenTextFile(sOutfile, ForAppending, True) 
For Each wmiAce In DACL 
' Get Win32_Trustee object from ACE 
Set Trustee = wmiAce.Trustee 
If UCase(Trustee.Name) = UCase(sUserName) Then
fsOut.Writeline "<tr><td width='50%'>"&objFolder.Name&"</td>" & _ 
"<td width='50%'>"&Trustee.Domain&"\"&Trustee.Name&"</td>" 
'fsOut.Write objFolder.Name & "," & Trustee.Domain & "\" & Trustee.Name & "," 
FoundAccessMask = False 
CustomAccessMask = Flase 
While Not FoundAccessMask And Not CustomAccessMask 
If wmiAce.AccessMask = FullAccessMask Then 
AccessType = "Full Control" 
FoundAccessMask = True 
End If 
If wmiAce.AccessMask = ModifyAccessMask Then 
AccessType = "Modify" 
FoundAccessMask = True 
End If 
If wmiAce.AccessMask = WriteAccessMask Then 
AccessType = "Read/Write Control" 
FoundAccessMask = True 
End If 
If wmiAce.AccessMask = ROAccessMask Then 
AccessType = "Read Only" 
FoundAccessMask = True 
Else 
CustomAccessMask = True 
End If 
Wend 
If FoundAccessMask Then 
'fsOut.Writeline AccessType 
fsOut.Writeline "<td width='50%'>"&AccessType&"</td></tr>" 
Else 
fsOut.Writeline "<td width='50%'>Custom</td></tr>" 
'fsOut.Writeline "Custom" 
End If 
End If
Next 
Set fsOut = Nothing 
Set fso = Nothing 
Next 
Set fsOut = Nothing 
Set fso = Nothing 
end Sub 
Sub ShowSubFolders (Folder,fname) 
On Error Resume Next  
For Each Subfolder in Folder.SubFolders 
Call OutputFolderInfo(Subfolder.Path,fname) 
Wscript.Echo Subfolder.Path 
call ShowSubFolders (Subfolder,fname) 
Next 
End Sub
 
点击复制整个脚本

ADManager Plus

要获取报告,

  • 在 NTFS Permissions 报告中选择账户可访问的文件夹。
  • 选择域。选择首选账户,选择“Check For Folders in”字段中的计算机,可通过选中复选框或使用快速查找功能搜索计算机。点击生成。
  • 点击 Permissions 按钮查看共享权限和文件夹权限。

截图

 

» 开始 30 天免费试用

使用 Windows PowerShell 等本地工具获取账户可访问文件夹报告的限制如下:

  • 我们应提供准确的 ParentFolder 名称和 UserName。
  • 运行此脚本的用户应具有读取文件夹权限的权限。
  • 对于子文件夹,必须明确指定需要权限的层级数。
  • 使用此脚本,无法获取账户的自定义权限。
  • 需要进一步处理 DACL 以获取访问类型(Allow/ Deny)和适用范围字段。
  • 以其他格式获取报告存在困难。

ADManager Plus 提供通过选择 NTFS permissions report 中的“Folders Accessible by Accounts”选项获取用户共享和文件夹权限的功能。

通过专用报告全面控制 NTFS 权限和文件共享。

  获取 30 天免费试用。

开始您的 无脚本 AD 管理,报告和 自动化之旅 使用 ADManager Plus。

  •  
     
  • 提交即表示您同意根据 隐私政策 处理个人数据。

谢谢

您的下载将在 15 秒内自动开始。如未开始,点击此处手动下载。

相关 Powershell 操作指南:

Active Directory 管理和报告的一站式解决方案

电子邮件下载链接 Email the ADManager Plus download link