< Home

Combining PowerShell Scripts

Jan 2, 2019

There are times when you find yourself executing one script, then another, then another. New user onboarding comes to mind. Many admins know the process well: make active directory account, add appropriate security groups, fill in account details, add an email license, and on and on. While some processes can be done in parallel, it is still time consuming and some scripts can’t be run until others are complete. I offer the following solution; think of your many processes as a single larger process.

Onboarding means different things to different departments. Human resources have a list of documents to sign, management sets up training sessions, and IT goes on an account creation frenzy. Each of these pieces are all important, but in the IT department, there’s no reason to segregate many of our tasks. I recently worked up a PowerShell script to turn a 30-45 minutes manual processes into 3 minutes of automation.

Logically I know that onboarding isn’t an identical operation for all our users. Some users only need some accounts or access. I started thinking about it as one larger process that only needed small parts fulfilled and combined my scripts together will a simple opt-out option. Here’s a snippet of my opt-out logic for the option to add an Office 365 license to their domain account:

# Admin confirmation email account creation
Confirmation = 0
$response = Read-Host "Does this user need an e-mail license? [y/n]"
if($response -like "n") {
    $Confirmation++
    Write-host "Aborting..."
}

while($confirmation -ne '1'){
    # Manual sync AD to Office 365
    Write-host "Syncing AD to Office 365... Enter your admin credentials to continue"
    Write-host "EXAMPLE: username@domain.com"
    Write-host "`n"

    $Credential = Get-Credential 
}

It’s a simple method of bypassing a process that may not be necessary. In this way, you can set yourself for success by combining your scripts to work together cohesively. Keep the mindset that your tasks may be smaller pieces of a larger process and see what you can do to make your scripts to the hard work.&nbsp;</p>

Greg Wilson

Overly dramatic IT Professional