to extract users from Azure SQL to Azure AD with the fields in the SQL tables
Achieving this you have to follow the below steps.
- Get the user table data from the SQL table
- Export the user data into csv file.
- create the users in Azure AD using the csv file.
You can use the below script to export Azure SQL Table data. Then exported data can be saved in a csv file.
Import-Module sqlps
$SQLServer = "<Your Azure SQL server>"
$DatabaseName = "<Database Name>"
$ExportLocation = "<Path to Export>"
$ResourceGroupName ="<Your resource group name>"
#Select Database
Get-AzureRmSqlDatabase -ServerName $SQLServer -ResourceGroupName $ResourceGroupName | select $DatabaseName
# Get Server Instance
$ServerInstance = Get-AzureRmSqlServer -ResourceGroupName $ResourceGroupName | where {$_.ServerName -eq $SQLServer}
$params = @{
'Database' = $DatabaseName
'ServerInstance' = $ServerInstance
'Username' = '<userName>'
'Password' = '<Password>'
'Query' = 'SELECT * FROM UsersTable'
}
$userResult = Invoke-Sqlcmd @params
$result |export-csv "$ExportLocation$userinfo.csv" -notypeinformation
Fetching all information from table
# Get user information from table
$Tables = (Get-SqlDatabase -ServerInstance $ServerInstance -Name $DatabaseName).tables
foreach($table in $Tables) {
$SQLquery="select * from $($table)"
$result=invoke-sqlcmd -query $SQLquery -serverinstance $SQLServer -database $DatabaseName
Write-Host "Now Exporting Table $table"
$result |export-csv "$ExportLocation$($table.Name).csv" -notypeinformation
}
Or in an Azure portal -> Azure SQL Database -> Query Editor also you can export the csv file.

After exported the CSV file import the user information into Azure AD.
Refer Link 1 & Link 2 to import users into Azure AD