Adding a column to destinguish between user and group

Albert Edelstein 91 Reputation points
2021-11-04T16:28:40.4+00:00

The Following script generate a breakdown of access and inheritance (true.false)
I want to modify the script to add a column representing whether the access level is a user or a group?

$AllFolders = Get-ChildItem -Directory -Path "R:\" -Recurse -Force

$Results = @()
Foreach ($Folder in $AllFolders) {
$Acl = Get-Acl -Path $Folder.FullName
foreach ($Access in $acl.Access) {
if ($Access.IdentityReference -notlike "BUILTIN\Administrators" -and $Access.IdentityReference -notlike "domain\Domain Admins" -and $Access.IdentityReference -notlike "CREATOR OWNER" -and $access.IdentityReference -notlike "NT AUTHORITY\SYSTEM") {
$Access.IdentityReference
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group'=$Access.IdentityReference; 'NameIs'=$Access.Name; 'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Results += New-Object -TypeName PSObject -Property $Properties
}
}
}

$Results | Export-Csv -path "C:\Temp\ACL-Report.csv"

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,351 questions
{count} votes

Accepted answer
  1. Rich Matheisen 44,621 Reputation points
    2021-11-04T18:43:46.497+00:00

    Assuming the IdentityReference property refers only to Active Directory object, use Get-ADObject to retrieve the object and use either objectClass or objectCategory to determine what they are. You may want to use both, though. There are objects in the AD (like a computer account) that have an objectClass of "User" and an objectCategory of "Computer". If you need that level of distinction, it'd probably be better to report them both to avoid surprises.

    If, on the other hand, you have LOCAL users in the ACL then if you fail to find the object in the AD you have to use Get-LocalUser and Get-LocalGroup in addition to Get-ADObject to report the type.

    0 comments No comments

0 additional answers

Sort by: Most helpful