Skip to content

Instantly share code, notes, and snippets.

@altrive
Created November 18, 2014 14:07
Show Gist options
  • Save altrive/ce37defb03aa4a98d438 to your computer and use it in GitHub Desktop.
Save altrive/ce37defb03aa4a98d438 to your computer and use it in GitHub Desktop.
$templates = @'
権限 :{0}
グループ名: {1}
含まれているユーザー:
{2}
'@
Add-Type -AssemblyName System.DirectoryServices
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$results = New-Object System.Collections.Generic.List[object]
Get-ChildItem -Path \\localhost\Shared -Directory | foreach {
$path = $_.FullName
$acl = Get-acl $_.FullName
$accessControls = $acl.Access
$ctx = New-Object DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine, "alt-PC");
$sb = New-Object Text.StringBuilder
foreach ($item in $accessControls)
{
Write-Host $item.IdentityReference
#$AccessControlType #
$identity = $item.IdentityReference
$sid = $identity.Translate([System.Security.Principal.SecurityIdentifier])
try {
$grp = [DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($ctx, [DirectoryServices.AccountManagement.IdentityType]::SamAccountName, $identity.Value);
$users = $grp.GetMembers()
$users = [String]::Join(",", $users.SamAccountName)
$isGroup = $true
} catch {
$users = $identity.Value
$isGroup = $false
}
$rights = $item.FileSystemRights
$rights = [Enum]::ToObject([System.Security.AccessControl.FileSystemRights], $rights)
$rigths = [String]::Join("'", $rights)
$sb.AppendLine($content) > $null
$content = $templates -f $rights, $users, $identity
$result = [pscustomobject] @{
Path = $path
Users = $users
Rights = $rights
}
$results.Add($result)
}
#return $result
$sb.ToString() | Out-File -FilePath (Join-Path $path "report.txt")
}
$results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment