微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

For Dear 于

$a="C:\temp" #Root Folder
$L=0 #how many layers of subfolders you want to look into, 0 means only root folder. 
$p=@()

If ($L -gt 0)  #this loop is for being compatible to PS 2.0, in 3.0 above this are -Depth -Directory for Get-ChildItem to support.
{
    For ($i=0;$i -lt $L;$i++)
    {
        $s="\*"
        $a=$a+$s
        $p=$p+$a
    }
    $b=Get-ChildItem $p | ?{ $_.PSIsContainer } | select -ExpandProperty FullName
    $b=$b+$a
}
Else
{
    $p=$p+$a
    $b=Get-Item $p | ?{ $_.PSIsContainer } | select -ExpandProperty FullName
}

$b | % {
    $c=$_
    $UserName=$null
    (Get-Acl $_).Access | % {
        If ($_.IdentityReference -ilike "S-1-5-*")
        {
            $UserName=SID2Name($_.IdentityReference)
        }
        Else
        {
            $UserName=$_.IdentityReference
        }

        New-Object -TypeName PSobject -Property @{
            Path=$c
            IdentityReference=$UserName
            FileSystemRights=$_.FileSystemRights
            AccessControlType=$_.AccessControlType
        }
    }
} | Export-Csv ".\ACL.csv" -NoTypeinformation -Encoding UTF8

& ".\ACL.csv"

Function SID2Name ($SID)
{
    $objSID = New-Object System.Security.Principal.SecurityIdentifier($SID)
    Try
    {
        $objUser = $objSID.Translate([System.Security.Principal.NTAccount]) 
    }
    Catch
    {
        Return $SID
    }
    Return $objUser.Value
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐