IsraelTorres

addADUser.ps1

Mar 15th, 2012
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Israel Torres
  2. # 2012-03-14
  3. # adds an AD User to a security group
  4. Import-Module ActiveDirectory
  5. #
  6. # args: username, security group
  7. if($args.Length -eq 2){
  8. $username = $args[0]
  9. $secgroup = $args[1]
  10.     if (!(Get-ADUser -filter {SamAccountName -eq $username})) {
  11.             Write-Host "User: $username does not exist; run .\CreateADUser.ps1 username password."        
  12.     }else{
  13.             Write-Host "Adding User:$username to $secgroup"
  14.             Add-ADGroupMember $secgroup $username
  15.     }
  16. }else{
  17.     Write-Host "Usage: .\addADUser.ps1 username securitygroup"
  18. }
  19. #EOF
RAW Paste Data