Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
  2. add-type -name win -member $t -namespace native
  3. [native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
  4.  
  5. Add-Type -AssemblyName System.Windows.Forms
  6.  
  7. $dir = "c:\ADUserCreator\"
  8. If(!(test-path $dir))
  9. {
  10. New-Item -ItemType Directory -Force -Path $dir
  11. }
  12.  
  13. #VZHLED FORMULARE
  14. $Form = New-Object system.Windows.Forms.Form
  15. $Form.Text = "AD User Creator"
  16. $Form.TopMost = $true
  17. $Form.Width = 312
  18. $Form.Height = 330
  19. $Form.KeyPreview = $True
  20. $Form.StartPosition = "CenterScreen"
  21.  
  22. $Maker = New-Object system.windows.Forms.Label
  23. $Maker.Text = "@Prihoda 2017"
  24. $Maker.AutoSize = $true
  25. $Maker.ForeColor = "#fffcfc"
  26. $Maker.Width = 25
  27. $Maker.Height = 10
  28. $Maker.Add_MouseHover({
  29. $Maker.ForeColor = "#000000"
  30. $Maker.Font = "Microsoft Sans Serif,10,style=Bold"
  31. })
  32. $Maker.location = new-object system.drawing.point(137,-25)
  33. $Maker.Font = "Microsoft Sans Serif,10"
  34. $Form.controls.Add($Maker)
  35.  
  36. $GivenName = New-Object system.windows.Forms.TextBox
  37. $GivenName.Width = 140
  38. $GivenName.Height = 20
  39. $GivenName.location = new-object system.drawing.point(145,10)
  40. $GivenName.Font = "Microsoft Sans Serif,10"
  41. $Form.controls.Add($GivenName)
  42.  
  43. $firstname = New-Object system.windows.Forms.Label
  44. $firstname.Text = "Křestní jméno"
  45. $firstname.AutoSize = $true
  46. $firstname.Width = 25
  47. $firstname.Height = 10
  48. $firstname.location = new-object system.drawing.point(13,10)
  49. $firstname.Font = "Microsoft Sans Serif,10"
  50. $Form.controls.Add($firstname)
  51.  
  52. $Surname = New-Object system.windows.Forms.TextBox
  53. $Surname.Width = 140
  54. $Surname.Height = 20
  55. $Surname.location = new-object system.drawing.point(145,35)
  56. $Surname.Font = "Microsoft Sans Serif,10"
  57. $Form.controls.Add($Surname)
  58.  
  59. $prijmeni = New-Object system.windows.Forms.Label
  60. $prijmeni.Text = "Příjmení"
  61. $prijmeni.AutoSize = $true
  62. $prijmeni.Width = 25
  63. $prijmeni.Height = 10
  64. $prijmeni.location = new-object system.drawing.point(13,35)
  65. $prijmeni.Font = "Microsoft Sans Serif,10"
  66. $Form.controls.Add($prijmeni)
  67.  
  68. $Name = New-Object system.windows.Forms.TextBox
  69. $Name.Width = 140
  70. $Name.Height = 20
  71. $Name.location = new-object system.drawing.point(145,60)
  72. $Name.Font = "Microsoft Sans Serif,10"
  73. $Form.controls.Add($Name)
  74.  
  75. $username = New-Object system.windows.Forms.Label
  76. $username.Text = "Uživatelské jméno"
  77. $username.AutoSize = $true
  78. $username.Width = 25
  79. $username.Height = 10
  80. $username.location = new-object system.drawing.point(13,60)
  81. $username.Font = "Microsoft Sans Serif,10"
  82. $Form.controls.Add($username)
  83.  
  84. $DisplayName = New-Object system.windows.Forms.TextBox
  85. $DisplayName.Text = "`"PRIJMENI Jmeno`""
  86. $DisplayName.Width = 140
  87. $DisplayName.Height = 20
  88. $DisplayName.location = new-object system.drawing.point(145,85)
  89. $DisplayName.Font = "Microsoft Sans Serif,10"
  90. $Form.controls.Add($DisplayName)
  91.  
  92. $displayedname = New-Object system.windows.Forms.Label
  93. $displayedname.Text = "Zobrazované jméno"
  94. $displayedname.AutoSize = $true
  95. $displayedname.Width = 25
  96. $displayedname.Height = 10
  97. $displayedname.location = new-object system.drawing.point(13,85)
  98. $displayedname.Font = "Microsoft Sans Serif,10"
  99. $Form.controls.Add($displayedname)
  100.  
  101. $OU = New-Object system.windows.Forms.TextBox
  102. $OU.Width = 140
  103. $OU.Height = 20
  104. $OU.location = new-object system.drawing.point(145,110)
  105. $OU.Font = "Microsoft Sans Serif,10"
  106. $Form.controls.Add($OU)
  107.  
  108. $department = New-Object system.windows.Forms.Label
  109. $department.Text = "Oddělení"
  110. $department.AutoSize = $true
  111. $department.Width = 25
  112. $department.Height = 10
  113. $department.location = new-object system.drawing.point(13,110)
  114. $department.Font = "Microsoft Sans Serif,10"
  115. $Form.controls.Add($department)
  116.  
  117. $Title = New-Object system.windows.Forms.TextBox
  118. $Title.Width = 140
  119. $Title.Height = 20
  120. $Title.location = new-object system.drawing.point(145,135)
  121. $Title.Font = "Microsoft Sans Serif,10"
  122. $Form.controls.Add($Title)
  123.  
  124. $funkce = New-Object system.windows.Forms.Label
  125. $funkce.Text = "Funkce"
  126. $funkce.AutoSize = $true
  127. $funkce.Width = 25
  128. $funkce.Height = 10
  129. $funkce.location = new-object system.drawing.point(13,135)
  130. $funkce.Font = "Microsoft Sans Serif,10"
  131. $Form.controls.Add($funkce)
  132.  
  133. $MailNickname = New-Object system.windows.Forms.TextBox
  134. $MailNickname.Text = "bez @daidometal.com"
  135. $MailNickname.Width = 140
  136. $MailNickname.Height = 20
  137. $MailNickname.location = new-object system.drawing.point(145,185)
  138. $MailNickname.Font = "Microsoft Sans Serif,9"
  139. $Form.controls.Add($MailNickname)
  140.  
  141. $Mailenabled1 = New-Object system.windows.Forms.Label
  142. $Mailenabled1.Text = "Povolit email"
  143. $Mailenabled1.AutoSize = $true
  144. $Mailenabled1.Width = 95
  145. $Mailenabled1.Height = 20
  146. $Mailenabled1.location = new-object system.drawing.point(13,160)
  147. $Mailenabled1.Font = "Microsoft Sans Serif,10"
  148. $Form.controls.Add($Mailenabled1)
  149.  
  150. $Mailenabled2 = New-Object system.windows.Forms.Checkbox
  151. $Mailenabled2.location = new-object system.drawing.point(145,160)
  152. $Form.controls.Add($Mailenabled2)
  153.  
  154. $mailname = New-Object system.windows.Forms.Label
  155. $mailname.Text = "Jméno emailu"
  156. $mailname.AutoSize = $true
  157. $mailname.Width = 25
  158. $mailname.Height = 10
  159. $mailname.location = new-object system.drawing.point(13,185)
  160. $mailname.Font = "Microsoft Sans Serif,10"
  161. $Form.controls.Add($mailname)
  162.  
  163. $enabled = New-Object system.windows.Forms.CheckBox
  164. $enabled.Text = "enable account"
  165. $enabled.Checked = $true
  166. $enabled.AutoSize = $true
  167. $enabled.Width = 95
  168. $enabled.Height = 20
  169. $enabled.location = new-object system.drawing.point(145,230)
  170. $enabled.Font = "Microsoft Sans Serif,10"
  171. $Form.controls.Add($enabled)
  172.  
  173. $label18 = New-Object system.windows.Forms.Label
  174. $label18.Text = "Heslo"
  175. $label18.AutoSize = $true
  176. $label18.Width = 25
  177. $label18.Height = 10
  178. $label18.location = new-object system.drawing.point(13,210)
  179. $label18.Font = "Microsoft Sans Serif,10"
  180. $Form.controls.Add($label18)
  181.  
  182. $Password = New-Object system.windows.Forms.TextBox
  183. $Password.Text = "Daidometal1"
  184. $Password.Width = 140
  185. $Password.Height = 20
  186. $Password.location = new-object system.drawing.point(145,210)
  187. $Password.Font = "Microsoft Sans Serif,8"
  188. $Form.controls.Add($Password)
  189.  
  190.  
  191.  
  192.  
  193. "GivenName,Surname,Name,DisplayName,OU,Title,Password" | OUT-FILE c:\ADUserCreator\info.txt -force
  194. "MailNickname" | OUT-FILE c:\ADUserCreator\mail.txt -force
  195.  
  196. $button3 = New-Object system.windows.Forms.Button
  197. $button3.BackColor = "#8ef2aa"
  198. $button3.Text = "Přidat"
  199. $button3.ForeColor = "#000000"
  200. $button3.Width = 90
  201. $button3.Height = 30
  202. $button3.location = new-object system.drawing.point(8,250)
  203. $button3.Font = "Microsoft Sans Serif,10,style=Bold"
  204. $Form.controls.Add($button3)
  205. #PO STISKNUTI TLACITKA ZKONTROLOVAT SE OTEVRE TXT SOUBOR S UDAJI, BUDE NAHRAZENO TLACITKEM "PRIDAT DALSI"
  206. $button3.Add_Click(
  207. {$GivenName.Text+","+$Surname.Text+","+$Name.Text+","+$DisplayName.Text+","+$OU.Text+","+$Title.Text+","+$Password.text| Out-File c:\ADUserCreator\info.txt -append
  208. $MailNickname.Text | OUT-FILE c:\ADUserCreator\mail.txt -append
  209. })
  210.  
  211. $button2 = New-Object system.windows.Forms.Button
  212. $button2.Text = "Check user name"
  213. $button2.ForeColor = "#000000"
  214. $button2.Width = 90
  215. $button2.Height = 30
  216. $button2.location = new-object system.drawing.point(103,250)
  217. $button2.Font = "Microsoft Sans Serif,6,style=Bold"
  218. $Form.controls.Add($button2)
  219. $button2.Add_Click({
  220. if (dsquery user -samid $Name.text){
  221. $button2.BackColor = "#ff0000"
  222. }
  223. else{
  224. $button2.BackColor = "#04ff00"};
  225. })
  226.  
  227. $button4 = New-Object system.windows.Forms.Button
  228. $button4.BackColor = "#ffbfbf"
  229. $button4.Text = "Vyčistit"
  230. $button4.Width = 90
  231. $button4.Height = 30
  232. $button4.location = new-object system.drawing.point(198,250)
  233. $button4.Font = "Microsoft Sans Serif,10,style=Bold"
  234. $Form.controls.Add($button4)
  235. $button4.Add_Click(
  236. {$GivenName.Clear();$Surname.Clear();$Name.Clear();$DisplayName.text ="`"PRIJMENI Jmeno`"";$OU.Clear();$Title.Clear();$MailNickname.text = "bez @daidometal.com";$Mailenabled2.Checked = $false;$enabled.Checked = $true; $Password.text = "Daidometal1"})
  237.  
  238. #ZMACKNUTI ESC ZAVRE FORMULAR
  239. $Form.Add_KeyDown({
  240. if($_.KeyCode -eq "Escape") {
  241. $form.Close()
  242. Stop-Process -name ADUserCreator.exe
  243. }
  244. #ZMACKNUTI ENTERU ULOZI UDAJE Z FORMULARE DO TXT SOUBORU
  245. if($_.KeyCode -eq "Return"){
  246. $GivenName.Text+","+$Surname.Text+","+$Name.Text+","+$DisplayName.Text+","+$OU.Text+","+$Title.Text+","+$Password.text| Out-File c:\ADUserCreator\info.txt -append -NoNewline
  247. }
  248. })
  249.  
  250. $button3.Add_Click({
  251. $path = import-csv "C:\ADUserCreator\info.txt"
  252. ForEach ($line in $path)
  253. {
  254. $GName = $line.GivenName
  255. $SName = $line.Surname
  256. $Nname = $line.Name
  257. $Dname = $line.DisplayName
  258. $OUnit = $line.OU
  259. $TTitle = $line.Title
  260. $Pass = ConvertTo-SecureString -AsPlainText $line.Password -force
  261. }
  262.  
  263. $cesta="OU="+$OUnit+",OU=GeneralUsers,OU=DMC,OU=EU,DC=global,DC=ad,DC=local"
  264. New-ADUser -name $Nname -SamAccountName $Nname -GivenName $Gname -Surname $Sname -DisplayName $Dname -AccountPassword $Pass -Path $Cesta -UserPrincipalName $Nname"@daidometal.com" -OtherAttributes @{'countryCode'="203";'postalCode'="60200";'l'="Brno";'c'="CZ";'company'="DMC";'st'="GLOBAL";'department'=$OUnit;'title'=$TTitle;'co'="Česká Republika";'streetAddress'="Švédské valy 6";} -PassThru | % {Add-ADGroupMember -Identity "DMCZ" -Members $_;Add-ADGroupMember -Identity "GISA006" -Members $_};
  265. If ($enabled.Checked -eq $true)
  266. {
  267. Enable-ADAccount -Identity $Nname
  268. }
  269.  
  270.  
  271. $path2 = import-csv "C:\ADUserCreator\mail.txt"
  272. ForEach ($line1 in $path2)
  273. {$MNickname = $line1.MailNickname}
  274. $Mmail=$MNickname+"@daidomatel.com"
  275. If ($Mailenabled2.Checked -eq $true)
  276. {Set-ADUser -Identity $Nname -add @{'mail'=$Mmail;'mailNickname'=$MNickname;'proxyAddresses'="SMTP:"+$Mmail;}}
  277. })
  278. [void]$Form.ShowDialog()
  279. $Form.Dispose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement