![]() |
VOOZH | about |
The CData Cmdlets for Microsoft Planner 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 Planner.
The Cmdlets are not only a PowerShell interface to Microsoft Planner, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Microsoft Planner data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Microsoft Planner. To access Microsoft Planner data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Microsoft Planner.
Once you have acquired the necessary connection properties, accessing Microsoft Planner data in PowerShell can be enabled in three steps.
You can connect without setting any connection properties for your user credentials. Below are the minimum connection properties required to connect.
When you connect the Driver opens the MS Planner OAuth endpoint in your default browser. Log in and grant permissions to the Driver. The Driver then completes the OAuth process.
Install the module:
Install-Module MicrosoftPlannerCmdlets
Connect:
$microsoftplanner = Connect-MicrosoftPlanner -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$taskid = "BCrvyMoiLEafem-3RxIESmUAHbLK" $tasks = Select-MicrosoftPlanner -Connection $microsoftplanner -Table "Tasks" -Where "TaskId = `'$TaskId`'" $tasks
You can also use the Invoke-MicrosoftPlanner cmdlet to execute SQL commands:
$tasks = Invoke-MicrosoftPlanner -Connection $microsoftplanner -Query 'SELECT * FROM Tasks WHERE TaskId = @TaskId' -Params @{'@TaskId'='BCrvyMoiLEafem-3RxIESmUAHbLK'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Microsoft Planner\lib\System.Data.CData.MicrosoftPlanner.dll")
Connect to Microsoft Planner:
$conn= New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerConnection("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the MicrosoftPlannerDataAdapter, execute an SQL query, and output the results:
$sql="SELECT TaskId, startDateTime from Tasks"
$da= New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.taskid $_.startdatetime
}
Update-MicrosoftPlanner -Connection $MicrosoftPlanner -Columns @('TaskId','startDateTime') -Values @('MyTaskId', 'MystartDateTime') -Table Tasks -Id "MyId"
$cmd = New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerCommand("UPDATE Tasks SET TaskId='BCrvyMoiLEafem-3RxIESmUAHbLK' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-MicrosoftPlanner -Connection $MicrosoftPlanner -Table Tasks -Columns @("TaskId", "startDateTime") -Values @("MyTaskId", "MystartDateTime")
$cmd = New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerCommand("INSERT INTO Tasks (TaskId) VALUES (@myTaskId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerParameter("@myTaskId","BCrvyMoiLEafem-3RxIESmUAHbLK")))
$cmd.ExecuteNonQuery()
Remove-MicrosoftPlanner -Connection $MicrosoftPlanner -Table "Tasks" -Id "MyId"
$cmd = New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerCommand("DELETE FROM Tasks WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftPlanner.MicrosoftPlannerParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Microsoft Planner Data Provider to get started:
Download NowLearn more:
👁 Microsoft Planner IconRapidly create and deploy powerful .NET applications that integrate with Microsoft Planner.