![]() |
VOOZH | about |
The CData Cmdlets for Slack 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 Slack.
The Cmdlets are not only a PowerShell interface to Slack, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Slack data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Slack. To access Slack data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Slack.
Once you have acquired the necessary connection properties, accessing Slack data in PowerShell can be enabled in three steps.
Slack uses the OAuth authentication standard. To authenticate using OAuth, create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the Getting Started section of the help documentation for an authentication guide.
Install the module:
Install-Module SlackCmdlets
Connect:
$slack = Connect-Slack -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$ispublic = "True" $channels = Select-Slack -Connection $slack -Table "Channels" -Where "IsPublic = `'$IsPublic`'" $channels
You can also use the Invoke-Slack cmdlet to execute SQL commands:
$channels = Invoke-Slack -Connection $slack -Query 'SELECT * FROM Channels WHERE IsPublic = @IsPublic' -Params @{'@IsPublic'='True'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Slack\lib\System.Data.CData.Slack.dll")
Connect to Slack:
$conn= New-Object System.Data.CData.Slack.SlackConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the SlackDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Channels"
$da= New-Object System.Data.CData.Slack.SlackDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.name
}
Update-Slack -Connection $Slack -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Channels -Id "MyId"
$cmd = New-Object System.Data.CData.Slack.SlackCommand("UPDATE Channels SET IsPublic='True' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Slack.SlackParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Slack -Connection $Slack -Table Channels -Columns @("Id", "Name") -Values @("MyId", "MyName")
$cmd = New-Object System.Data.CData.Slack.SlackCommand("INSERT INTO Channels (IsPublic) VALUES (@myIsPublic)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Slack.SlackParameter("@myIsPublic","True")))
$cmd.ExecuteNonQuery()
Remove-Slack -Connection $Slack -Table "Channels" -Id "MyId"
$cmd = New-Object System.Data.CData.Slack.SlackCommand("DELETE FROM Channels WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Slack.SlackParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Slack Data Provider to get started:
Download NowLearn more:
👁 Slack IconRapidly create and deploy powerful .NET applications that integrate with Slack.