Skip to content

Instantly share code, notes, and snippets.

@RhysC
Created November 17, 2016 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RhysC/2b899333d622b2d91798269407960b19 to your computer and use it in GitHub Desktop.
Save RhysC/2b899333d622b2d91798269407960b19 to your computer and use it in GitHub Desktop.
Active directory snippets
# opens a GUI to manage users under the given account - fine for adding/upodate one or two accounts
runas /user:myDomain\myusername "C:\Windows\System32\rundll32.exe dsquery, OpenQueryWindow"
##POWERSHELL – to load the users, done from a server so it has the AD PS modules
import-module activedirectory
# basic search using ps filters
Get-ADUser -filter {GivenName -like "rickie"}
# get all the users in a group in normal looking string
Get-ADGroupMember Role-Department-Application-Admin | %{ Get-ADUser -Identity $_ } | %{ $_.GivenName + " " + $_.Surname}
##START – Bulk load the users
$userCsv = "C:\Users\myprofile\Documents\My_app_users.csv"
$adminCsv = "C:\Users\myprofile\Documents\My_app_admin.csv"
Import-Csv $userCsv | % {
Add-ADGroupMember -Identity Role-Department-Application-User -members $_.Username
}
Import-Csv $adminCsv | % {
Add-ADGroupMember -Identity Role-Department-Application-Admin -members $_.Username
}
#SHOW USERS IN GROUPS
get-adgroupmember -Identity "Role-Department-Application-User"
get-adgroupmember -Identity "Role-Department-Application-Admin"
##END – Bulk load the users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment