![]() |
VOOZH | about |
The CData Cmdlets for Act-On 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 Act-On.
The Cmdlets are not only a PowerShell interface to Act-On, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Act-On data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Act-On. To access Act-On data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Act-On.
Once you have acquired the necessary connection properties, accessing Act-On data in PowerShell can be enabled in three steps.
ActOn 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 guide in the CData driver documentation for more information.
Install the module:
Install-Module ActOnCmdlets
Connect:
$acton = Connect-ActOn -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$foldername = "New Folder" $images = Select-ActOn -Connection $acton -Table "Images" -Where "FolderName = `'$FolderName`'" $images
You can also use the Invoke-ActOn cmdlet to execute SQL commands:
$images = Invoke-ActOn -Connection $acton -Query 'SELECT * FROM Images WHERE FolderName = @FolderName' -Params @{'@FolderName'='New Folder'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Act-On\lib\System.Data.CData.ActOn.dll")
Connect to Act-On:
$conn= New-Object System.Data.CData.ActOn.ActOnConnection("InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the ActOnDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Name from Images"
$da= New-Object System.Data.CData.ActOn.ActOnDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.name
}
Update-ActOn -Connection $ActOn -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Images -Id "MyId"
$cmd = New-Object System.Data.CData.ActOn.ActOnCommand("UPDATE Images SET FolderName='New Folder' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ActOn.ActOnParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-ActOn -Connection $ActOn -Table Images -Columns @("Id", "Name") -Values @("MyId", "MyName")
$cmd = New-Object System.Data.CData.ActOn.ActOnCommand("INSERT INTO Images (FolderName) VALUES (@myFolderName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ActOn.ActOnParameter("@myFolderName","New Folder")))
$cmd.ExecuteNonQuery()
Remove-ActOn -Connection $ActOn -Table "Images" -Id "MyId"
$cmd = New-Object System.Data.CData.ActOn.ActOnCommand("DELETE FROM Images WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ActOn.ActOnParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Act-On Data Provider to get started:
Download NowLearn more:
👁 Act-On IconRapidly create and deploy powerful .NET applications that integrate with Act-On marketing automation data including Campaigns, Programs, Reports, and more!