Server 2012 Powershell Check Members of a Group - windows

I have users and groups in the Users folder of a Windows 2012 Server. I want to check if a user is a member of a group and if not, add to the group. To list the members of a group, I've tried everything including:
get-adgroupmember -identity "cs99group"
which produces the error
get-adgroupmember : Cannot find an object with identity: 'cs99group' under: ...
The following works perfectly
get-adgroupmember -identity "Administrators"
Of course the Administrators group is in the Builtin folder and cs99group is in the Users folder. What am I doing wrong?

Can you try with the parameter -recursive added?
Does the command Get-AdGroup work?
If so, try Get-AdGroup "cs99group" | get-adgroupmember

Related

Powershell: Add "Domain Admins" Group to ALL Fileshares on Server

I am currently trying to add a group called "Domain Admins" to all fileshares, we have over 300. I would like to automate this so I don't have to do this manually for each one, and would then like to remove the local administrator group from each fileshare as well.
I currently am able to get all fileshares names and permissions of each one with:
$shares = Get-SmbShare
foreach($share in $shares) {
$share
(get-smbshare $share.Path)| select #{Label="Path"; Expression = { Convert-Path $_.Path }} -ExpandProperty Access
}
But I can't seem to find any resources that demonstrate how to add a group to all fileshares. I know how to add a group to a specific file share, but not all. If anyone can share some tips, that would be great!

Add a user to a domain group and set the user privileges to certain folder

I have a user in my workplace domain, I want to add him to a specific domain group then assign him some privileges on a specific folder.
I wonder how this can be done using command line or a more automated process than doing it step by step as I do this quite often.
I'm using AD on Windows 10
Looks like dsmod group can be used but I don't know how.
If I have a user with username userh01 in domain mydom how I can add him automatically to group mydomgroup1?
I've tried this command:
dsmod group "mydomgroup1" -addmbr "userh01"
but I get this error
dsmod failed:Value for 'Target object for this command' has incorrect format.
Any advice?
Maybe using powershell to add memeber to a domain group is an alternative way.
here below th script for example
Add-ADGroupMember -Identity "Groupmane" -Memebers "Username to add"
Add-ADGroupMember -Identity "mymdomgroup1" -Memebers "userh01"
ps:you may need to import active diretory modul. before using Add-ADGroupMeber parameter use this command 'Import-Module ActiveDirectory' at begining
for different syntax and detailed description to add-adgroupmember parameter follow this link
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee617210(v=technet.10)

Removing AD Group Membership (PowerShell)

I have a script for people who leave my organization. It basically creates a user backup folder and file before changing the password, removing the manager, backing up all member of groups, removing all group memberships, disabling the account and moving to different OU.
The part that i seem to be stuck on is the membership removals. This is what i have for that task:
Get-ADPrincipalGroupMembership -Identity "$Username" | % {Remove-ADPrincipalGroupMembership -Identity "$Username" -MemberOf $_}
This DOES work but I am prompted to confirm Yes or No to each group. When i add:
-confirm $false
at the end, none of the groups are removed. How can I get it to not ask for confirmation while still removing the groups?
Thank You!
This worked for me:
Get-ADPrincipalGroupMembership -Identity "$Username" | % {Remove-ADPrincipalGroupMembership -Identity "$Username" -MemberOf $_ -Confirm:$False}
No prompts and all of the removals worked just fine.
I wonder if there is a way to suppress the error message thrown up with respect to the user's Primary Group -- DomainMembers, in our case. I'm perfectly happy with the result (the command won't remove the user from his primary group, while the user is removed from all others), but the error message just looks ugly.`

import distribution group members into security group via PowerShell

Can anyone give me some guidance on what PowerShell command I can use to import all the members of a distribution group in Active Directory into a security group?
you could just use this (use your group names for "distributiongroup" and "securitygroup"):
Get-ADGroupMember -Identity distributiongroup | ForEach-Object { Add-ADGroupMember -Identity securitygroup -Members $_ }
Kind regards
To add to stephanb's answer, if you have nested groups under the distribution group you are attempting to copy from, you will need to add the -recursive parameter in order to pull in the users from those sub-groups.
Here is an example that worked for me:
Add-ADGroupMember -Identity 'securitygroup' -Members (Get-ADGroupMember -Identity 'distributiongroup' -Recursive)

How do I export Active Directory membership?

I am in an organization with thousands of users and some of them are not in the correct Active Directory group. I can access most of the groups through dsquery Rundll dsquery.dll OpenQueryWindow, but the way the groups are configured, it takes forever to check. Microsoft doesn't provide any information I've seen to export this to a text file or other source, but there must be a better way to get this information.
I assume you mean organizational unit (OU) instead of group.
Use PowerShell. You do need RSAT installed. Then you can run:
Import-Module ActiveDirectory
Get-ADUser -Filter * -SearchBase "ou=testou,dc=iammred,dc=net"
Change the OU to the OU you want to look at.
Or if you really did mean group:
Get-ADGroupMember -identity "GROUPNAME" -Recursive

Resources