Backstory: I set out to create a script that will get the acls from a specified shared folder and do the following.
- Identify subfolders
- Get ACLs for the folder (recursively)
- Parse any security groups out into individual users
- Output report to CSV with info.
<hr />
Get-ADGroupMember : Cannot bind parameter 'Identity'. Cannot convert the "MCMCG\Domain Admins" value of type "System.Security.Principal.NTAccount" to type "Microsoft.ActiveDirectory.Management.ADGroup".
At C:\Scripts\FileShareAudit\GetFolderACLUsers.ps1:14 char:60
+ $GroupMember = Get-ADGroupMember -Identity $Group
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember
Below is my script, with the path omitted for obvious reasons.
#Import the Active Directory moduleImport-Module ActiveDirectory
#Get all subfolders from the folder path.
$FolderPath = Get-ChildItem -Directory -Path "\server\share" -Recurse -Force
$Output = @()
#Gets the users and groups with access to the folder and subfolders
ForEach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName ForEach ($Access in $Acl.Access) { #Assigns Group Names to variable $Groups = $Access.IdentityReference ForEach ($Group in $Groups){ #Parses group members from security group $GroupMember = Get-ADGroupMember -Identity $Group #Prints out names of group members on screen to confirm this is working Write-Host $GroupMember #Assigns properties to the spreadsheet output and lists variables they're to be pulled from $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$GroupMember;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}$Output += New-Object -TypeName PSObject -Property $Properties
}
}
}
#Take properties complied for output and export to CSV
$Output | Export-CSV -Path C:\Temp\FolderACLs.csv