functions/New-BBUser.ps1


#Does not create a new one if one exists. This is how the API Works.
function New-BBUser
{
    [CmdletBinding(SupportsShouldProcess)]
    [Alias()]
    Param
    (
        [parameter(ValueFromPipelineByPropertyName)]$externalId,
        [parameter(ValueFromPipelineByPropertyName)]$dataSourceId = "",
        [parameter(ValueFromPipelineByPropertyName)]$userName = "",
        [parameter(ValueFromPipelineByPropertyName)]$studentId = "",
        [parameter(ValueFromPipelineByPropertyName)]$educationLevel = "",
        [parameter(ValueFromPipelineByPropertyName)]$gender = "",
        [parameter(ValueFromPipelineByPropertyName)]$birthDate = "",
        [parameter(ValueFromPipelineByPropertyName)]$institutionRoleIds = "",
        [parameter(ValueFromPipelineByPropertyName)]$systemRoleIds = "",
        [parameter(ValueFromPipelineByPropertyName)]$availability = "",
        [parameter(ValueFromPipelineByPropertyName)]$name = "",
        [parameter(ValueFromPipelineByPropertyName)]$job = "",
        [parameter(ValueFromPipelineByPropertyName)]$contact = "",
        [parameter(ValueFromPipelineByPropertyName)]$address = "",
        [parameter(ValueFromPipelineByPropertyName)]$locale = "",
        #[parameter(ValueFromPipelineByPropertyName)]$avatar = "",

        [string]$Password = '',
        [string]$Environment = 'Production'
    )

    Begin
    {


    }
    Process
    {
         if(!$Password){
            $Password = ([char[]]([char]33..[char]95) + ([char[]]([char]97..[char]126)) + 0..9 | sort {Get-Random})[0..12] -join ''
        }
        $Body = @{}
        if($externalId){$Body.Add('externalId', $externalId)}
        if($dataSourceId){$Body.Add('dataSourceId', $dataSourceId)}
        if($userName){$Body.Add('userName', $userName)}
        if($studentId){$Body.Add('studentId', $studentId)}
        if($educationLevel){$Body.Add('educationLevel', $educationLevel)}

        if($gender){$Body.Add('gender', $gender)}
        if($birthDate){$Body.Add('birthDate', $birthDate)}
        if($institutionRoleIds){$Body.Add('institutionRoleIds', $institutionRoleIds)}
        if($systemRoleIds){$Body.Add('systemRoleIds', $systemRoleIds)}
        if($availability){$Body.Add('availability', $availability)}
        if($name){$Body.Add('name', $name)}
        if($job){$Body.Add('job', $job)}
        if($contact){$Body.Add('contact', $contact)}
        if($address){$Body.Add('address', $address)}
        if($locale){$Body.Add('locale', $locale)}
        if($avatar){$Body.Add('avatar', $avatar)}
        $Body.Add('password', $Password)

        Invoke-BBRestMethod -API "/learn/api/public/v1/users"`
            -Method Post `
            -ContentType application/json `
            -Body $Body `
            -Environment $Environment
    }
    End
    {
    }
}