I have a csv file, params.csv, consisting of the following dummy data for instance:
"Victor Okwuemu","n939NekyPa8910","VictorO003_gmail.com#EXT#@Hegemongroup.onmicrosoft.com"
"Jackson Kiraly","n939Nek00O1yPa","JacksonK004_gmail.com#EXT#@Hegemongroup.onmicrosoft.com"
"Benson Thomas","n939Nek025yPa","bensonT005_gmail.com#EXT#@Hegemongroup.onmicrosoft.com"
I used a while loop to read each line and extract the strings in each line based on the comma into the variables: displayname, password and upn using these commands: $(echo $line | cut -d "," -f 1), $(echo $line | cut -d "," -f 2) and $(echo $line | cut -d "," -f 3) respectively as shown below:
file='params.csv'
while read line; do
displayName=$(echo $line | cut -d "," -f 1)
password=$(echo $line | cut -d "," -f 2)
upn=$(echo $line | cut -d "," -f 3)
var1="az ad user create --display-name"
var2="--password"
var3="--user-principal-name"
eval ${var1} ${displayName} ${var2} ${password} ${var3} ${upn}
done < $file
My goal is to pass the extracted strings into an Azure Active Directory CLI commands to create multiple users in Azure Active Directory tenant without using Azure portal.
The program loops, evaluates the first line and adds the user to my Azure active directory tenant, then fails to do for other lines in the the file. However, when I comment out the 'eval' line and echo the variables, the while loop goes through every line and and extracts all the strings for each line.
I have tried writing the commands in various other format as follows:
az ad user create --display-name "$displayName" --password "$password" --user-principal-name "$upn"
echo "az ad user create --display-name $displayName --password $password --user-principal-name $upn"
az ad user create --display-name $(echo $line | cut -d "," -f 1 | tr -d '"') --password $(echo $line | cut -d "," -f 2 | tr -d '"') --user-principal-name $(echo $line | cut -d "," -f 3 | tr -d '"')
All of these methods have failed to create the users as I expected. Any body with an idea on this? The problem here is that the while loop breaks after evaluating the first line in the file.