Advertisement
lutherinbmore

FreeCompmaggus v. 1.0

Jun 17th, 2015
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Name: FreeCompmaggus v. 1.0
  2. #Description: Utility for creating an arbitrary number of domain joinable Active Directory computer objects in a designated container.
  3. #Update History:
  4. #1.0- Original release. 06/17/15
  5. #Copyright 2015, Luther Clark Jr. (lutherinbmore@gmail.com)
  6.  
  7. #    This program is free software: you can redistribute it and/or modify
  8. #    it under the terms of the GNU General Public License as published by
  9. #    the Free Software Foundation, either version 3 of the License, or
  10. #    (at your option) any later version.
  11.  
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16.  
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20.  
  21. #region Script Settings
  22. #<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
  23. #  <ScriptPackager>
  24. #    <process>powershell.exe</process>
  25. #    <arguments />
  26. #    <extractdir>%TEMP%</extractdir>
  27. #    <files />
  28. #    <usedefaulticon>true</usedefaulticon>
  29. #    <icon>Z:\RHEL 7\LAN-128.ico</icon>
  30. #    <showinsystray>false</showinsystray>
  31. #    <altcreds>false</altcreds>
  32. #    <efs>true</efs>
  33. #    <ntfs>true</ntfs>
  34. #    <local>false</local>
  35. #    <abortonfail>true</abortonfail>
  36. #    <product />
  37. #    <version>1.0.0.1</version>
  38. #    <versionstring />
  39. #    <comments />
  40. #    <company />
  41. #    <includeinterpreter>false</includeinterpreter>
  42. #    <forcecomregistration>false</forcecomregistration>
  43. #    <consolemode>false</consolemode>
  44. #    <EnableChangelog>false</EnableChangelog>
  45. #    <AutoBackup>false</AutoBackup>
  46. #    <snapinforce>false</snapinforce>
  47. #    <snapinshowprogress>false</snapinshowprogress>
  48. #    <snapinautoadd>2</snapinautoadd>
  49. #    <snapinpermanentpath />
  50. #    <cpumode>1</cpumode>
  51. #    <hidepsconsole>false</hidepsconsole>
  52. #  </ScriptPackager>
  53. #</ScriptSettings>
  54. #endregion
  55.  
  56. #region ScriptForm Designer
  57.  
  58. #region Constructor
  59.  
  60. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  61. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  62.  
  63. #endregion
  64.  
  65. #region Post-Constructor Custom Code
  66.  
  67. #endregion
  68.  
  69. #region Form Creation
  70. #Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
  71. #When working with the ScriptForm designer this region and any changes within may be overwritten.
  72. #~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. $Form1 = New-Object System.Windows.Forms.Form
  74. $Form1.ClientSize = New-Object System.Drawing.Size(532, 163)
  75. $Form1.Text = "Compmaggus v. 1.0"
  76. #~~< GroupBox2 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. $GroupBox2 = New-Object System.Windows.Forms.GroupBox
  78. $GroupBox2.Location = New-Object System.Drawing.Point(12, 68)
  79. $GroupBox2.Size = New-Object System.Drawing.Size(248, 47)
  80. $GroupBox2.TabIndex = 13
  81. $GroupBox2.TabStop = $false
  82. $GroupBox2.Text = "Distinguished Name of Domain Join Group"
  83. #~~< TextBox3 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84. $TextBox3 = New-Object System.Windows.Forms.TextBox
  85. $TextBox3.Location = New-Object System.Drawing.Point(7, 18)
  86. $TextBox3.Size = New-Object System.Drawing.Size(235, 20)
  87. $TextBox3.TabIndex = 0
  88. $TextBox3.Text = ""
  89. $GroupBox2.Controls.Add($TextBox3)
  90. #~~< GroupBox3 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. $GroupBox3 = New-Object System.Windows.Forms.GroupBox
  92. $GroupBox3.Location = New-Object System.Drawing.Point(270, 12)
  93. $GroupBox3.Size = New-Object System.Drawing.Size(257, 47)
  94. $GroupBox3.TabIndex = 12
  95. $GroupBox3.TabStop = $false
  96. $GroupBox3.Text = "Distinguished Name Excluding CN"
  97. #~~< TextBox2 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. $TextBox2 = New-Object System.Windows.Forms.TextBox
  99. $TextBox2.Location = New-Object System.Drawing.Point(7, 18)
  100. $TextBox2.Size = New-Object System.Drawing.Size(244, 20)
  101. $TextBox2.TabIndex = 0
  102. $TextBox2.Text = ""
  103. $GroupBox3.Controls.Add($TextBox2)
  104. #~~< CheckBox1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  105. $CheckBox1 = New-Object System.Windows.Forms.CheckBox
  106. $CheckBox1.Location = New-Object System.Drawing.Point(18, 127)
  107. $CheckBox1.Size = New-Object System.Drawing.Size(213, 24)
  108. $CheckBox1.TabIndex = 11
  109. $CheckBox1.Text = "Add Leading Zeros to Computer Name"
  110. $CheckBox1.UseVisualStyleBackColor = $true
  111. #~~< GroupBox6 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112. $GroupBox6 = New-Object System.Windows.Forms.GroupBox
  113. $GroupBox6.Location = New-Object System.Drawing.Point(270, 66)
  114. $GroupBox6.Size = New-Object System.Drawing.Size(153, 49)
  115. $GroupBox6.TabIndex = 10
  116. $GroupBox6.TabStop = $false
  117. $GroupBox6.Text = "Progress"
  118. #~~< ProgressBar1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. $ProgressBar1 = New-Object System.Windows.Forms.ProgressBar
  120. $ProgressBar1.Location = New-Object System.Drawing.Point(6, 20)
  121. $ProgressBar1.Size = New-Object System.Drawing.Size(133, 23)
  122. $ProgressBar1.TabIndex = 9
  123. $ProgressBar1.Text = ""
  124. $ProgressBar1.add_Click({ProgressBar1Click($ProgressBar1)})
  125. $GroupBox6.Controls.Add($ProgressBar1)
  126. $GroupBox6.add_Enter({GroupBox6Enter($GroupBox6)})
  127. #~~< Button1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128. $Button1 = New-Object System.Windows.Forms.Button
  129. $Button1.Location = New-Object System.Drawing.Point(429, 86)
  130. $Button1.Size = New-Object System.Drawing.Size(98, 27)
  131. $Button1.TabIndex = 8
  132. $Button1.Text = "Submit"
  133. $Button1.UseVisualStyleBackColor = $true
  134. $Button1.add_Click({makeADComputers($Button1)})
  135. #~~< GroupBox5 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136. $GroupBox5 = New-Object System.Windows.Forms.GroupBox
  137. $GroupBox5.Location = New-Object System.Drawing.Point(183, 12)
  138. $GroupBox5.Size = New-Object System.Drawing.Size(77, 48)
  139. $GroupBox5.TabIndex = 7
  140. $GroupBox5.TabStop = $false
  141. $GroupBox5.Text = "Number"
  142. #~~< NumericUpDown1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. $NumericUpDown1 = New-Object System.Windows.Forms.NumericUpDown
  144. $NumericUpDown1.Location = New-Object System.Drawing.Point(6, 19)
  145. $NumericUpDown1.Size = New-Object System.Drawing.Size(42, 20)
  146. $NumericUpDown1.TabIndex = 6
  147. $GroupBox5.Controls.Add($NumericUpDown1)
  148. #~~< GroupBox4 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. $GroupBox4 = New-Object System.Windows.Forms.GroupBox
  150. $GroupBox4.Location = New-Object System.Drawing.Point(12, 12)
  151. $GroupBox4.Size = New-Object System.Drawing.Size(165, 47)
  152. $GroupBox4.TabIndex = 5
  153. $GroupBox4.TabStop = $false
  154. $GroupBox4.Text = "Base Computer Name"
  155. #~~< TextBox1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. $TextBox1 = New-Object System.Windows.Forms.TextBox
  157. $TextBox1.Location = New-Object System.Drawing.Point(6, 19)
  158. $TextBox1.Size = New-Object System.Drawing.Size(152, 20)
  159. $TextBox1.TabIndex = 0
  160. $TextBox1.Text = ""
  161. $TextBox1.add_TextChanged({TextBox1TextChanged($TextBox1)})
  162. $GroupBox4.Controls.Add($TextBox1)
  163. $GroupBox4.add_Enter({GroupBox4Enter($GroupBox4)})
  164. $Form1.Controls.Add($GroupBox2)
  165. $Form1.Controls.Add($GroupBox3)
  166. $Form1.Controls.Add($CheckBox1)
  167. $Form1.Controls.Add($GroupBox6)
  168. $Form1.Controls.Add($Button1)
  169. $Form1.Controls.Add($GroupBox5)
  170. $Form1.Controls.Add($GroupBox4)
  171.  
  172. #endregion
  173.  
  174. #region Custom Code
  175.  
  176. #endregion
  177.  
  178. #region Event Loop
  179.  
  180. function Main{
  181.     [System.Windows.Forms.Application]::EnableVisualStyles()
  182.     [System.Windows.Forms.Application]::Run($Form1)
  183. }
  184.  
  185. #endregion
  186.  
  187. #endregion
  188.  
  189. #region Event Handlers
  190.  
  191. function ProgressBar1Click( $object ){
  192.  
  193. }
  194.  
  195. function GroupBox6Enter( $object ){
  196.  
  197. }
  198.  
  199.  
  200. function makeADComputers($object){
  201.        
  202.     #Pull the total number of computers to create.
  203.     $total = $NumericUpDown1.Value
  204.    
  205.     #Setup the progress bar
  206.     $ProgressBar1.Maximum = $total*2 + 2
  207.     $ProgressBar1.Value = 0
  208.    
  209.     #Get the Distinguished Name for the Path switch and the DN for the Domain Join Group
  210.     $PATHDN = $TextBox2.Text
  211.     $JOINGROUPDN = $TextBox3.Text
  212.        
  213.     #Set the alphabetical portion of the object name and create a query based on it.
  214.     $UNNUMB = $TextBox1.Text
  215.     $QUERY = "$UNNUMB*"
  216.        
  217.     #Increment the progress bar
  218.     $ProgressBar1.Value ++  
  219.    
  220.     #Use the query to obtain the highest numbered computer object name.
  221.     $COMPY = get-adcomputer -filter { Name -like $QUERY } | ForEach-Object  { echo $_.Name } | Select-Object -last 1
  222.     $TEST = $COMPY -match "[0-9]*[0-9]*[0-9]"
  223.     $lastNUM = [int]$matches[0]
  224.    
  225.     $count = 0
  226.        
  227.     #Increment the progress bar
  228.     $ProgressBar1.Value ++  
  229.        
  230.     #Start a loop to create the new accounts and change the permissions so that members of the Domain Join group can join them.
  231.     while ($count -lt $total)
  232.     {
  233.       #Gotta make sure that you aren't trying to create an already existing object.
  234.         $lastNUM++
  235.        
  236.         #If required, add the leading zeros back in (they were stripped out when the $lastNUM became an integer).
  237.         if ($CheckBox1.Checked)
  238.         {
  239.             if ($lastNUM -match "^[0-9]$")
  240.             {
  241.                 $lastSTRING = "00$lastNUM"
  242.             }
  243.             elseif ($lastNUM -match "^[0-9][0-9]$")
  244.             {
  245.                 $lastSTRING = "0$lastNUM"
  246.             }
  247.             else
  248.             {
  249.                 $lastSTRING = [string]$lastNUM
  250.             }
  251.         }  
  252.         #Make the new object.
  253.         new-adcomputer -name $UNNUMB$lastSTRING -SAMAccountName "$UNNUMB$lastSTRING`$" -Path $PATHDN
  254.                        
  255.         #Increment the progress bar
  256.         $ProgressBar1.Value++      
  257.        
  258.         #Update the Access Control List
  259.         dsacls "CN=$UNNUMB$lastSTRING,$PATHDN" /G "$JOINGROUPDN:CA;Reset password" "$JOINGROUPDN:CA;Send as" "$JOINGROUPDN:CA;Receive as" "$JOINGROUPDN:CA;Change password" "$JOINGROUPDN:CA;Allowed to authenticate" "$JOINGROUPDN:WP;Account restrictions" "$JOINGROUPDN:WS;Validated write to service principal name" "$JOINGROUPDN:WS;Validated write to DNS host name" "$JOINGROUPDN:GR"
  260.                
  261.         #Increment the progress bar again
  262.         $ProgressBar1.Value++    
  263.         $count++
  264.     }
  265.    
  266.     #[System.Windows.Forms.MessageBox]::Show("$UNNUMB")
  267.    
  268. }
  269.  
  270.  
  271. function TextBox1TextChanged( $object ){
  272.  
  273. }
  274.  
  275. function GroupBox4Enter( $object ){
  276.  
  277. }
  278.  
  279. Main # This call must remain below all other event functions
  280.  
  281. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement