Advertisement
Guest User

Untitled

a guest
May 12th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.16 KB | None | 0 0
  1. function OnApplicationLoad {
  2. $CreateXML = @"
  3. <?xml version="1.0" standalone="no"?>
  4. <OPTIONS Product="Arposh New User Creation" Version="1.2">
  5. <Settings>
  6. <sAMAccountName Generate="True">
  7. <Style Format="FirstName.LastName" Enabled="True" />
  8. <Style Format="FirstInitialLastName" Enabled="False" />
  9. <Style Format="LastNameFirstInitial" Enabled="False" />
  10. </sAMAccountName>
  11. <UPN Generate="True">
  12. <Style Format="FirstName.LastName" Enabled="True" />
  13. <Style Format="FirstInitialLastName" Enabled="False" />
  14. <Style Format="LastNameFirstInitial" Enabled="False" />
  15. </UPN>
  16. <DisplayName Generate="True">
  17. <Style Format="FirstName LastName" Enabled="False" />
  18. <Style Format="LastName, FirstName" Enabled="True" />
  19. </DisplayName>
  20. <AccountStatus Enabled="True" />
  21. <Password ChangeAtLogon="True" />
  22. </Settings>
  23. <Default>
  24. <Domain>RU.lab</Domain>
  25. <Path>OU=MyOU,DC=ru,DC=lab</Path>
  26. <FirstName></FirstName>
  27. <LastName></LastName>
  28. <Office></Office>
  29. <Title></Title>
  30. <Description>Full-Time Employee</Description>
  31. <Department>IT</Department>
  32. <Company>Arposh</Company>
  33. <Phone>212-555-1000</Phone>
  34. <Site>NY</Site>
  35. <StreetAddress>100 Main Street</StreetAddress>
  36. <City>New York</City>
  37. <State>NY</State>
  38. <PostalCode>10001</PostalCode>
  39. <Password>P@ssw0rd</Password>
  40. </Default>
  41. <Locations>
  42. <Location Site="NY">
  43. <StreetAddress>1 Main Street</StreetAddress>
  44. <City>New York</City>
  45. <State>NY</State>
  46. <PostalCode>10001</PostalCode>
  47. </Location>
  48. <Location Site="NJ">
  49. <StreetAddress>2 Main Street</StreetAddress>
  50. <City>Edison</City>
  51. <State>NJ</State>
  52. <PostalCode>22222</PostalCode>
  53. </Location>
  54. <Location Site="Custom">
  55. <StreetAddress></StreetAddress>
  56. <City></City>
  57. <State></State>
  58. <PostalCode></PostalCode>
  59. </Location>
  60. </Locations>
  61. <Domains>
  62. <Domain Name="RU.lab">
  63. <Path>OU=MyOU,DC=ru,DC=lab</Path>
  64. <Path>CN=Users,DC=ru,DC=lab</Path>
  65. </Domain>
  66. <Domain Name="RP.lab">
  67. <Path>OU=RPUsers1,DC=rp,DC=lab</Path>
  68. <Path>OU=RPUsers2,DC=rp,DC=lab</Path>
  69. <Path>OU=RPUsers3,DC=rp,DC=lab</Path>
  70. </Domain>
  71. </Domains>
  72. <Descriptions>
  73. <Description>Full-Time Employee</Description>
  74. <Description>Part-Time Employee</Description>
  75. <Description>Consultant</Description>
  76. <Description>Intern</Description>
  77. <Description>Service Account</Description>
  78. <Description>Temp</Description>
  79. <Description>Freelancer</Description>
  80. </Descriptions>
  81. <Departments>
  82. <Department>Finance</Department>
  83. <Department>IT</Department>
  84. <Department>Marketing</Department>
  85. <Department>Sales</Department>
  86. <Department>Executive</Department>
  87. <Department>Human Resources</Department>
  88. <Department>Security</Department>
  89. </Departments>
  90. </OPTIONS>
  91. "@
  92.  
  93. Import-Module ActiveDirectory
  94. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
  95. $XMLOptions = "ANUC.Options.xml"
  96. $Script:ParentFolder = Split-Path (Get-Variable MyInvocation -scope 1 -ValueOnly).MyCommand.Definition
  97. $XMLFile = Join-Path $ParentFolder $XMLOptions
  98.  
  99. $XMLMsg = "Configuration file $XMLOptions not detected in folder $ParentFolder. Would you like to create one now?"
  100. if(!(Test-Path $XMLFile)){
  101. if([System.Windows.Forms.MessageBox]::Show($XMLMsg,"Warning",[System.Windows.Forms.MessageBoxButtons]::YesNo) -eq "Yes")
  102. {
  103. $CreateXML | Out-File $XMLFile
  104. $TemplateMsg = "Opening XML configuration file for editing ($XMLFile). Please relaunch the script when the configuration is complete."
  105. [System.Windows.Forms.MessageBox]::Show($TemplateMsg,"Information",[System.Windows.Forms.MessageBoxButtons]::Ok) | Out-Null
  106. notepad $XMLFile
  107. Exit
  108. }
  109. else{Exit}
  110. }
  111. else{[XML]$Script:XML = Get-Content $XMLFile}
  112. if($XML.Options.Version -ne ([xml]$CreateXML).Options.Version)
  113. {
  114. $VersionMsg = "You are using an older version of the Options file. Please generate a new Options file and transfer your settings.`r`nIn Use: $($XML.Options.Version) `r`nLatest: $(([xml]$CreateXML).Options.Version)"
  115. [System.Windows.Forms.MessageBox]::Show($VersionMsg,"Warning",[System.Windows.Forms.MessageBoxButtons]::Ok)
  116. }
  117. else{}
  118. return $true#return true for success or false for failure
  119. }
  120.  
  121. function OnApplicationExit {
  122. Remove-Module ActiveDirectory
  123. $script:ExitCode = 0 #Set the exit code for the Packager
  124. }
  125.  
  126. Function Set-sAMAccountName {
  127. Param([Switch]$Csv=$false)
  128. if(!$Csv)
  129. {
  130. $GivenName = $txtFirstName.text
  131. $SurName = $txtLastName.text
  132. }
  133. else{}
  134. Switch($XML.Options.Settings.sAMAccountName.Style | Where{$_.Enabled -eq $True} | Select -ExpandProperty Format)
  135. {
  136. "FirstName.LastName" {"{0}.{1}" -f $GivenName,$Surname}
  137. "FirstInitialLastName" {"{0}{1}" -f ($GivenName)[0],$SurName}
  138. "LastNameFirstInitial" {"{0}{1}" -f $SurName,($GivenName)[0]}
  139. Default {"{0}.{1}" -f $GivenName,$Surname}
  140. }
  141. }
  142.  
  143. Function Set-UPN {
  144. Param([Switch]$Csv=$false)
  145. if(!$Csv)
  146. {
  147. $GivenName = $txtFirstName.text
  148. $SurName = $txtLastName.text
  149. $Domain = $cboDomain.Text
  150. }
  151. else{}
  152. Switch($XML.Options.Settings.UPN.Style | Where{$_.Enabled -eq $True} | Select -ExpandProperty Format)
  153. {
  154. "FirstName.LastName" {"{0}.{1}@{2}" -f $GivenName,$Surname,$Domain}
  155. "FirstInitialLastName" {"{0}{1}@{2}" -f ($GivenName)[0],$SurName,$Domain}
  156. "LastNameFirstInitial" {"{0}{1}@{2}" -f $SurName,($GivenName)[0],$Domain}
  157. Default {"{0}.{1}@{2}" -f $GivenName,$Surname,$Domain}
  158. }
  159. }
  160.  
  161. Function Set-DisplayName {
  162. Param([Switch]$Csv=$false)
  163. if(!$Csv)
  164. {
  165. $GivenName = $txtFirstName.text
  166. $SurName = $txtLastName.text
  167. }
  168. else{}
  169. Switch($XML.Options.Settings.DisplayName.Style | Where{$_.Enabled -eq $True} | Select -ExpandProperty Format)
  170. {
  171. "FirstName LastName" {"{0} {1}" -f $GivenName,$Surname}
  172. "LastName, FirstName" {"{0}, {1}" -f $SurName, $GivenName}
  173. Default {"{0} {1}" -f $GivenName,$Surname}
  174. }
  175. }
  176. #endregion Application Functions
  177.  
  178. #----------------------------------------------
  179. # Generated Form Function
  180. #----------------------------------------------
  181. function Call-ANUC_pff {
  182.  
  183. #----------------------------------------------
  184. #region Import the Assemblies
  185. #----------------------------------------------
  186. [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  187. [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  188. [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  189. [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  190. [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  191. [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  192. [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  193. [void][reflection.assembly]::Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  194. #endregion Import Assemblies
  195.  
  196. #----------------------------------------------
  197. #region Generated Form Objects
  198. #----------------------------------------------
  199. [System.Windows.Forms.Application]::EnableVisualStyles()
  200. $formMain = New-Object System.Windows.Forms.Form
  201. $btnSubmitAll = New-Object System.Windows.Forms.Button
  202. $btnLast = New-Object System.Windows.Forms.Button
  203. $btnNext = New-Object System.Windows.Forms.Button
  204. $btnPrev = New-Object System.Windows.Forms.Button
  205. $btnFirst = New-Object System.Windows.Forms.Button
  206. $btnImportCSV = New-Object System.Windows.Forms.Button
  207. $lvCSV = New-Object System.Windows.Forms.ListView
  208. $txtUPN = New-Object System.Windows.Forms.TextBox
  209. $txtsAM = New-Object System.Windows.Forms.TextBox
  210. $txtDN = New-Object System.Windows.Forms.TextBox
  211. $cboDepartment = New-Object System.Windows.Forms.ComboBox
  212. $labelUserPrincipalName = New-Object System.Windows.Forms.Label
  213. $labelSamAccountName = New-Object System.Windows.Forms.Label
  214. $labelDisplayName = New-Object System.Windows.Forms.Label
  215. $SB = New-Object System.Windows.Forms.StatusBar
  216. $cboSite = New-Object System.Windows.Forms.ComboBox
  217. $labelSite = New-Object System.Windows.Forms.Label
  218. $cboDescription = New-Object System.Windows.Forms.ComboBox
  219. $txtPassword = New-Object System.Windows.Forms.TextBox
  220. $labelPassword = New-Object System.Windows.Forms.Label
  221. $cboDomain = New-Object System.Windows.Forms.ComboBox
  222. $labelCurrentDomain = New-Object System.Windows.Forms.Label
  223. $txtPostalCode = New-Object System.Windows.Forms.TextBox
  224. $txtState = New-Object System.Windows.Forms.TextBox
  225. $txtCity = New-Object System.Windows.Forms.TextBox
  226. $txtStreetAddress = New-Object System.Windows.Forms.TextBox
  227. $txtOffice = New-Object System.Windows.Forms.TextBox
  228. $txtCompany = New-Object System.Windows.Forms.TextBox
  229. $txtTitle = New-Object System.Windows.Forms.TextBox
  230. $txtOfficePhone = New-Object System.Windows.Forms.TextBox
  231. $txtLastName = New-Object System.Windows.Forms.TextBox
  232. $cboPath = New-Object System.Windows.Forms.ComboBox
  233. $labelOU = New-Object System.Windows.Forms.Label
  234. $txtFirstName = New-Object System.Windows.Forms.TextBox
  235. $labelPostalCode = New-Object System.Windows.Forms.Label
  236. $labelState = New-Object System.Windows.Forms.Label
  237. $labelCity = New-Object System.Windows.Forms.Label
  238. $labelStreetAddress = New-Object System.Windows.Forms.Label
  239. $labelOffice = New-Object System.Windows.Forms.Label
  240. $labelCompany = New-Object System.Windows.Forms.Label
  241. $labelDepartment = New-Object System.Windows.Forms.Label
  242. $labelTitle = New-Object System.Windows.Forms.Label
  243. $btnSubmit = New-Object System.Windows.Forms.Button
  244. $labelDescription = New-Object System.Windows.Forms.Label
  245. $labelOfficePhone = New-Object System.Windows.Forms.Label
  246. $labelLastName = New-Object System.Windows.Forms.Label
  247. $labelFirstName = New-Object System.Windows.Forms.Label
  248. $menustrip1 = New-Object System.Windows.Forms.MenuStrip
  249. $fileToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem
  250. $formMode = New-Object System.Windows.Forms.ToolStripMenuItem
  251. $CSVTemplate = New-Object System.Windows.Forms.SaveFileDialog
  252. $OFDImportCSV = New-Object System.Windows.Forms.OpenFileDialog
  253. $CreateCSVTemplate = New-Object System.Windows.Forms.ToolStripMenuItem
  254. $MenuExit = New-Object System.Windows.Forms.ToolStripMenuItem
  255. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  256. #endregion Generated Form Objects
  257.  
  258. #----------------------------------------------
  259. # User Generated Script
  260. #----------------------------------------------
  261.  
  262.  
  263.  
  264. $formMain_Load={
  265.  
  266. $formMain.Text = $formMain.Text + " " + $XML.Options.Version
  267.  
  268. Write-Verbose "Adding domains to combo box"
  269. $XML.Options.Domains.Domain | %{$cboDomain.Items.Add($_.Name)}
  270.  
  271. Write-Verbose "Adding OUs to combo box"
  272. $XML.Options.Domains.Domain | ?{$_.Name -match $cboDomain.Text} | Select -ExpandProperty Path | %{$cboPath.Items.Add($_)}
  273.  
  274. Write-Verbose "Adding descriptions to combo box"
  275. $XML.Options.Descriptions.Description | %{$cboDescription.Items.Add($_)}
  276.  
  277. Write-Verbose "Adding sites to combo box"
  278. $XML.Options.Locations.Location | %{$cboSite.Items.Add($_.Site)}
  279.  
  280. Write-Verbose "Adding departments to combo box"
  281. $XML.Options.Departments.Department | %{$cboDepartment.Items.Add($_)}
  282.  
  283. Write-Verbose "Setting default fields"
  284. $cboDomain.SelectedItem = $XML.Options.Default.Domain
  285. $cboPath.SelectedItem = $XML.Options.Default.Path
  286. $txtFirstName.Text = $XML.Options.Default.FirstName
  287. $txtLastName.Text = $XML.Options.Default.LastName
  288. $txtOffice.Text = $XML.Options.Default.Office
  289. $txtTitle.Text = $XML.Options.Default.Title
  290. $cboDescription.SelectedItem = $XML.Options.Default.Description
  291. $cboDepartment.SelectedItem = $XML.Options.Default.Department
  292. $txtCompany.Text = $XML.Options.Default.Company
  293. $txtOfficePhone.Text = $XML.Options.Default.Phone
  294. $cboSite.SelectedItem = $XML.Options.Default.Site
  295. $txtStreetAddress.Text = $XML.Options.Default.StreetAddress
  296. $txtCity.Text = $XML.Options.Default.City
  297. $txtState.Text = $XML.Options.Default.State
  298. $txtPostalCode.Text = $XML.Options.Default.PostalCode
  299. $txtPassword.Text = $XML.Options.Default.Password
  300.  
  301. Write-Verbose "Creating CSV Headers"
  302. $Headers = @('ID','Domain','Path','FirstName','LastName','Office','Title','Description','Department','Company','Phone','StreetAddress','City','State','PostalCode','Password','sAMAccountName','userPrincipalName','DisplayName')
  303. $Headers| %{[Void]$lvCSV.Columns.Add($_)}
  304. }
  305.  
  306. $btnSubmit_Click={
  307.  
  308. $Domain=$cboDomain.Text
  309. $Path=$cboPath.Text
  310. $GivenName = $txtFirstName.Text
  311. $Surname = $txtLastName.Text
  312. $OfficePhone = $txtOfficePhone.Text
  313. $Description = $cboDescription.Text
  314. $Title = $txtTitle.Text
  315. $Department = $cboDepartment.Text
  316. $Company = $txtCompany.Text
  317. $Office = $txtOffice.Text
  318. $StreetAddress = $txtStreetAddress.Text
  319. $City = $txtCity.Text
  320. $State = $txtState.Text
  321. $PostalCode = $txtPostalCode.Text
  322.  
  323. if($XML.Options.Settings.Password.ChangeAtLogon -eq "True"){$ChangePasswordAtLogon = $True}
  324. else{$ChangePasswordAtLogon = $false}
  325.  
  326. if($XML.Options.Settings.AccountStatus.Enabled -eq "True"){$Enabled = $True}
  327. else{$Enabled = $false}
  328.  
  329. $Name="$GivenName $Surname"
  330.  
  331. if($XML.Options.Settings.sAMAccountName.Generate -eq $True){$sAMAccountName = Set-sAMAccountName}
  332. else{$sAMAccountName = $txtsAM.Text}
  333.  
  334. if($XML.Options.Settings.uPN.Generate -eq $True){$userPrincipalName = Set-UPN}
  335. else{$userPrincipalName = $txtuPN.Text}
  336.  
  337. if($XML.Options.Settings.DisplayName.Generate -eq $True){$DisplayName = Set-DisplayName}
  338. else{$DisplayName = $txtDN.Text}
  339.  
  340. $AccountPassword = $txtPassword.text | ConvertTo-SecureString -AsPlainText -Force
  341.  
  342. $User = @{
  343. Name = $Name
  344. GivenName = $GivenName
  345. Surname = $Surname
  346. Path = $Path
  347. samAccountName = $samAccountName
  348. userPrincipalName = $userPrincipalName
  349. DisplayName = $DisplayName
  350. AccountPassword = $AccountPassword
  351. ChangePasswordAtLogon = $ChangePasswordAtLogon
  352. Enabled = $Enabled
  353. OfficePhone = $OfficePhone
  354. Description = $Description
  355. Title = $Title
  356. Department = $Department
  357. Company = $Company
  358. Office = $Office
  359. StreetAddress = $StreetAddress
  360. City = $City
  361. State = $State
  362. PostalCode = $PostalCode
  363. }
  364. $SB.Text = "Creating new user $sAMAccountName"
  365. $ADError = $Null
  366. New-ADUser @User -ErrorVariable ADError
  367. if ($ADerror){$SB.Text = "[$sAMAccountName] $ADError"}
  368. else{$SB.Text = "$sAMAccountName created successfully."}
  369. }
  370.  
  371. $cboDomain_SelectedIndexChanged={
  372. $cboPath.Items.Clear()
  373. Write-Verbose "Adding OUs to combo box"
  374. $XML.Options.Domains.Domain | ?{$_.Name -match $cboDomain.Text} | Select -ExpandProperty Path | %{$cboPath.Items.Add($_)}
  375. Write-Verbose "Creating required account fields"
  376.  
  377. if ($XML.Options.Settings.DisplayName.Generate) {$txtDN.Text = Set-DisplayName}
  378. if ($XML.Options.Settings.sAMAccountName.Generate) {$txtsAM.Text = Set-sAMAccountName}
  379. if ($XML.Options.Settings.UPN.Generate) {$txtUPN.Text = Set-UPN}
  380. }
  381.  
  382. $cboSite_SelectedIndexChanged={
  383. Write-Verbose "Updating site fields with address information"
  384. $Site = $XML.Options.Locations.Location | ?{$_.Site -match $cboSite.Text}
  385. $txtStreetAddress.Text = $Site.StreetAddress
  386. $txtCity.Text = $Site.City
  387. $txtState.Text = $Site.State
  388. $txtPostalCode.Text = $Site.PostalCode
  389. }
  390.  
  391. $txtName_TextChanged={
  392. Write-Verbose "Creating required account fields"
  393.  
  394. if ($XML.Options.Settings.DisplayName.Generate -eq $True) {$txtDN.Text = Set-DisplayName}
  395. if ($XML.Options.Settings.sAMAccountName.Generate -eq $True) {$txtsAM.Text = (Set-sAMAccountName)}
  396. if ($XML.Options.Settings.UPN.Generate -eq $True) {$txtUPN.Text = Set-UPN}
  397. }
  398.  
  399. $createTemplateToolStripMenuItem_Click={
  400. $CSVTemplate.ShowDialog()
  401. }
  402.  
  403. $CSVTemplate_FileOk=[System.ComponentModel.CancelEventHandler]{
  404. "" |
  405. Select Domain,Path,FirstName,LastName,Office,Title,Description,Department,Company,Phone,StreetAddress,City,State,PostalCode,Password,sAMAccountName,userPrincipalName,DisplayName |
  406. Export-CSV $CSVTemplate.FileName -NoTypeInformation
  407. }
  408.  
  409. $formMode_Click={
  410. if($formMode.Text -eq 'CSV Mode'){
  411. $formMode.Text = "Single-User Mode"
  412. Get-Variable | ?{$_.Name -match "txt"} | %{Try{$_.Value.Anchor = 'Top,Left'}catch{}}
  413. Get-Variable | ?{$_.Name -match "cbo"} | %{Try{$_.Value.Anchor = 'Top,Left'}catch{}}
  414. Get-Variable | ?{$_.Name -match "btn"} | %{Try{$_.Value.Anchor = 'Top,Left'}catch{}}
  415. $formMain.Size = '1484,635'
  416. $btnFirst.Visible = $True
  417. $btnPrev.Visible = $True
  418. $btnNext.Visible = $True
  419. $btnLast.Visible = $True
  420. $btnImportCSV.Visible = $True
  421. $btnSubmitAll.Visible = $True
  422. $lvCSV.Visible = $True
  423. $cboDomain.Width = '175'
  424. $cboPath.Width = '249'
  425. $txtFirstName.Width = '175'
  426. $txtLastName.Width = '175'
  427. $txtOffice.Width = '175'
  428. $txtTitle.Width = '175'
  429. $cboDescription.Width = '175'
  430. $cboDepartment.Width = '175'
  431. $txtCompany.Width = '175'
  432. $txtOfficePhone.Width = '175'
  433. $cboSite.Width = '175'
  434. $txtStreetAddress.Width = '175'
  435. $txtCity.Width = '175'
  436. $txtState.Width = '175'
  437. $txtPostalCode.Width = '175'
  438. $txtPassword.Width = '175'
  439. $txtDN.Width = '175'
  440. $txtsAM.Width = '175'
  441. $txtUPN.Width = '175'
  442. }
  443. else{
  444. $formMode.Text = "CSV Mode"
  445. $formMain.Size = '320,635'
  446. Get-Variable | ?{$_.Name -match "txt"} | %{Try{$_.Value.Anchor = 'Top,Left,Right'}catch{}}
  447. Get-Variable | ?{$_.Name -match "cbo"} | %{Try{$_.Value.Anchor = 'Top,Left,Right'}catch{}}
  448. Get-Variable | ?{$_.Name -match "btn"} | %{Try{$_.Value.Anchor = 'Top,Left,Right'}catch{}}
  449. $btnFirst.Visible = $False
  450. $btnPrev.Visible = $False
  451. $btnNext.Visible = $False
  452. $btnLast.Visible = $False
  453. $btnImportCSV.Visible = $False
  454. $btnSubmitAll.Visible = $False
  455. $lvCSV.Visible = $False
  456. }
  457. }
  458.  
  459. $btnImportCSV_Click={
  460. $OFDImportCSV.ShowDialog()
  461. $CSV = Import-Csv $OFDImportCSV.FileName
  462. $i = 0
  463. ForEach ($Entry in $CSV){
  464. $User = New-Object System.Windows.Forms.ListViewItem($i)
  465. ForEach ($Col in ($lvCSV.Columns | ?{$_.Text -ne "ID"})){
  466. $Field = $Col.Text
  467. $SubItem = "$($Entry.$Field)"
  468. if($Field -eq 'FirstName'){$Script:GivenName = $SubItem}
  469. if($Field -eq 'LastName'){$Script:Surname = $SubItem}
  470. if($Field -eq 'Domain'){$Domain = $SubItem}
  471. if($Field -eq 'sAMAccountName' -AND $SubItem -eq ""){$SubItem = Set-sAMAccountName -Csv}
  472. if($Field -eq 'userPrincipalName' -AND $SubItem -eq ""){$SubItem = Set-UPN -Csv}
  473. if($Field -eq 'DisplayName' -AND $SubItem -eq ""){$SubItem = Set-DisplayName -Csv}
  474. $User.SubItems.Add($SubItem)
  475. }
  476. $lvCSV.Items.Add($User)
  477. $i++
  478. }
  479. }
  480.  
  481. $lvCSV_SelectedIndexChanged={
  482. try{$cboDomain.SelectedItem = $lvCSV.SelectedItems[0].SubItems[1].Text}catch{}
  483. try{$cboPath.SelectedItem = $lvCSV.SelectedItems[0].SubItems[2].Text}catch{}
  484. try{$txtFirstName.Text = $lvCSV.SelectedItems[0].SubItems[3].Text}catch{}
  485. try{$txtLastName.Text = $lvCSV.SelectedItems[0].SubItems[4].Text}catch{}
  486. try{$txtOffice.Text = $lvCSV.SelectedItems[0].SubItems[5].Text}catch{}
  487. try{$txtTitle.Text = $lvCSV.SelectedItems[0].SubItems[6].Text}catch{}
  488. try{$cboDescription.SelectedItem = $lvCSV.SelectedItems[0].SubItems[7].Text}catch{}
  489. try{$cboDepartment.SelectedItem = $lvCSV.SelectedItems[0].SubItems[8].Text}catch{}
  490. try{$txtCompany.Text = $lvCSV.SelectedItems[0].SubItems[9].Text}catch{}
  491. try{$txtOfficePhone.Text = $lvCSV.SelectedItems[0].SubItems[10].Text}catch{}
  492. try{$txtStreetAddress.Text = $lvCSV.SelectedItems[0].SubItems[11].Text}catch{}
  493. try{$txtCity.Text = $lvCSV.SelectedItems[0].SubItems[12].Text}catch{}
  494. try{$txtState.Text = $lvCSV.SelectedItems[0].SubItems[13].Text}catch{}
  495. try{$txtPostalCode.Text = $lvCSV.SelectedItems[0].SubItems[14].Text}catch{}
  496. try{$txtPassword.Text = $lvCSV.SelectedItems[0].SubItems[15].Text}catch{}
  497. try{$txtsAM.Text = $lvCSV.SelectedItems[0].SubItems[16].Text}catch{}
  498. try{$txtuPN.Text = $lvCSV.SelectedItems[0].SubItems[17].Text}catch{}
  499. try{$txtDN.Text = $lvCSV.SelectedItems[0].SubItems[18].Text}catch{}
  500. }
  501.  
  502. $btnFirst_Click={
  503. $lvCSV.Items | %{$_.Selected = $False}
  504. $lvCSV.Items[0].Selected = $True
  505. }
  506.  
  507. $btnLast_Click={
  508. $LastRow = ($lvCSV.Items).Count - 1
  509. $lvCSV.Items | %{$_.Selected = $False}
  510. $lvCSV.Items[$LastRow].Selected = $True
  511. }
  512.  
  513. $btnNext_Click={
  514. $LastRow = ($lvCSV.Items).Count - 1
  515. [Int]$Index = $lvCSV.SelectedItems[0].Index
  516. if($LastRow -gt $Index){
  517. $lvCSV.Items | %{$_.Selected = $False}
  518. $lvCSV.Items[$Index+1].Selected = $True
  519. }
  520. }
  521.  
  522. $btnPrev_Click={
  523. [Int]$Index = $lvCSV.SelectedItems[0].Index
  524. if($Index -gt 0){
  525. $lvCSV.Items | %{$_.Selected = $False}
  526. $lvCSV.Items[$Index-1].Selected = $True
  527. }
  528. }
  529.  
  530. $MenuExit_Click={
  531. $formMain.Close()
  532. }
  533.  
  534. $btnSubmitAll_Click={
  535. $lvCSV.Items | %{
  536.  
  537. $Domain = $_.Subitems[1].Text
  538. $Path = $_.Subitems[2].Text
  539. $GivenName = $_.Subitems[3].Text
  540. $Surname = $_.Subitems[4].Text
  541. $OfficePhone = $_.Subitems[5].Text
  542. $Title = $_.Subitems[6].Text
  543. $Description = $_.Subitems[7].Text
  544. $Department = $_.Subitems[8].Text
  545. $Company = $_.Subitems[9].Text
  546. $Office = $_.Subitems[10].Text
  547. $StreetAddress = $_.Subitems[11].Text
  548. $City = $_.Subitems[12].Text
  549. $State = $_.Subitems[13].Text
  550. $PostalCode = $_.Subitems[14].Text
  551.  
  552. $Name = "$GivenName $Surname"
  553.  
  554. if($XML.Options.Settings.Password.ChangeAtLogon -eq "True"){$ChangePasswordAtLogon = $True}
  555. else{$ChangePasswordAtLogon = $false}
  556.  
  557. if($XML.Options.Settings.AccountStatus.Enabled -eq "True"){$Enabled = $True}
  558. else{$Enabled = $false}
  559.  
  560. if($_.Subitems[16].Text -eq $null){$sAMAccountName = Set-sAMAccountName}
  561. else{$sAMAccountName = $_.Subitems[16].Text}
  562.  
  563. if($_.Subitems[17].Text -eq $null){$userPrincipalName = Set-UPN}
  564. else{$userPrincipalName = $_.Subitems[17].Text}
  565.  
  566. if($_.Subitems[18].Text -eq $null){$DisplayName = Set-DisplayName}
  567. else{$DisplayName = $_.Subitems[18].Text}
  568.  
  569. $AccountPassword = $_.Subitems[15].Text | ConvertTo-SecureString -AsPlainText -Force
  570.  
  571. $User = @{
  572. Name = $Name
  573. GivenName = $GivenName
  574. Surname = $Surname
  575. Path = $Path
  576. samAccountName = $samAccountName
  577. userPrincipalName = $userPrincipalName
  578. DisplayName = $DisplayName
  579. AccountPassword = $AccountPassword
  580. ChangePasswordAtLogon = $ChangePasswordAtLogon
  581. Enabled = $Enabled
  582. OfficePhone = $OfficePhone
  583. Description = $Description
  584. Title = $Title
  585. Department = $Department
  586. Company = $Company
  587. Office = $Office
  588. StreetAddress = $StreetAddress
  589. City = $City
  590. State = $State
  591. PostalCode = $PostalCode
  592. }
  593. $SB.Text = "Creating new user $sAMAccountName"
  594. $ADError = $Null
  595. New-ADUser @User -ErrorVariable ADError
  596. if ($ADerror){$SB.Text = "[$sAMAccountName] $ADError"}
  597. else{$SB.Text = "$sAMAccountName created successfully."}
  598. }
  599. }
  600.  
  601.  
  602. # --End User Generated Script--
  603. #----------------------------------------------
  604. #region Generated Events
  605. #----------------------------------------------
  606.  
  607. $Form_StateCorrection_Load=
  608. {
  609. #Correct the initial state of the form to prevent the .Net maximized form issue
  610. $formMain.WindowState = $InitialFormWindowState
  611. }
  612.  
  613. $Form_Cleanup_FormClosed=
  614. {
  615. #Remove all event handlers from the controls
  616. try
  617. {
  618. $btnSubmitAll.remove_Click($btnSubmitAll_Click)
  619. $btnLast.remove_Click($btnLast_Click)
  620. $btnNext.remove_Click($btnNext_Click)
  621. $btnPrev.remove_Click($btnPrev_Click)
  622. $btnFirst.remove_Click($btnFirst_Click)
  623. $btnImportCSV.remove_Click($btnImportCSV_Click)
  624. $lvCSV.remove_SelectedIndexChanged($lvCSV_SelectedIndexChanged)
  625. $cboSite.remove_SelectedIndexChanged($cboSite_SelectedIndexChanged)
  626. $cboDomain.remove_SelectedIndexChanged($cboDomain_SelectedIndexChanged)
  627. $txtLastName.remove_TextChanged($txtName_TextChanged)
  628. $txtFirstName.remove_TextChanged($txtName_TextChanged)
  629. $btnSubmit.remove_Click($btnSubmit_Click)
  630. $formMain.remove_Load($formMain_Load)
  631. $formMode.remove_Click($formMode_Click)
  632. $CSVTemplate.remove_FileOk($CSVTemplate_FileOk)
  633. $CreateCSVTemplate.remove_Click($createTemplateToolStripMenuItem_Click)
  634. $MenuExit.remove_Click($MenuExit_Click)
  635. $formMain.remove_Load($Form_StateCorrection_Load)
  636. $formMain.remove_FormClosed($Form_Cleanup_FormClosed)
  637. }
  638. catch [Exception]
  639. { }
  640. }
  641. #endregion Generated Events
  642.  
  643. #----------------------------------------------
  644. #region Generated Form Code
  645. #----------------------------------------------
  646. #
  647. # formMain
  648. #
  649. $formMain.Controls.Add($btnSubmitAll)
  650. $formMain.Controls.Add($btnLast)
  651. $formMain.Controls.Add($btnNext)
  652. $formMain.Controls.Add($btnPrev)
  653. $formMain.Controls.Add($btnFirst)
  654. $formMain.Controls.Add($btnImportCSV)
  655. $formMain.Controls.Add($lvCSV)
  656. $formMain.Controls.Add($txtUPN)
  657. $formMain.Controls.Add($txtsAM)
  658. $formMain.Controls.Add($txtDN)
  659. $formMain.Controls.Add($cboDepartment)
  660. $formMain.Controls.Add($labelUserPrincipalName)
  661. $formMain.Controls.Add($labelSamAccountName)
  662. $formMain.Controls.Add($labelDisplayName)
  663. $formMain.Controls.Add($SB)
  664. $formMain.Controls.Add($cboSite)
  665. $formMain.Controls.Add($labelSite)
  666. $formMain.Controls.Add($cboDescription)
  667. $formMain.Controls.Add($txtPassword)
  668. $formMain.Controls.Add($labelPassword)
  669. $formMain.Controls.Add($cboDomain)
  670. $formMain.Controls.Add($labelCurrentDomain)
  671. $formMain.Controls.Add($txtPostalCode)
  672. $formMain.Controls.Add($txtState)
  673. $formMain.Controls.Add($txtCity)
  674. $formMain.Controls.Add($txtStreetAddress)
  675. $formMain.Controls.Add($txtOffice)
  676. $formMain.Controls.Add($txtCompany)
  677. $formMain.Controls.Add($txtTitle)
  678. $formMain.Controls.Add($txtOfficePhone)
  679. $formMain.Controls.Add($txtLastName)
  680. $formMain.Controls.Add($cboPath)
  681. $formMain.Controls.Add($labelOU)
  682. $formMain.Controls.Add($txtFirstName)
  683. $formMain.Controls.Add($labelPostalCode)
  684. $formMain.Controls.Add($labelState)
  685. $formMain.Controls.Add($labelCity)
  686. $formMain.Controls.Add($labelStreetAddress)
  687. $formMain.Controls.Add($labelOffice)
  688. $formMain.Controls.Add($labelCompany)
  689. $formMain.Controls.Add($labelDepartment)
  690. $formMain.Controls.Add($labelTitle)
  691. $formMain.Controls.Add($btnSubmit)
  692. $formMain.Controls.Add($labelDescription)
  693. $formMain.Controls.Add($labelOfficePhone)
  694. $formMain.Controls.Add($labelLastName)
  695. $formMain.Controls.Add($labelFirstName)
  696. $formMain.Controls.Add($menustrip1)
  697. $formMain.AcceptButton = $btnSubmit
  698. $formMain.ClientSize = '304, 597'
  699. $System_Windows_Forms_MenuStrip_1 = New-Object System.Windows.Forms.MenuStrip
  700. $System_Windows_Forms_MenuStrip_1.Location = '0, 0'
  701. $System_Windows_Forms_MenuStrip_1.Name = ""
  702. $System_Windows_Forms_MenuStrip_1.Size = '271, 24'
  703. $System_Windows_Forms_MenuStrip_1.TabIndex = 1
  704. $System_Windows_Forms_MenuStrip_1.Visible = $False
  705. $formMain.MainMenuStrip = $System_Windows_Forms_MenuStrip_1
  706. $formMain.Name = "formMain"
  707. $formMain.ShowIcon = $False
  708. $formMain.StartPosition = 'CenterScreen'
  709. $formMain.Text = "Arposh New User Creation"
  710. $formMain.add_Load($formMain_Load)
  711. #
  712. # btnSubmitAll
  713. #
  714. $btnSubmitAll.Location = '503, 0'
  715. $btnSubmitAll.Name = "btnSubmitAll"
  716. $btnSubmitAll.Size = '75, 25'
  717. $btnSubmitAll.TabIndex = 59
  718. $btnSubmitAll.Text = "Submit All"
  719. $btnSubmitAll.UseVisualStyleBackColor = $True
  720. $btnSubmitAll.Visible = $False
  721. $btnSubmitAll.add_Click($btnSubmitAll_Click)
  722. #
  723. # btnLast
  724. #
  725. $btnLast.Location = '472, 0'
  726. $btnLast.Name = "btnLast"
  727. $btnLast.Size = '30, 25'
  728. $btnLast.TabIndex = 58
  729. $btnLast.Text = ">>"
  730. $btnLast.UseVisualStyleBackColor = $True
  731. $btnLast.Visible = $False
  732. $btnLast.add_Click($btnLast_Click)
  733. #
  734. # btnNext
  735. #
  736. $btnNext.Location = '441, 0'
  737. $btnNext.Name = "btnNext"
  738. $btnNext.Size = '30, 25'
  739. $btnNext.TabIndex = 57
  740. $btnNext.Text = ">"
  741. $btnNext.UseVisualStyleBackColor = $True
  742. $btnNext.Visible = $False
  743. $btnNext.add_Click($btnNext_Click)
  744. #
  745. # btnPrev
  746. #
  747. $btnPrev.Location = '410, 0'
  748. $btnPrev.Name = "btnPrev"
  749. $btnPrev.Size = '30, 25'
  750. $btnPrev.TabIndex = 56
  751. $btnPrev.Text = "<"
  752. $btnPrev.UseVisualStyleBackColor = $True
  753. $btnPrev.Visible = $False
  754. $btnPrev.add_Click($btnPrev_Click)
  755. #
  756. # btnFirst
  757. #
  758. $btnFirst.Location = '379, 0'
  759. $btnFirst.Name = "btnFirst"
  760. $btnFirst.Size = '30, 25'
  761. $btnFirst.TabIndex = 55
  762. $btnFirst.Text = "<<"
  763. $btnFirst.UseVisualStyleBackColor = $True
  764. $btnFirst.Visible = $False
  765. $btnFirst.add_Click($btnFirst_Click)
  766. #
  767. # btnImportCSV
  768. #
  769. $btnImportCSV.Location = '303, 0'
  770. $btnImportCSV.Name = "btnImportCSV"
  771. $btnImportCSV.Size = '75, 25'
  772. $btnImportCSV.TabIndex = 54
  773. $btnImportCSV.Text = "Import CSV"
  774. $btnImportCSV.UseVisualStyleBackColor = $True
  775. $btnImportCSV.Visible = $False
  776. $btnImportCSV.add_Click($btnImportCSV_Click)
  777. #
  778. # lvCSV
  779. #
  780. $lvCSV.FullRowSelect = $True
  781. $lvCSV.GridLines = $True
  782. $lvCSV.Location = '305, 35'
  783. $lvCSV.Name = "lvCSV"
  784. $lvCSV.Size = '1150, 535'
  785. $lvCSV.TabIndex = 53
  786. $lvCSV.UseCompatibleStateImageBehavior = $False
  787. $lvCSV.View = 'Details'
  788. $lvCSV.Visible = $False
  789. $lvCSV.add_SelectedIndexChanged($lvCSV_SelectedIndexChanged)
  790. #
  791. # txtUPN
  792. #
  793. $txtUPN.Anchor = 'Top, Left, Right'
  794. $txtUPN.Location = '118, 505'
  795. $txtUPN.Name = "txtUPN"
  796. $txtUPN.Size = '173, 20'
  797. $txtUPN.TabIndex = 51
  798. #
  799. # txtsAM
  800. #
  801. $txtsAM.Anchor = 'Top, Left, Right'
  802. $txtsAM.Location = '118, 480'
  803. $txtsAM.Name = "txtsAM"
  804. $txtsAM.Size = '173, 20'
  805. $txtsAM.TabIndex = 50
  806. #
  807. # txtDN
  808. #
  809. $txtDN.Anchor = 'Top, Left, Right'
  810. $txtDN.Location = '118, 455'
  811. $txtDN.Name = "txtDN"
  812. $txtDN.Size = '173, 20'
  813. $txtDN.TabIndex = 49
  814. #
  815. # cboDepartment
  816. #
  817. $cboDepartment.Anchor = 'Top, Left, Right'
  818. $cboDepartment.FormattingEnabled = $True
  819. $cboDepartment.Location = '118, 235'
  820. $cboDepartment.Name = "cboDepartment"
  821. $cboDepartment.Size = '173, 21'
  822. $cboDepartment.TabIndex = 8
  823. #
  824. # labelUserPrincipalName
  825. #
  826. $labelUserPrincipalName.Location = '10, 505'
  827. $labelUserPrincipalName.Name = "labelUserPrincipalName"
  828. $labelUserPrincipalName.Size = '100, 23'
  829. $labelUserPrincipalName.TabIndex = 48
  830. $labelUserPrincipalName.Text = "userPrincipalName"
  831. $labelUserPrincipalName.TextAlign = 'MiddleLeft'
  832. #
  833. # labelSamAccountName
  834. #
  835. $labelSamAccountName.Location = '10, 480'
  836. $labelSamAccountName.Name = "labelSamAccountName"
  837. $labelSamAccountName.Size = '100, 23'
  838. $labelSamAccountName.TabIndex = 47
  839. $labelSamAccountName.Text = "samAccountName"
  840. $labelSamAccountName.TextAlign = 'MiddleLeft'
  841. #
  842. # labelDisplayName
  843. #
  844. $labelDisplayName.Location = '10, 455'
  845. $labelDisplayName.Name = "labelDisplayName"
  846. $labelDisplayName.Size = '100, 23'
  847. $labelDisplayName.TabIndex = 46
  848. $labelDisplayName.Text = "Display Name"
  849. $labelDisplayName.TextAlign = 'MiddleLeft'
  850. #
  851. # SB
  852. #
  853. $SB.Location = '0, 575'
  854. $SB.Name = "SB"
  855. $SB.Size = '304, 22'
  856. $SB.TabIndex = 45
  857. $SB.Text = "Ready"
  858. #
  859. # cboSite
  860. #
  861. $cboSite.Anchor = 'Top, Left, Right'
  862. $cboSite.FormattingEnabled = $True
  863. $cboSite.Location = '118, 320'
  864. $cboSite.Name = "cboSite"
  865. $cboSite.Size = '173, 21'
  866. $cboSite.TabIndex = 11
  867. $cboSite.add_SelectedIndexChanged($cboSite_SelectedIndexChanged)
  868. #
  869. # labelSite
  870. #
  871. $labelSite.Location = '10, 320'
  872. $labelSite.Name = "labelSite"
  873. $labelSite.Size = '100, 23'
  874. $labelSite.TabIndex = 44
  875. $labelSite.Text = "Site"
  876. $labelSite.TextAlign = 'MiddleLeft'
  877. #
  878. # cboDescription
  879. #
  880. $cboDescription.Anchor = 'Top, Left, Right'
  881. $cboDescription.FormattingEnabled = $True
  882. $cboDescription.Location = '118, 210'
  883. $cboDescription.Name = "cboDescription"
  884. $cboDescription.Size = '173, 21'
  885. $cboDescription.TabIndex = 7
  886. #
  887. # txtPassword
  888. #
  889. $txtPassword.Anchor = 'Top, Left, Right'
  890. $txtPassword.Location = '118, 547'
  891. $txtPassword.Name = "txtPassword"
  892. $txtPassword.Size = '173, 20'
  893. $txtPassword.TabIndex = 16
  894. $txtPassword.UseSystemPasswordChar = $True
  895. #
  896. # labelPassword
  897. #
  898. $labelPassword.Location = '10, 545'
  899. $labelPassword.Name = "labelPassword"
  900. $labelPassword.Size = '100, 23'
  901. $labelPassword.TabIndex = 41
  902. $labelPassword.Text = "Password"
  903. $labelPassword.TextAlign = 'MiddleLeft'
  904. #
  905. # cboDomain
  906. #
  907. $cboDomain.Anchor = 'Top, Left, Right'
  908. $cboDomain.FormattingEnabled = $True
  909. $cboDomain.Location = '118, 35'
  910. $cboDomain.Name = "cboDomain"
  911. $cboDomain.Size = '173, 21'
  912. $cboDomain.TabIndex = 1
  913. $cboDomain.add_SelectedIndexChanged($cboDomain_SelectedIndexChanged)
  914. #
  915. # labelCurrentDomain
  916. #
  917. $labelCurrentDomain.Location = '10, 35'
  918. $labelCurrentDomain.Name = "labelCurrentDomain"
  919. $labelCurrentDomain.Size = '100, 23'
  920. $labelCurrentDomain.TabIndex = 39
  921. $labelCurrentDomain.Text = "Current Domain"
  922. $labelCurrentDomain.TextAlign = 'MiddleLeft'
  923. #
  924. # txtPostalCode
  925. #
  926. $txtPostalCode.Anchor = 'Top, Left, Right'
  927. $txtPostalCode.Location = '118, 420'
  928. $txtPostalCode.Name = "txtPostalCode"
  929. $txtPostalCode.Size = '173, 20'
  930. $txtPostalCode.TabIndex = 15
  931. #
  932. # txtState
  933. #
  934. $txtState.Anchor = 'Top, Left, Right'
  935. $txtState.Location = '118, 395'
  936. $txtState.Name = "txtState"
  937. $txtState.Size = '173, 20'
  938. $txtState.TabIndex = 14
  939. #
  940. # txtCity
  941. #
  942. $txtCity.Anchor = 'Top, Left, Right'
  943. $txtCity.Location = '118, 370'
  944. $txtCity.Name = "txtCity"
  945. $txtCity.Size = '173, 20'
  946. $txtCity.TabIndex = 13
  947. #
  948. # txtStreetAddress
  949. #
  950. $txtStreetAddress.Anchor = 'Top, Left, Right'
  951. $txtStreetAddress.Location = '118, 345'
  952. $txtStreetAddress.Name = "txtStreetAddress"
  953. $txtStreetAddress.Size = '173, 20'
  954. $txtStreetAddress.TabIndex = 12
  955. #
  956. # txtOffice
  957. #
  958. $txtOffice.Anchor = 'Top, Left, Right'
  959. $txtOffice.Location = '118, 160'
  960. $txtOffice.Name = "txtOffice"
  961. $txtOffice.Size = '173, 20'
  962. $txtOffice.TabIndex = 5
  963. #
  964. # txtCompany
  965. #
  966. $txtCompany.Anchor = 'Top, Left, Right'
  967. $txtCompany.Location = '118, 260'
  968. $txtCompany.Name = "txtCompany"
  969. $txtCompany.Size = '173, 20'
  970. $txtCompany.TabIndex = 9
  971. #
  972. # txtTitle
  973. #
  974. $txtTitle.Anchor = 'Top, Left, Right'
  975. $txtTitle.Location = '118, 185'
  976. $txtTitle.Name = "txtTitle"
  977. $txtTitle.Size = '173, 20'
  978. $txtTitle.TabIndex = 6
  979. #
  980. # txtOfficePhone
  981. #
  982. $txtOfficePhone.Anchor = 'Top, Left, Right'
  983. $txtOfficePhone.Location = '118, 285'
  984. $txtOfficePhone.Name = "txtOfficePhone"
  985. $txtOfficePhone.Size = '173, 20'
  986. $txtOfficePhone.TabIndex = 10
  987. #
  988. # txtLastName
  989. #
  990. $txtLastName.Anchor = 'Top, Left, Right'
  991. $txtLastName.Location = '118, 135'
  992. $txtLastName.Name = "txtLastName"
  993. $txtLastName.Size = '173, 20'
  994. $txtLastName.TabIndex = 4
  995. $txtLastName.add_TextChanged($txtName_TextChanged)
  996. #
  997. # cboPath
  998. #
  999. $cboPath.Anchor = 'Top, Left, Right'
  1000. $cboPath.FormattingEnabled = $True
  1001. $cboPath.Location = '45, 65'
  1002. $cboPath.Name = "cboPath"
  1003. $cboPath.Size = '247, 21'
  1004. $cboPath.TabIndex = 2
  1005. #
  1006. # labelOU
  1007. #
  1008. $labelOU.Location = '10, 65'
  1009. $labelOU.Name = "labelOU"
  1010. $labelOU.Size = '36, 23'
  1011. $labelOU.TabIndex = 26
  1012. $labelOU.Text = "OU"
  1013. $labelOU.TextAlign = 'MiddleLeft'
  1014. #
  1015. # txtFirstName
  1016. #
  1017. $txtFirstName.Anchor = 'Top, Left, Right'
  1018. $txtFirstName.Location = '118, 110'
  1019. $txtFirstName.Name = "txtFirstName"
  1020. $txtFirstName.Size = '173, 20'
  1021. $txtFirstName.TabIndex = 3
  1022. $txtFirstName.add_TextChanged($txtName_TextChanged)
  1023. #
  1024. # labelPostalCode
  1025. #
  1026. $labelPostalCode.Location = '10, 420'
  1027. $labelPostalCode.Name = "labelPostalCode"
  1028. $labelPostalCode.Size = '100, 23'
  1029. $labelPostalCode.TabIndex = 24
  1030. $labelPostalCode.Text = "Postal Code"
  1031. $labelPostalCode.TextAlign = 'MiddleLeft'
  1032. #
  1033. # labelState
  1034. #
  1035. $labelState.Location = '10, 395'
  1036. $labelState.Name = "labelState"
  1037. $labelState.Size = '100, 23'
  1038. $labelState.TabIndex = 23
  1039. $labelState.Text = "State"
  1040. $labelState.TextAlign = 'MiddleLeft'
  1041. #
  1042. # labelCity
  1043. #
  1044. $labelCity.Location = '10, 370'
  1045. $labelCity.Name = "labelCity"
  1046. $labelCity.Size = '100, 23'
  1047. $labelCity.TabIndex = 22
  1048. $labelCity.Text = "City"
  1049. $labelCity.TextAlign = 'MiddleLeft'
  1050. #
  1051. # labelStreetAddress
  1052. #
  1053. $labelStreetAddress.Location = '10, 345'
  1054. $labelStreetAddress.Name = "labelStreetAddress"
  1055. $labelStreetAddress.Size = '100, 23'
  1056. $labelStreetAddress.TabIndex = 21
  1057. $labelStreetAddress.Text = "Street Address"
  1058. $labelStreetAddress.TextAlign = 'MiddleLeft'
  1059. #
  1060. # labelOffice
  1061. #
  1062. $labelOffice.Location = '10, 160'
  1063. $labelOffice.Name = "labelOffice"
  1064. $labelOffice.Size = '100, 23'
  1065. $labelOffice.TabIndex = 20
  1066. $labelOffice.Text = "Office"
  1067. $labelOffice.TextAlign = 'MiddleLeft'
  1068. #
  1069. # labelCompany
  1070. #
  1071. $labelCompany.Location = '10, 260'
  1072. $labelCompany.Name = "labelCompany"
  1073. $labelCompany.Size = '100, 23'
  1074. $labelCompany.TabIndex = 19
  1075. $labelCompany.Text = "Company"
  1076. $labelCompany.TextAlign = 'MiddleLeft'
  1077. #
  1078. # labelDepartment
  1079. #
  1080. $labelDepartment.Location = '10, 235'
  1081. $labelDepartment.Name = "labelDepartment"
  1082. $labelDepartment.Size = '100, 23'
  1083. $labelDepartment.TabIndex = 18
  1084. $labelDepartment.Text = "Department"
  1085. $labelDepartment.TextAlign = 'MiddleLeft'
  1086. #
  1087. # labelTitle
  1088. #
  1089. $labelTitle.Location = '10, 185'
  1090. $labelTitle.Name = "labelTitle"
  1091. $labelTitle.Size = '100, 23'
  1092. $labelTitle.TabIndex = 17
  1093. $labelTitle.Text = "Title"
  1094. $labelTitle.TextAlign = 'MiddleLeft'
  1095. #
  1096. # btnSubmit
  1097. #
  1098. $btnSubmit.Location = '216, 0'
  1099. $btnSubmit.Name = "btnSubmit"
  1100. $btnSubmit.Size = '75, 25'
  1101. $btnSubmit.TabIndex = 17
  1102. $btnSubmit.Text = "Submit"
  1103. $btnSubmit.UseVisualStyleBackColor = $True
  1104. $btnSubmit.add_Click($btnSubmit_Click)
  1105. #
  1106. # labelDescription
  1107. #
  1108. $labelDescription.Location = '10, 210'
  1109. $labelDescription.Name = "labelDescription"
  1110. $labelDescription.Size = '100, 23'
  1111. $labelDescription.TabIndex = 15
  1112. $labelDescription.Text = "Description"
  1113. $labelDescription.TextAlign = 'MiddleLeft'
  1114. #
  1115. # labelOfficePhone
  1116. #
  1117. $labelOfficePhone.Location = '10, 285'
  1118. $labelOfficePhone.Name = "labelOfficePhone"
  1119. $labelOfficePhone.Size = '100, 23'
  1120. $labelOfficePhone.TabIndex = 14
  1121. $labelOfficePhone.Text = "Office Phone"
  1122. $labelOfficePhone.TextAlign = 'MiddleLeft'
  1123. #
  1124. # labelLastName
  1125. #
  1126. $labelLastName.Location = '10, 135'
  1127. $labelLastName.Name = "labelLastName"
  1128. $labelLastName.Size = '100, 23'
  1129. $labelLastName.TabIndex = 13
  1130. $labelLastName.Text = "Last Name"
  1131. $labelLastName.TextAlign = 'MiddleLeft'
  1132. #
  1133. # labelFirstName
  1134. #
  1135. $labelFirstName.Location = '10, 110'
  1136. $labelFirstName.Name = "labelFirstName"
  1137. $labelFirstName.Size = '100, 23'
  1138. $labelFirstName.TabIndex = 12
  1139. $labelFirstName.Text = "First Name"
  1140. $labelFirstName.TextAlign = 'MiddleLeft'
  1141. #
  1142. # menustrip1
  1143. #
  1144. [void]$menustrip1.Items.Add($fileToolStripMenuItem)
  1145. $menustrip1.Location = '0, 0'
  1146. $menustrip1.Name = "menustrip1"
  1147. $menustrip1.Size = '304, 24'
  1148. $menustrip1.TabIndex = 52
  1149. $menustrip1.Text = "menustrip1"
  1150. #
  1151. # fileToolStripMenuItem
  1152. #
  1153. [void]$fileToolStripMenuItem.DropDownItems.Add($formMode)
  1154. [void]$fileToolStripMenuItem.DropDownItems.Add($CreateCSVTemplate)
  1155. [void]$fileToolStripMenuItem.DropDownItems.Add($MenuExit)
  1156. $fileToolStripMenuItem.Name = "fileToolStripMenuItem"
  1157. $fileToolStripMenuItem.Size = '37, 20'
  1158. $fileToolStripMenuItem.Text = "File"
  1159. #
  1160. # formMode
  1161. #
  1162. $formMode.Name = "formMode"
  1163. $formMode.Size = '185, 22'
  1164. $formMode.Text = "CSV Mode"
  1165. $formMode.add_Click($formMode_Click)
  1166. #
  1167. # CSVTemplate
  1168. #
  1169. $CSVTemplate.CheckPathExists = $False
  1170. $CSVTemplate.DefaultExt = "csv"
  1171. $CSVTemplate.FileName = "ANUCusers.csv"
  1172. $CSVTemplate.Filter = "CSV Files|*.csv|All Files|*.*"
  1173. $CSVTemplate.ShowHelp = $True
  1174. $CSVTemplate.Title = "Create CSV Template For ANUC"
  1175. $CSVTemplate.add_FileOk($CSVTemplate_FileOk)
  1176. #
  1177. # OFDImportCSV
  1178. #
  1179. $OFDImportCSV.FileName = "C:\ANUC\AnucUsers.csv"
  1180. $OFDImportCSV.ShowHelp = $True
  1181. #
  1182. # CreateCSVTemplate
  1183. #
  1184. $CreateCSVTemplate.Name = "CreateCSVTemplate"
  1185. $CreateCSVTemplate.Size = '185, 22'
  1186. $CreateCSVTemplate.Text = "Create CSV Template"
  1187. $CreateCSVTemplate.add_Click($createTemplateToolStripMenuItem_Click)
  1188. #
  1189. # MenuExit
  1190. #
  1191. $MenuExit.Name = "MenuExit"
  1192. $MenuExit.Size = '185, 22'
  1193. $MenuExit.Text = "Exit"
  1194. $MenuExit.add_Click($MenuExit_Click)
  1195. #endregion Generated Form Code
  1196.  
  1197. #----------------------------------------------
  1198.  
  1199. #Save the initial state of the form
  1200. $InitialFormWindowState = $formMain.WindowState
  1201. #Init the OnLoad event to correct the initial state of the form
  1202. $formMain.add_Load($Form_StateCorrection_Load)
  1203. #Clean up the control events
  1204. $formMain.add_FormClosed($Form_Cleanup_FormClosed)
  1205. #Show the Form
  1206. return $formMain.ShowDialog()
  1207.  
  1208. } #End Function
  1209.  
  1210. #Call OnApplicationLoad to initialize
  1211. if((OnApplicationLoad) -eq $true)
  1212. {
  1213. #Call the form
  1214. Call-ANUC_pff | Out-Null
  1215. #Perform cleanup
  1216. OnApplicationExit
  1217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement