The following script helps you to:
- Import Active Directory groups and their descriptions from a CSV file;
- Create Active Directory Groups and add Description
- If the Group is flagged (Yes or No), it will be added to another group (e.g. User groups –> Application provisioning group)
Excel view:
AD Group Name | AD Group Description | Add to Group |
ROLE-G-APPLICATION-Users | Application Users | NO |
ROLE-G-APPLICATION-PowerUsers | Application Power Users | YES |
ROLE-G-APPLICATION-Administrators | Application Administrators | YES |
CSV file:
AD Group Name,AD Group Description,Add to Group ROLE-G-APPLICATION-Users,Application Users,NO ROLE-G-APPLICATION-PowerUsers,Application Power Users,YES ROLE-G-APPLICATION-Administrators,Application Administrators,YES
The script:
# Prompts you for Domain Admin like credentials $LoginPassword = Get-Credential # Imports groups and description list from CSV file $groups = Import-CSV "D:groups.csv" foreach ($item in $groups) { # Map variables from CSV $group = $item.'AD Group Name' $description = $item.'AD Group Description' # Creates Active Directory Group New-ADGroup –name $group –groupscope Global -Description $description –path “OU=Application,OU=Groups,DC=internal,DC=vstrong,DC=info” -Credential $LoginPassword # Adds newly created group to existing group if ($item.'Add to Group' -eq "YES") {Add-ADGroupMember APP-APPLICATION-Publish -Members $group -Credential $LoginPassword} }
I hope you will find this useful.
Recent Comments