![]() |
VOOZH | about |
The CData Cmdlets for ADP 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 ADP.
The Cmdlets are not only a PowerShell interface to ADP, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete ADP data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for ADP. To access ADP data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for ADP.
Once you have acquired the necessary connection properties, accessing ADP data in PowerShell can be enabled in three steps.
Connect to ADP by specifying the following properties:
The connector uses OAuth to authenticate with ADP. OAuth requires the authenticating user to interact with ADP using the browser. OAuth access can be configured in ADP through ADP API Central. For more information, refer ADP's API Central Quick Start Guide and the OAuth section in CData's Help documentation.
Install the module:
Install-Module ADPCmdlets
Connect:
$adp = Connect-ADP -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -SSLClientCert "$SSLClientCert" -SSLClientCertPassword "$SSLClientCertPassword" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$associateoid = "G3349PZGBADQY8H8" $workers = Select-ADP -Connection $adp -Table "Workers" -Where "AssociateOID = `'$AssociateOID`'" $workers
You can also use the Invoke-ADP cmdlet to execute SQL commands:
$workers = Invoke-ADP -Connection $adp -Query 'SELECT * FROM Workers WHERE AssociateOID = @AssociateOID' -Params @{'@AssociateOID'='G3349PZGBADQY8H8'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for ADP\lib\System.Data.CData.ADP.dll")
Connect to ADP:
$conn= New-Object System.Data.CData.ADP.ADPConnection("OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;SSLClientCert='c:\cert.pfx';SSLClientCertPassword='admin@123';InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the ADPDataAdapter, execute an SQL query, and output the results:
$sql="SELECT AssociateOID, WorkerID from Workers"
$da= New-Object System.Data.CData.ADP.ADPDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.associateoid $_.workerid
}
Update-ADP -Connection $ADP -Columns @('AssociateOID','WorkerID') -Values @('MyAssociateOID', 'MyWorkerID') -Table Workers -Id "MyId"
$cmd = New-Object System.Data.CData.ADP.ADPCommand("UPDATE Workers SET AssociateOID='G3349PZGBADQY8H8' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ADP.ADPParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-ADP -Connection $ADP -Table Workers -Columns @("AssociateOID", "WorkerID") -Values @("MyAssociateOID", "MyWorkerID")
$cmd = New-Object System.Data.CData.ADP.ADPCommand("INSERT INTO Workers (AssociateOID) VALUES (@myAssociateOID)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ADP.ADPParameter("@myAssociateOID","G3349PZGBADQY8H8")))
$cmd.ExecuteNonQuery()
Remove-ADP -Connection $ADP -Table "Workers" -Id "MyId"
$cmd = New-Object System.Data.CData.ADP.ADPCommand("DELETE FROM Workers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ADP.ADPParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the ADP Data Provider to get started:
Download NowLearn more:
👁 ADP IconRapidly create and deploy powerful .NET applications that integrate with ADP.