![]() |
VOOZH | about |
The CData Cmdlets for Kintone 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 Kintone.
The Cmdlets are not only a PowerShell interface to Kintone, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Kintone data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Kintone. To access Kintone data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Kintone.
Once you have acquired the necessary connection properties, accessing Kintone data in PowerShell can be enabled in three steps.
In addition to the authentication values, set the following parameters to connect to and retrieve data from Kintone:
Kintone supports the following authentication methods.
You must set the following to authenticate:
If the basic authentication security feature is set on the domain, supply the additional login credentials with BasicAuthUser and BasicAuthPassword. Basic authentication requires these credentials in addition to User and Password.
Instead of basic authentication, you can specify a client certificate to authenticate. Set SSLClientCert, SSLClientCertType, SSLClientCertSubject, and SSLClientCertPassword. Additionally, set User and Password to your login credentials.
Install the module:
Install-Module KintoneCmdlets
Connect:
$kintone = Connect-Kintone -User "$User" -Password "$Password" -Url "$Url" -GuestSpaceId "$GuestSpaceId"
Search for and retrieve data:
$appid = "1354841" $comments = Select-Kintone -Connection $kintone -Table "Comments" -Where "AppId = `'$AppId`'" $comments
You can also use the Invoke-Kintone cmdlet to execute SQL commands:
$comments = Invoke-Kintone -Connection $kintone -Query 'SELECT * FROM Comments WHERE AppId = @AppId' -Params @{'@AppId'='1354841'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Kintone\lib\System.Data.CData.Kintone.dll")
Connect to Kintone:
$conn= New-Object System.Data.CData.Kintone.KintoneConnection("User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid")
$conn.Open()
Instantiate the KintoneDataAdapter, execute an SQL query, and output the results:
$sql="SELECT CreatorName, Text from Comments"
$da= New-Object System.Data.CData.Kintone.KintoneDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.creatorname $_.text
}
Update-Kintone -Connection $Kintone -Columns @('CreatorName','Text') -Values @('MyCreatorName', 'MyText') -Table Comments -Id "MyId"
$cmd = New-Object System.Data.CData.Kintone.KintoneCommand("UPDATE Comments SET AppId='1354841' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Kintone.KintoneParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Kintone -Connection $Kintone -Table Comments -Columns @("CreatorName", "Text") -Values @("MyCreatorName", "MyText")
$cmd = New-Object System.Data.CData.Kintone.KintoneCommand("INSERT INTO Comments (AppId) VALUES (@myAppId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Kintone.KintoneParameter("@myAppId","1354841")))
$cmd.ExecuteNonQuery()
Remove-Kintone -Connection $Kintone -Table "Comments" -Id "MyId"
$cmd = New-Object System.Data.CData.Kintone.KintoneCommand("DELETE FROM Comments WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Kintone.KintoneParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Kintone Data Provider to get started:
Download NowLearn more:
👁 Kintone IconRapidly create and deploy powerful .NET applications that integrate with Kintone applications and databases.