Ready to get started?

Learn more about the CData ADO.NET Provider for Microsoft Teams or download a free trial:

Download Now

Automate Microsoft Teams Integration Tasks from PowerShell

Are you looking for a quick and easy way to access Microsoft Teams data from PowerShell? We show how to use the Cmdlets for Microsoft Teams and the CData ADO.NET Provider for Microsoft Teams to connect to Microsoft Teams data and synchronize, automate, download, and more.

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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Microsoft Teams API, 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.

After obtaining the needed connection properties, accessing Microsoft Teams data in PowerShell consists of three basic 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.

PowerShell

  1. Install the module:

    Install-Module MSTeamsCmdlets
  2. Connect:

    $msteams = Connect-MSTeams -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL"
  3. 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'}

ADO.NET

  1. 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")
  2. Connect to Microsoft Teams:

    $conn= New-Object System.Data.CData.MSTeams.MSTeamsConnection("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. 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 Microsoft Teams Data

PowerShell

Update-MSTeams -Connection $MSTeams -Columns @('subject','location_displayName') -Values @('Mysubject', 'Mylocation_displayName') -Table Teams -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("UPDATE Teams SET Id='Jq74mCczmFXk1tC10GB' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.MSTeams.MSTeamsParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Microsoft Teams Data

PowerShell

Add-MSTeams -Connection $MSTeams -Table Teams -Columns @("subject", "location_displayName") -Values @("Mysubject", "Mylocation_displayName")

ADO.NET

$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("INSERT INTO Teams (Id) VALUES (@myId)", $conn) $cmd.Parameters.Add(new System.Data.CData.MSTeams.MSTeamsParameter("@myId","Jq74mCczmFXk1tC10GB")) $cmd.ExecuteNonQuery()

Delete Microsoft Teams Data

PowerShell

Remove-MSTeams -Connection $MSTeams -Table "Teams" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.MSTeams.MSTeamsCommand("DELETE FROM Teams WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.MSTeams.MSTeamsParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()