Permissions report for AD groups - powershell

I am trying to get a table of permissions out of some groups that I have in AD. I'm pretty new to PowerShell and I'm not sure what I want is even possible.
So far I've been able to select the groups that I want by using
Get-ADUser -Identity groupname
And I can see the info pulled up in the response from PowerShell, but from there I've hit a huge dead-end with piping the result into anything that would let me see the permissions for that group.

I'm assuming you want the permissions to the group itself (for example, who is allowed to modify the group).
You can use Get-Acl (ACL stands for Access-Control List), which is used for getting permissions from files as well. To direct it to AD, you use the AD: drive, along with the distinguished name of the AD object. For example:
(Get-Acl "AD:CN=SomeGroup,OU=Groups,DC=example,DC=com").Access
If you don't know the distinguished name, you can get that from your call to Get-ADGroup (I assume you meant to use Get-ADGroup, not Get-ADUser like you put in your question).
$group = Get-ADGroup groupname
(Get-Acl "AD:$($group.distinguishedName)").Access
More reading here: Understanding Get-ACL and AD Drive Output

Related

Finding secondary Owners of Security groups using ADSI Searcher

I am trying to find all owners and secondary owners of security groups within my environment
Could someone please advise me on how i could amend my option 1 command to include secondary owners?
Or any other command that i can use ADSI searcher for to get this information
Thanks,
Ryan
I have tried tackling this 2 ways:
find the specific user I am after and reporting back on any groups this person is an owner of - using the below
Distinguished Name of the user
$DN = "CN=***"
Retrieve the groups managed by this user
$groups = ([ADSISearcher]"(&(objectCategory=group)(ManagedBy=$DN))").findall()
foreach ($group in $groups)
{
$group.properties.samaccountname | out-file C:\users\...
}
this works to an extent but does not return any groups that the user is a secondary owner of.
The second way I am doing this is also looking at the specific groups that i know have multiple owners and trying to report back the necessary property for the secondary owner but having no luck

Retrieving SamAccountName and associated groups in a formatted csv

I'm trying to retrieve a list of all Ad users matching a filter, pipe that into Get-ADPrincipalGroupMembership and then export the result to an easy to read CSV.
*NB I can't use MemberOf as it returns blank for every single Ad user, and most successful scripts I've found are using MemberOf.
Here's what I've tried which gives me a list of groups but no association as to who goes where. Tried to export-csv as well but it complains of an empty pipe?
import-module activedirectory
foreach ($user in (Get-AdUser -Filter {(Name -Like "*(s)") } | select samaccountName)) {
Get-ADPrincipalGroupMembership $user.samaccountName | select samaccountname,name
}
This will include the user's sAMAccountName in the group results:
Import-Module ActiveDirectory
ForEach ($user in (Get-AdUser -Filter {(Name -Like "*(s)") } | select sAMAccountName)) {
Get-ADPrincipalGroupMembership $user.sAMAccountName| select #{Expression={$user.sAMAccountName};Label="User"},sAMAccountName,name
}
That weird notation is for creating a custom table. You can read more about it here: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ee692794(v=technet.10)
Not seeing anything in memberOf may be normal. If you check in Users and Computers, do you see a value in memberOf?
The memberOf attribute will only show groups with a Universal scope in the same AD forest, Global groups on the same domain, or Domain Local groups on the same domain of the server you're reading from (which may not be the same domain as the user). So it has its limitations.
Users can also be "a member" of a group by the primaryGroupId attribute, which stores the RID (the last section of the SID) of the user's primary group. This is usually only used for the Domain Users group.
Get-ADPrincipalGroupMembership takes care of all of that for you. It will include the primary group and search every domain in your forest for Global and Domain Local groups that have the user as a member.

Why won't powershell recognize Active Directory group?

I use a simple Get-ADGroup on this top level of our networks Active Directory and I get back the error "get-adgroup : cannot find an object with identity 'GroupName' under: Domain
I have tried to query the group using "Find" in Active Directory Users and Computers and it is only able to be found if set to search for Organizational Units, however if I try a Get-ADOrganizationalUnit with the name of the OU nothing will populate.
Most of the time, the group name you see from your front-end is not actually what the group name is in ActiveDirectory.
I suggest you install Active Directory Users and Computers
Query the group based on the current group name you think it is.
Open the properties and see what the actual group name is.
The fact that Get-AdGroup returned that error means you have the wrong group name.
For Get-ADGroup you have to use the objects GUID or the DistinguishedName. What I typically do with this is something like this:
Get-DistributionGroup -identity "GroupName" | select -Expand DistinguishedName | Get-ADGroup

Expand an AD group inside a collection

I am creating a script that should check the file server for shares, and should list user's that have any kind of access control type (allow / deny) and their rights on the share. I've successfully managed to create collection of objects that have data that I want, but I have issues formatting them in the way I want.
Current situation, how the collection looks like
Path Identity Access Rights
Share1 User1 Allow Full Control
Share1 Group1 Allow Full Control
Share2 Group1 Deny Full Control
Share2 Group2 Allow Modify
I am fine with having shares appear in multiple objects, with one identity (user or a group) per object, but I would like to expand groups with its members, when the $_.Identity in pipe is a group. But I have issues getting there
My code example is practically non existing, I just tried to check every object in the pipe if it's Identity can be used with Get-ADGroupMember but that's it
$Collection | ForEachObject { if (Get-ADGroupMember $_.Identity) {Get-ADGroupMember $_.Identity }} ...
Desired solution should be like this:
Path Identity Access Rights
Share1 User1 Allow Full Control
Share1 User1,User2 Allow Full Control
Share2 User1,User2 Deny Full Control
Share2 User2,User3 Allow Modify
In this test example, Group1 is consisted of User1 and User2, while Group2 is consisted of User2 and User3.
Any help is appreciated.
I think what I would do is to generate the value on the pipeline like this:
$Collection | Select Path,#{l='Identity';e={ if (Get-ADGroupMember $_.Identity) {(Get-ADGroupMember $_.Identity) -join ", "}else{$_.Identity}}},Access,Rights
I was working on a very similar script. Rather than bore you with my code, here's where I found assistance in sorting out the nested groups.
Sort Nested Groups
Basically, you create a function to get all the group members and then test each item. If it is a group, call the same function and pass it the newly found group name.
Regarding:
$_.identity
I used
$_.objectclass
That will tell you if the get-adgroupmember result is a user or group. It will error on users, but I just suppress the errors at runtime with
$erroractionpreference = "silentlycontinue"
That's probably not best practice, but it works for me.
I tested this with circular nesting and it does not get stuck in an infinite loop. It actually handled it perfectly by returning the individual results only once. Probably has to do with safeguards built into windows for cirucular nesting situations.
Some of the info here might be helpful as well:
Circular Nesting Consequences - ServerFault

How to display list Active Directory users that arent in specific AD Groups

I have a requirment to create a report/text file that displays the users that arent in specific AD groups. I know displaying users that are in specific AD groups is easy enough with Powershell.
Surely its possible to display the users that ARENT in specific AD groups with powershell also ??
One approach:
Export all users
Export users that are members of that specific group
Do excel work to find out users that aren't members
However, if the task is to perform it with powershell only, you have to do your research how to perform those steps without excel.
Export a list of all users 'cn' in your active directory to a text file
Get-ADUser | Select-Object sAMAccountname > c:\temp\directory list
Depending on group sizes .netFramework has issues with groups with a large number of members (1500+) use 'dsget' to get a list of members in the group and store these into a variable
$groupName = dsget group "groupname" -members
compose foreach statement
if you need the actual code syntax -
http://stackoverflow.com/questions/22145586/powershell-compare-csv-to-ad