Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import the Active Directory module
- Import-Module ActiveDirectory
- #Create a GUI window
- $Window = New-Object System.Windows.Forms.Form
- #Set the window title
- $Window.Text = "Create Active Directory and Exchange Account"
- #Set the window size
- $Window.Size = New-Object System.Drawing.Size(500,300)
- #Create a label for the username
- $UsernameLabel = New-Object System.Windows.Forms.Label
- $UsernameLabel.Text = "Username:"
- $UsernameLabel.Location = New-Object System.Drawing.Size(10,10)
- $Window.Controls.Add($UsernameLabel)
- #Create a textbox for the username
- $UsernameTextbox = New-Object System.Windows.Forms.TextBox
- $UsernameTextbox.Location = New-Object System.Drawing.Size(100,10)
- $Window.Controls.Add($UsernameTextbox)
- #Create a checkbox for the exchange account
- $ExchangeCheckbox = New-Object System.Windows.Forms.CheckBox
- $ExchangeCheckbox.Text = "Create Exchange Account"
- $ExchangeCheckbox.Location = New-Object System.Drawing.Size(10,40)
- $Window.Controls.Add($ExchangeCheckbox)
- #Create a checkbox for the Skype for
- Business account
- $SkypeCheckbox = New-Object System.Windows.Forms.CheckBox
- $SkypeCheckbox.Text = "Create Skype for Business Account"
- $SkypeCheckbox.Location = New-Object System.Drawing.Size(10,70)
- $Window.Controls.Add($SkypeCheckbox)
- #Create a button to create the accounts
- $CreateButton = New-Object System.Windows.Forms.Button
- $CreateButton.Text = "Create"
- $CreateButton.Location = New-Object System.Drawing.Size(10,100)
- $CreateButton.Size = New-Object System.Drawing.Size(100,25)
- $CreateButton.Add_Click({
- # Get the username from the textbox
- $Username = $UsernameTextbox.Text
- # Check if the username is not empty
- if($Username -ne "") {
- # Create the active directory account
- New-ADUser -Name $Username -SamAccountName $Username -UserPrincipalName $Username@domain.com -AccountPassword (ConvertTo-SecureString -AsPlainText "password" -Force) -Enabled $True
- # Check if the exchange account checkbox is checked
- if($ExchangeCheckbox.Checked) {
- # Create the exchange account
- New-Mailbox -Name $Username -UserPrincipalName $Username@domain.com -Password (ConvertTo-SecureString -AsPlainText "password" -Force) -Database "Exchange Mailbox Database"
- }
- # Check if the Skype for Business account checkbox is checked
- if($SkypeCheckbox.Checked) {
- # Create the Skype for Business account
- New-CsOnlineUser -UserPrincipalName $Username@domain.com -DisplayName $Username -RegistrarPool "skypepool.domain.com"
- }
- # Show a message that the accounts have been created
- [System.Windows.Forms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement