Advertisement
Guest User

Untitled

a guest
Dec 4th, 2022
1,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1.  
  2. #Import the Active Directory module
  3.  
  4. Import-Module ActiveDirectory
  5.  
  6. #Create a GUI window
  7.  
  8. $Window = New-Object System.Windows.Forms.Form
  9.  
  10. #Set the window title
  11.  
  12. $Window.Text = "Create Active Directory and Exchange Account"
  13.  
  14. #Set the window size
  15.  
  16. $Window.Size = New-Object System.Drawing.Size(500,300)
  17.  
  18. #Create a label for the username
  19.  
  20. $UsernameLabel = New-Object System.Windows.Forms.Label
  21. $UsernameLabel.Text = "Username:"
  22. $UsernameLabel.Location = New-Object System.Drawing.Size(10,10)
  23. $Window.Controls.Add($UsernameLabel)
  24.  
  25. #Create a textbox for the username
  26.  
  27. $UsernameTextbox = New-Object System.Windows.Forms.TextBox
  28. $UsernameTextbox.Location = New-Object System.Drawing.Size(100,10)
  29. $Window.Controls.Add($UsernameTextbox)
  30.  
  31. #Create a checkbox for the exchange account
  32.  
  33. $ExchangeCheckbox = New-Object System.Windows.Forms.CheckBox
  34. $ExchangeCheckbox.Text = "Create Exchange Account"
  35. $ExchangeCheckbox.Location = New-Object System.Drawing.Size(10,40)
  36. $Window.Controls.Add($ExchangeCheckbox)
  37.  
  38. #Create a checkbox for the Skype for
  39. Business account
  40.  
  41. $SkypeCheckbox = New-Object System.Windows.Forms.CheckBox
  42. $SkypeCheckbox.Text = "Create Skype for Business Account"
  43. $SkypeCheckbox.Location = New-Object System.Drawing.Size(10,70)
  44. $Window.Controls.Add($SkypeCheckbox)
  45.  
  46. #Create a button to create the accounts
  47.  
  48. $CreateButton = New-Object System.Windows.Forms.Button
  49. $CreateButton.Text = "Create"
  50. $CreateButton.Location = New-Object System.Drawing.Size(10,100)
  51. $CreateButton.Size = New-Object System.Drawing.Size(100,25)
  52. $CreateButton.Add_Click({
  53. # Get the username from the textbox
  54. $Username = $UsernameTextbox.Text
  55. # Check if the username is not empty
  56. if($Username -ne "") {
  57. # Create the active directory account
  58. New-ADUser -Name $Username -SamAccountName $Username -UserPrincipalName $Username@domain.com -AccountPassword (ConvertTo-SecureString -AsPlainText "password" -Force) -Enabled $True
  59.  
  60. # Check if the exchange account checkbox is checked
  61. if($ExchangeCheckbox.Checked) {
  62. # Create the exchange account
  63. New-Mailbox -Name $Username -UserPrincipalName $Username@domain.com -Password (ConvertTo-SecureString -AsPlainText "password" -Force) -Database "Exchange Mailbox Database"
  64. }
  65.  
  66. # Check if the Skype for Business account checkbox is checked
  67. if($SkypeCheckbox.Checked) {
  68. # Create the Skype for Business account
  69. New-CsOnlineUser -UserPrincipalName $Username@domain.com -DisplayName $Username -RegistrarPool "skypepool.domain.com"
  70. }
  71.  
  72. # Show a message that the accounts have been created
  73. [System.Windows.Forms
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement