Last active
August 29, 2015 14:14
-
-
Save derak/233353627ded0a749f41 to your computer and use it in GitHub Desktop.
shit for windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Open Active Directory Module for Windows PowerShell in Administrative Tools and type the following command. | |
| Get-ADGroupMember -Identity GROUP-A | Add-ADPrincipalGroupMembership -MemberOf GROUP-B | |
| # Get-ADGroupMember gets all the members of GROUP-A and pipes into Add-ADPrincipalGroupMembership cmdlet that added the incoming members to GROUP-B. | |
| # count members | |
| (Get-ADGroupMember -Identity “GROUPNAME”).count | |
| # print group members | |
| Get-ADGroupMember -identity “Name of Group” | select name | Export-csv -path C:\Output\Groupmembers.csv -NoTypeInformation | |
| (you can replace name with any attribute ie. samaccountname | |
| #Purpose – Add users to a group from an input file – PowerShell V2 Script. | |
| # | |
| #Input file – Input file (Users.csv) contains samAccountName in the following format: | |
| # | |
| # Add User to a Group - PowerShell Script | |
| # | |
| #Purpose – Add users to a group from an input file – PowerShell V2 Script. | |
| # | |
| #Input file – Input file (Users.csv) contains samAccountName in the following format: | |
| # | |
| # Add User to a Group - PowerShell Script | |
| # | |
| Import-Module ActiveDirectory | |
| $adGroup = "GroupName" | |
| Import-Csv "C:\Users\administrator.AD\Desktop\CSVName.csv" | ForEach-Object { | |
| $samAccountName = $_."samAccountName" | |
| Add-ADGroupMember $adGroup $samAccountName; | |
| Write-Host "- "$samAccountName" added to "$adGroup | |
| } | |
| ## | |
| ## | |
| ## You may need to set execution policy | |
| #http://blogs.technet.com/b/heyscriptingguy/archive/2009/04/27/how-can-i-write-and-run-a-windows-powershell-script.aspx | |
| ##################### | |
| # Through the regular command shell | |
| # print members | |
| net group "GroupName" /domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment