![]() |
VOOZH | about |
The CData Cmdlets for Vault CRM 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 Vault CRM.
The Cmdlets are not only a PowerShell interface to Vault CRM, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Vault CRM data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Vault CRM. To access Vault CRM data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Vault CRM.
Once you have acquired the necessary connection properties, accessing Vault CRM data in PowerShell can be enabled in three steps.
You are ready to connect after specifying the following connection properties:
Install the module:
Install-Module VaultCRMCmdlets
Connect:
$vaultcrm = Connect-VaultCRM -User "$User" -Password "$Password" -Server "$Server" -Database "$Database"
Search for and retrieve data:
$categoryid = "5" $northwindproducts = Select-VaultCRM -Connection $vaultcrm -Table "NorthwindProducts" -Where "CategoryId = `'$CategoryId`'" $northwindproducts
You can also use the Invoke-VaultCRM cmdlet to execute SQL commands:
$northwindproducts = Invoke-VaultCRM -Connection $vaultcrm -Query 'SELECT * FROM NorthwindProducts WHERE CategoryId = @CategoryId' -Params @{'@CategoryId'='5'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Vault CRM\lib\System.Data.CData.VaultCRM.dll")
Connect to Vault CRM:
$conn= New-Object System.Data.CData.VaultCRM.VaultCRMConnection("User=myuser;Password=mypassword;Server=localhost;Database=mydatabase;")
$conn.Open()
Instantiate the VaultCRMDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ProductId, ProductName from NorthwindProducts"
$da= New-Object System.Data.CData.VaultCRM.VaultCRMDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.productid $_.productname
}
Update-VaultCRM -Connection $VaultCRM -Columns @('ProductId','ProductName') -Values @('MyProductId', 'MyProductName') -Table NorthwindProducts -Id "MyId"
$cmd = New-Object System.Data.CData.VaultCRM.VaultCRMCommand("UPDATE NorthwindProducts SET CategoryId='5' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.VaultCRM.VaultCRMParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-VaultCRM -Connection $VaultCRM -Table NorthwindProducts -Columns @("ProductId", "ProductName") -Values @("MyProductId", "MyProductName")
$cmd = New-Object System.Data.CData.VaultCRM.VaultCRMCommand("INSERT INTO NorthwindProducts (CategoryId) VALUES (@myCategoryId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.VaultCRM.VaultCRMParameter("@myCategoryId","5")))
$cmd.ExecuteNonQuery()
Remove-VaultCRM -Connection $VaultCRM -Table "NorthwindProducts" -Id "MyId"
$cmd = New-Object System.Data.CData.VaultCRM.VaultCRMCommand("DELETE FROM NorthwindProducts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.VaultCRM.VaultCRMParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Vault CRM Data Provider to get started:
Download NowLearn more:
👁 Vault CRM IconRapidly create and deploy powerful .NET applications that integrate with Veeva Vault & Vault CRM account data including Documents, Users, Groups, and more!