8 Unified user creation

 

This chapter covers:

  • Using conditional logic to call a function.
  • Using Exchange cmdlets on any PC in your domain utilizing PSSessions.
  • Creating unique usernames to prevent duplicates
  • Unifying several scripts to create a user, email and default groups with a few questions.
  • Testing and optimizing your searches.

Up until now we have dealt with scripts that do very specific things.  They might help us create an email address, create a user, or transfer group memberships.  Each of these scripts are useful in their own right, but we’re interested in automation.  Why not create one script that does all of these things?

As we have seen, each of these scripts are a time savings in themselves.  It can take several minutes to create an Active Directory user by hand.  It can take dozens of clicks to duplicate group membership from one user to another.  Each of these scripts deserves a place in our ecosystem of scripts.  But one of the core concepts of automation is doing more with less.  If we could integrate some of the things we’ve done and weave them into a coherent script that did all of those things; that would save us even more!  Here we can create a unified user creation script.

This script will:

8.1 Project Code

8.2 Script Parameters

8.2.1 Mandatory Parameters

8.2.2 How we use Parameters in our Script

8.3 PSSession

8.3.1 New-PSSession

8.3.2 Get-PSSession

8.3.3 Import-PSSession

8.3.4 Remove-PSSession

8.3.5 How we use PSSessions in our Script

8.4 If not

8.4.1 How we use If Not in our Script

8.5 Get-Credential

8.5.1 How we use Get-Credential in our Script

8.6 Filtering performance

8.6.1 Measure-Command

8.6.2 Null values

8.6.3 Filtering Null Values

8.6.4 How we use NULL values in our Script

8.7 Summary