cloudfil.ch Cloud - First in Line

Azure AD – Bulk Users Import with Powershell (Special Chars)

Bulk Users Import with Umlauts

Switzerland German, also known as Swiss German or Schwyzerdütsch, is a variety of German spoken in Switzerland. It is a High German language, closely related to standard German, but with a number of distinctive characteristics and dialects. (Bulk Users Import with Powershell)

In Switzerland German, as in standard German, the umlauts ä, ö, and ü are used to represent certain vowel sounds. The umlauts are written as ae, oe, and ue when the letters are not available, such as in ASCII text or when using certain fonts.

Here are some examples of words with umlauts in Switzerland German:

  • Männer (men)
  • Möbel (furniture)
  • Bücher (books)

In addition to the umlauts, Switzerland German also uses a number of special characters and diacritics, such as the sharp s (ß) and the eszett (ẞ), which is used to represent the sound of the “ss” combination in certain contexts.

To type Switzerland German special characters and umlauts on a computer, you can use the relevant keys on your keyboard or insert the characters using a character map or symbol tool. Some software programs and applications may also provide an option to insert special characters and umlauts using a menu or toolbar.

PowerShell Script with automatic Replacement

Here is an example script which imports users from a CSV file, automatically replaces special characters (umlauts) in the name and automatically records the users in the system. There is also the possibility to add license or other groups. For the import a default password is assigned FirstnamePassword$

<!-- wp:code {"fontSize":"small"} -->
<pre class="wp-block-code has-small-font-size"><code>Function Replace-Umlaut {

    param (
       &#91;string]$Text 
    )
 
    # create HashTable with replace map
    $characterMap = @{}
    $characterMap.(&#91;Int]&#91;Char]'ä') = "a"
    $characterMap.(&#91;Int]&#91;Char]'ö') = "o"
	$characterMap.(&#91;Int]&#91;Char]'ó') = "o"
    $characterMap.(&#91;Int]&#91;Char]'ü') = "u"
    $characterMap.(&#91;Int]&#91;Char]'ß') = "ss"
    $characterMap.(&#91;Int]&#91;Char]'Ä') = "A"
    $characterMap.(&#91;Int]&#91;Char]'Ü') = "U"
    $characterMap.(&#91;Int]&#91;Char]'Ö') = "O"
    $characterMap.(&#91;Int]&#91;Char]'é') = "e"
    $characterMap.(&#91;Int]&#91;Char]'ë') = "e"
    $characterMap.(&#91;Int]&#91;Char]'è') = "e"
    $characterMap.(&#91;Int]&#91;Char]'á') = "a"
	$characterMap.(&#91;Int]&#91;Char]' ') = "-"
    
    # Replace chars
    ForEach ($key in $characterMap.Keys) {
        $Text = $Text -creplace (&#91;Char]$key),$characterMap&#91;$key] 
    }
 
     # return result
     $Text
}

# Define Paramaters
$strAdmin = "administrator@TENANT.onmicrosoft.com"
$Directory = "edu.DOMAIN"
$CsvFilePath = "./Users.csv"

# Login zu AzureAD
$cred = Get-Credential -UserName $strAdmin -Message "Login to AzureAD"
Connect-AzureAD -Credential $cred

# Get the CSV 
$NewUsers = import-csv -Path $CsvFilePath -Encoding Default #CSV Westeurop ischen Context Encoded

# Get Groups
$AAD_LIC_Users = Get-AzureADGroup -SearchString "LIC_Users"
$AAD_PersonalOwnedUsers = Get-AzureADGroup -Filter "DisplayName eq 'AAD_Users'"

# Loop trough all Users 
ForEach ($u in $NewUsers) { 

    $UserPrincipalName = Replace-Umlaut($u.Firstname + "." + $u.LastName + "@" + $Directory)
    $DisplayName = $u.Firstname + " " + $u.Lastname
    $MailNickName = Replace-Umlaut($u.Firstname + "." + $u.LastName)

	$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
	$DefaultPw = "$(Replace-Umlaut($u.Firstname))Password$"
	$PasswordProfile.Password = $DefaultPw

	Write-Host $UserPrincipalName " - " $DisplayName " - " $u.FirstName " - " $u.LastName " - " $MailNickName " - " $PasswordProfile
    try {
        New-AzureADUser -UserPrincipalName $UserPrincipalName -AccountEnabled $true -DisplayName $DisplayName -GivenName $u.FirstName -Surname $u.LastName -MailNickName $MailNickName -PasswordProfile $PasswordProfile
    } catch {
        Write-Host "Already Exist or Error `r`n $_.Exception.Message"
    }
	
    $ADuser = Get-AzureADUser -ObjectId "$UserPrincipalName"

    try {
	
		#Assign Groups to new User
        Add-AzureADGroupMember -ObjectId $AAD_PersonalOwnedUsers.ObjectID -RefObjectId $ADuser.ObjectID 
        Add-AzureADGroupMember -ObjectId $AAD_LIC_Users.ObjectID -RefObjectId $ADuser.ObjectID 

    } catch {
        Write-Host "User is already in Group"
    }
}</code></pre>
<!-- /wp:code -->

How does the CSV File looks like

Lastname,Firstname
Gamper,Hans
Kàttel,Jannik
Merkurt,Damian
Lüönd,Kim
Otter,Remo
Bärgler,Maria
Inderbitzin,Karl
Jöckel,Lim
Küttel,Sia
Rebelo dos Santos,Kurt
Kircimi,ézden

Conclusion

There are a few reasons why you might want to import Azure AD users using PowerShell:

  1. Efficient bulk user management: If you have a large number of users to manage, using PowerShell can be more efficient than manually creating each user in the Azure AD portal.
  2. Automation: You can use PowerShell scripts to automate the process of importing users, which can save time and reduce the potential for errors.
  3. Customization: Using PowerShell allows you to customize the import process to meet your specific needs. For example, you can use PowerShell to assign specific roles or groups to users as part of the import process.
  4. Integration with other systems: If you have a system that generates user information (such as an HR database), you can use PowerShell to integrate with that system and import the user information automatically.

Overall, using PowerShell to import Azure AD users can be a useful tool for efficiently managing and automating the process of creating and maintaining users in your Azure AD tenant.

Nico Wyss

Writer & Blogger

Be the First in Line!

Sign up for a Newsletter.

You have been successfully Subscribed! Ops! Something went wrong, please try again.

© 2023 Copyright