【问题标题】:Check if user has Read/Write permissions检查用户是否具有读/写权限
【发布时间】:2016-04-23 21:42:21
【问题描述】:

我得到了用户域名\名称、密码和路径,我想显示给定用户在给定目录中是否具有写入或/和读取权限。

总体思路:

function Has-Read-Access {
    param(
        [Parameter(Mandatory=$true)][string]$userLogin
        [Parameter(Mandatory=$true)][string]$userPwd
        [Parameter(Mandatory=$true)][string]$directory
    )
    $hasReadAccess = 0
    #insert magic here
    return $hasReadAccess
}

Has-Read-Access -userLogin 'DOMAIN\user' -userPwd 'Passw0rd' -directory 'C:\FolderName\'

我已尝试由其他用户运行 powershell.exe

Start-Process powershell.exe -Credential "TestDomain\Me"

但这似乎是一种错误的方法。

【问题讨论】:

  • 请避免重新发布问题。通过将缺失的信息编辑到其中以使其重新打开/取消投票来改进您的 existing question。收集被否决的问题最终可能会导致问题被禁止。

标签: windows powershell file-permissions


【解决方案1】:

查看谁拥有有效文件夹使用权限的简单方法 (PowerShellAccessControl Module 3.0/4.0

还有一些类似的代码:

Get-Item $directory | Get-EffectiveAccess -Principal $UserName

要获取有权访问文件夹的用户列表,请使用 Get-ACL (TechNet Article)

Get-ACL $Directory

注意:您无需知道某人的密码即可获得他们的访问权限。

【讨论】:

  • 但是请注意,这可能使用了具有a number of limitations 的 GetEffectiveRightsFromAcl。 (没有用户凭据,没有任何全面的方法可以做到这一点。)
  • 顺便说一句,您可能需要某人的密码来确定他们的访问权限的原因是他们可能(直接或间接)属于您无权查看其成员资格的域组。
猜你喜欢
  • 2015-09-04
  • 2019-12-18
  • 2015-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-10
  • 2011-04-20
相关资源
最近更新 更多