https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%20hero.png As a service desk analyst, setting up new employee accounts in Microsoft ActiveDirectory was a routine yet cumbersome task. Each account creation involved sending a confirmation email, leading to repetitive copying and pasting, often resulting in errors. Determined to streamline this process, I developed a PowerShell tool to automate email generation and account creation, significantly reducing time and errors.

Project Overview:

My tool utilizes WinForms to provide a user-friendly interface for a PowerShell script. By using an existing .eml file as a template, the script dynamically generates emails, replacing template placeholders with user-entered values. This approach minimizes copy-paste errors and emphasizes efficiency by reducing clicks and keystrokes.

Notable features include obtaining temporary user IDs without visiting proprietary webpages, auto-filling fields via Quest Active Directory Management Shell for PowerShell, and quickly accessing group policies for assigning Microsoft 365 licenses.

Development Process:

During development, I explored various PowerShell mail-sending methods and immersed myself in Windows.System.Forms to create the GUI. Among the options, I chose Outlook as it provided the flexibility to manually review and encrypt emails before sending, ensuring data security and compliance with organizational policies. Challenges arose due to limited access to Active Directory, necessitating the use of Quest Active Directory Management Shell. Overcoming these challenges was both frustrating and rewarding, leading to a robust solution tailored to available resources.

Technologies Used:

Demo:

The Existing Email Template

https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%20%201.PNG

The Windows Form GUI

https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%202.PNG

Autofill using qAD Connect

https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%205.gif

Web request for temp ID

https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%204.gif

Final Email

https://personalporfoliostorage.blob.core.windows.net/personalportfolio-images/Streamlining%20Onboarding%20A%20PowerShell%20Tool%20for%20New%20Account%20Creation%20Email%20Generation%203.PNG

Code Highlights:

  • Short code snippet of adding the OK button to the form and displaying the form
#GUI
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form
$form.Text = 'New Starter Email Form'
$form.Size = New-Object System.Drawing.Size(700,800)
$form.StartPosition = 'CenterScreen'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(245,700)
$okButton.Size = New-Object System.Drawing.Size(75,35)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$form.Topmost = $true

#focus
$form.Add_Shown({$TasktextBox.Select()})

$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{}
  • Creating the Outlook mail item
  $file2= 'C:\Scripts\NewStarterEmail\New Starter.msg';

    #Create email Item
    $outlook= New-Object -ComObject outlook.application;
    $msg= $outlook.createitemfromtemplate($file2);

    #Email headers
    $msg.To = $RequestorEmail;
    $msg.CC = $LineManager;
    $msg.Subject = $msg.Subject.Replace($defaults.NewStarter, $NewStarter);
    $msg.Display();
  • Active Directory Integration
try{
$qADUser= get-qadUser -identity $StartertextBox.Text;
$UnametextBox.Text = $qADUser.sAMAccountName
$EmailtextBox.Text = $qADUser.email
$pintextBox.Text = $qADUser.Name -replace '.*\(' -replace '\).*'
$qADManager = $qADUser | select -ExpandProperty manager
$qADManagerMail = get-qadUser -identity $qADManager | select -ExpandProperty mail
$LMtextBox.Text = $qADManagerMail
} catch {
           Write-Host "Failed: $(($PSItem.Exception.Message -split '\|')[-1])" -ForegroundColor Red
       }

Conclusion:

My PowerShell tool significantly enhances the efficiency of new employee onboarding by simplifying account creation and email generation. It optimizes the onboarding process, making it more streamlined and error-resistant. By my estimates, the process now takes between 5-10 minutes, compared to the previous 10-15 minutes, resulting in substantial time savings.

This project also provided me with an invaluable learning experience. With no prior experience in WinForms, diving into its intricacies was both challenging and rewarding. Additionally, interacting with Active Directory via scripting was a fascinating endeavor. The ability to create Outlook emails via PowerShell is a skill I’m grateful to have acquired, as I see its usefulness in future automation projects.