![]() |
VOOZH | about |
The CData Cmdlets for Microsoft OneDrive are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Microsoft OneDrive.
The Cmdlets are not only a PowerShell interface to Microsoft OneDrive, but also an SQL interface; this tutorial shows how to use both to retrieve Microsoft OneDrive data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Microsoft OneDrive. To access Microsoft OneDrive data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Microsoft OneDrive.
Once you have acquired the necessary connection properties, accessing Microsoft OneDrive data in PowerShell can be enabled in three steps.
OneDrive 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 of the Help documentation for an authentication guide.
Install the module:
Install-Module OneDriveCmdlets
Connect:
$onedrive = Connect-OneDrive -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -OAuthCallbackURL "$OAuthCallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$id = "Jq74mCczmFXk1tC10GB" $files = Select-OneDrive -Connection $onedrive -Table "Files" -Where "Id = `'$Id`'" $files
You can also use the Invoke-OneDrive cmdlet to execute SQL commands:
$files = Invoke-OneDrive -Connection $onedrive -Query 'SELECT * FROM Files WHERE Id = @Id' -Params @{'@Id'='Jq74mCczmFXk1tC10GB'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Microsoft OneDrive\lib\System.Data.CData.OneDrive.dll")
Connect to Microsoft OneDrive:
$conn= New-Object System.Data.CData.OneDrive.OneDriveConnection("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;OAuthCallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the OneDriveDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Files"
$da= New-Object System.Data.CData.OneDrive.OneDriveDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.name
}
Download a free trial of the Microsoft OneDrive Data Provider to get started:
Download NowLearn more:
👁 Microsoft OneDrive IconRapidly create and deploy powerful .NET applications that integrate with Microsoft OneDrive.