简体   繁体   English

具有Powershell文件夹的过时ACL

[英]outdated ACL on folders with powershell

I use Powershell to pull in data about user accounts, some of which includes details about an user's home folder. 我使用Powershell提取有关用户帐户的数据,其中一些数据包含有关用户主文件夹的详细信息。

I have been using get-item on folders to get the ACL to make sure an user has proper access to their home folder. 我一直在文件夹上使用get-item来获取ACL,以确保用户可以正确访问其主文件夹。 An example of my code is: 我的代码示例是:

((get-item C:\exampleFolder).GetAccessControl('access')).Access

This provided me the list I needed and works great. 这为我提供了所需的列表,效果很好。 However, if an user's username changes, it can take some time (like 5- 10 minutes) before Powershell can see the change even though viewing the folder's properties reflects the changes nearly instantaneously. 但是,如果用户的用户名更改了,即使查看文件夹的属性几乎立即反映了更改,Powershell仍需要一些时间(例如5至10分钟)才能看到更改。

I am just seeing if there is a better way to pull the ACL data so that what I see in folder property page is what Powershell gets. 我只是在查看是否有更好的方法来提取ACL数据,这样我在文件夹属性页中看到的就是Powershell所得到的。

first world issue for me really, just trying to make my code a little bit more efficient. 确实对我来说是第一世界的问题,只是试图使我的代码更有效率。

Edit: This is a change in a username on a domain though Active Directory, not a username on a local machine. 编辑:这是通过Active Directory在域中的用户名上的更改,而不是本地计算机上的用户名。

There is the Get-ACL Cmdlet. Get-ACL Cmdlet。 This will output an object with an Access property listing all users with Access and their Access Level. 这将输出一个具有Access属性的对象,该对象列出了所有具有Access及其访问权限的用户。

If you want to, you could use this to make a function to get more explicit data like this: 如果需要,可以使用此函数创建一个函数来获取更明确的数据,如下所示:

  function Get-Permissions ($folder) {
  (get-acl $folder).access | select `
        @{Label="Identity";Expression={$_.IdentityReference}}, `
        @{Label="Right";Expression={$_.FileSystemRights}}, `
        @{Label="Access";Expression={$_.AccessControlType}}, `
        @{Label="Inherited";Expression={$_.IsInherited}}, `
        @{Label="Inheritance Flags";Expression={$_.InheritanceFlags}}, `
        @{Label="Propagation Flags";Expression={$_.PropagationFlags}}
        }

This you could easily pipe on to a | Format-Table -Auto 您可以轻松地将其传送到| Format-Table -Auto | Format-Table -Auto or however you wish to visually consume your output. | Format-Table -Auto或者您希望在视觉上使用输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM