New AD User automation - Make functions or not

I am looking to automate creation of new AD Users from a csv. I need to assign a UPN suffix, I’m struggling to decide if to make that into a separate function or module, it is a simple task but after reading Powershell scriping and toolmaking it makes a point to make tools that are testable and only do one thing. Is this concept applicable here? example below, I haven’t finished the switch statement, thats just a placeholder. I find that with every task I need to do I keep thinking about the concept of tools even though these sub tasks aren’t really going to be used anywhere else and they are pretty basic things.

If you have any other comment on the script please feel free to do so.

[CmdletBinding()]
param (
    #Path to folder that contains new user csv files
    [Parameter()]
    [string]
    $path
)

$UserList = Import-Csv -Path $path

foreach ($User in $UserList) {

    #Set the UPN Suffix to be used in the UserPrincipalName
    switch ($user.department) {
        condition { $UPNSuffix =  }

        
      } #switch   

    $Attributes = @{

        Name              = "$($User.firstname) $($User.surname)"
        DisplayName       = "$($User.firstname) $($User.surname)"
        UserPrincipalName = "$($User.firstname).$($User.surname)$UPNSuffix"
        SamAccountName    = "$($User.firstname).$($User.surname)"

        GivenName         = $User.firstname
        Surname           = $User.surname

        Company           = $User.Company
        Department        = $User.Department
        Title             = $User.Title

        Description       = $user.Description
        Manager           = $user.Manager
        Office            = $user.Office


    }

    New-ADUser @Attributes

} #foreach $user in $UserList

At the end of the day it is up to you if you have other scripts or code where you could re-use this or that particular function or code. If the chances are nearly not existing it wouldn’t make that much sense to create a function or even a module for a sinple step. And if it’s just about providing a string via a variable I wouldn’t think twice about creating a separate function for it. :wink:

Thanks, for your feedback :slight_smile: