![]() |
VOOZH | about |
The CData Cmdlets for Azure Active Directory are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Azure Active Directory.
The Cmdlets are not only a PowerShell interface to Azure Active Directory, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Azure Active Directory data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Azure Active Directory. To access Azure Active Directory data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Azure Active Directory.
Once you have acquired the necessary connection properties, accessing Azure Active Directory data in PowerShell can be enabled in three steps.
Azure Active Directory uses the OAuth authentication standard. To authenticate using OAuth, create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the OAuth section in the Help documentation for an authentication guide.
Install the module:
Install-Module AzureADCmdlets
Connect:
$azuread = Connect-AzureAD -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$isverified = "TRUE" $domains = Select-AzureAD -Connection $azuread -Table "Domains" -Where "isVerified = `'$isVerified`'" $domains
You can also use the Invoke-AzureAD cmdlet to execute SQL commands:
$domains = Invoke-AzureAD -Connection $azuread -Query 'SELECT * FROM Domains WHERE isVerified = @isVerified' -Params @{'@isVerified'='TRUE'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Azure Active Directory\lib\System.Data.CData.AzureAD.dll")
Connect to Azure Active Directory:
$conn= New-Object System.Data.CData.AzureAD.AzureADConnection("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the AzureADDataAdapter, execute an SQL query, and output the results:
$sql="SELECT id, availabilityStatus from Domains"
$da= New-Object System.Data.CData.AzureAD.AzureADDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.availabilitystatus
}
Update-AzureAD -Connection $AzureAD -Columns @('id','availabilityStatus') -Values @('Myid', 'MyavailabilityStatus') -Table Domains -Id "MyId"
$cmd = New-Object System.Data.CData.AzureAD.AzureADCommand("UPDATE Domains SET isVerified='TRUE' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureAD.AzureADParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-AzureAD -Connection $AzureAD -Table Domains -Columns @("id", "availabilityStatus") -Values @("Myid", "MyavailabilityStatus")
$cmd = New-Object System.Data.CData.AzureAD.AzureADCommand("INSERT INTO Domains (isVerified) VALUES (@myisVerified)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureAD.AzureADParameter("@myisVerified","TRUE")))
$cmd.ExecuteNonQuery()
Remove-AzureAD -Connection $AzureAD -Table "Domains" -Id "MyId"
$cmd = New-Object System.Data.CData.AzureAD.AzureADCommand("DELETE FROM Domains WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureAD.AzureADParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Azure Active Directory Data Provider to get started:
Download NowLearn more:
👁 Azure Active Directory IconRapidly create and deploy powerful .NET applications that integrate with Azure Active Directory.