Functions/New-MgUserCustom.ps1


function New-MgUserCustom {

    Param (

        [parameter(mandatory = $true)][string]$UserPrincipalName,
        [string]$DisplayName,
        [string]$Password

    )

    # $UserPrincipalName = "test.$(Get-Random -Minimum 1 -Maximum 10000)@jaapterlouw.nl"
    # $DisplayName = "Test $(Get-Random -Minimum 1 -Maximum 10000)"
    # $Password = "$(Get-Random)1n3uow8efs@@!#"

    $Params = @{
        AccountEnabled    = $true
        DisplayName       = $DisplayName
        MailNickname      = "$(($UserPrincipalName).split("@")[0])"
        PasswordPolicies  = "DisablePasswordExpiration"
        PasswordProfile   = @{
            Password                      = $Password
            ForceChangePasswordNextSignIn = $false
        }
        PreferredLanguage = "nl-NL"
        UsageLocation     = "NL"
        UserPrincipalName = $UserPrincipalName
    }
    $Params

    New-MgUser @Params

}