Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. #=============================================passgenerator=====================================================================================================
  2. Function MakeUp-String([Int]$Size = 8, [Char[]]$CharSets = "ULNS", [Char[]]$Exclude) {
  3. $Chars = @(); $TokenSet = @()
  4. If (!$TokenSets) {$Global:TokenSets = @{
  5. U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  6. L = [Char[]]'abcdefghijklmnopqrstuvwxyz'
  7. N = [Char[]]'0123456789'
  8. S = [Char[]]'!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'
  9. }}
  10. $CharSets | ForEach {
  11. $Tokens = $TokenSets."$_" | ForEach {If ($Exclude -cNotContains $_) {$_}}
  12. If ($Tokens) {
  13. $TokensSet += $Tokens
  14. If ($_ -cle [Char]"Z") {$Chars += $Tokens | Get-Random} #Character sets defined in upper case are mandatory
  15. }
  16. }
  17. While ($Chars.Count -lt $Size) {$Chars += $TokensSet | Get-Random}
  18. ($Chars | Sort-Object {Get-Random}) -Join "" #Mix the (mandatory) characters and output string
  19. }; Set-Alias Create-Password MakeUp-String -Description "Generate a random string (password)"
  20. $randompassword = MakeUp-string
  21. $rndpass = $randompassword | Out-String
  22. $pass = ConvertTo-SecureString -string $rndpass -AsPlainText -Force
  23.  
  24.  
  25. #=============================================COLLECT DATA=========================================================================================================
  26. #$manager = read-Host ("manager")
  27. #copy properties from first direct report of manager:
  28. $copy_from = (Get-Aduser -Identity $manager -Properties directreports | Select-Object -ExpandProperty directreports | Get-Aduser -Properties Samaccountname | Select-Object -first 1 | Select-Object -ExpandProperty samaccountname)
  29. $olduser = get-aduser $copy_from -Properties *
  30. #$newuserfirstname = read-host ("First Name")
  31. #$newuserlastname = read-host ("Last Name")
  32. #$expdate = read-host ("Expiration Date dd.mm.rrrr")
  33.  
  34. #test
  35. $manager = "mtestowy"
  36. $newuserfirstname = "JOHN"
  37. $newuserlastname = "DOE"
  38. $expdate = "31.03.2019"
  39.  
  40.  
  41.  
  42.  
  43. $name = "$newuserlastname $newuserfirstname" #create username
  44. $samaccountname = "$($newuserfirstname[0])$newuserlastname" #create samaccountname
  45.  
  46. #todo: check if user exists
  47. #new user
  48. $params =@{
  49.  
  50. "AccountExpirationDate" = $expdate
  51. "SamAccountName" = $samaccountname
  52. "Department" = $olduser.department
  53. "AccountPassword" = $pass
  54. #"ChangePasswordAtLogon" = 'Enabled'
  55. "city" = $olduser.city
  56. "Company" = $olduser.company
  57. #"Description" = $olduser.description #nie działa
  58. "DisplayName" = $name
  59. #"Enabled" = 'Enabled'
  60. "GivenName" = $newuserfirstname
  61. "Manager" = $manager
  62. "Name" = $name
  63. "Office" =$olduser.office
  64. #"PasswordNeverExpires" = 'Disabled'
  65. #"Path" = $olduser.path #error
  66. "ScriptPath" = $olduser.scriptpath
  67. "StreetAddress" = $olduser.streetaddress
  68. "surname" = $newuserlastname
  69. "title" = $olduser.title
  70.  
  71. }
  72. #todo: memberof
  73. New-ADUser @params
  74. $ErrorActionPreference = "silentlycontinue"
  75. Set-ADUser -Identity $samaccountname -UserPrincipalName $samaccountname@vectradom.vec
  76. Set-Aduser -Identity $samaccountname -Replace @{office=$olduser.office; description=$olduser.description}
  77.  
  78.  
  79. #todo: home folder
  80. #todo: new email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement