![]() |
VOOZH | about |
The CData Cmdlets for Microsoft Teams 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 Microsoft Teams.
The Cmdlets are not only a PowerShell interface to Microsoft Teams, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Microsoft Teams data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Microsoft Teams. To access Microsoft Teams data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Microsoft Teams.
Once you have acquired the necessary connection properties, accessing Microsoft Teams data in PowerShell can be enabled in three steps.
You can connect to MS Teams using the embedded OAuth connectivity. When you connect, the MS Teams OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.
Install the module:
Install-Module MSTeamsCmdlets
Connect:
$msteams = Connect-MSTeams -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$id = "Jq74mCczmFXk1tC10GB" $teams = Select-MSTeams -Connection $msteams -Table "Teams" -Where "Id = `'$Id`'" $teams
You can also use the Invoke-MSTeams cmdlet to execute SQL commands:
$teams = Invoke-MSTeams -Connection $msteams -Query 'SELECT * FROM Teams WHERE Id = @Id' -Params @{'@Id'='Jq74mCczmFXk1tC10GB'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Microsoft Teams\lib\System.Data.CData.MSTeams.dll")
Connect to Microsoft Teams:
$conn= New-Object System.Data.CData.MSTeams.MSTeamsConnection("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the MSTeamsDataAdapter, execute an SQL query, and output the results:
$sql="SELECT subject, location_displayName from Teams"
$da= New-Object System.Data.CData.MSTeams.MSTeamsDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.subject $_.location_displayname
}
Update-MSTeams -Connection $MSTeams -Columns @('subject','location_displayName') -Values @('Mysubject', 'Mylocation_displayName') -Table Teams -Id "MyId"
$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("UPDATE Teams SET Id='Jq74mCczmFXk1tC10GB' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MSTeams.MSTeamsParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-MSTeams -Connection $MSTeams -Table Teams -Columns @("subject", "location_displayName") -Values @("Mysubject", "Mylocation_displayName")
$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("INSERT INTO Teams (Id) VALUES (@myId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MSTeams.MSTeamsParameter("@myId","Jq74mCczmFXk1tC10GB")))
$cmd.ExecuteNonQuery()
Remove-MSTeams -Connection $MSTeams -Table "Teams" -Id "MyId"
$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("DELETE FROM Teams WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MSTeams.MSTeamsParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Microsoft Teams Data Provider to get started:
Download NowLearn more:
👁 Microsoft Teams IconRapidly create and deploy powerful .NET applications that integrate with Microsoft Teams.