Ready to get started?

Learn more about the CData ADO.NET Provider for Veeva or download a free trial:

Download Now

Automate Veeva Integration Tasks from PowerShell

Are you looking for a quick and easy way to access Veeva data from PowerShell? We show how to use the Cmdlets for Veeva and the CData ADO.NET Provider for Veeva to connect to Veeva data and synchronize, automate, download, and more.

The CData Cmdlets for Veeva 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 Veeva.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Veeva API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Veeva data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Veeva. To access Veeva data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Veeva.

After obtaining the needed connection properties, accessing Veeva data in PowerShell consists of three basic steps.

You are ready to connect after specifying the following connection properties:

  • Url: The host you see in the URL after you login to your account. For example: https://my-veeva-domain.veevavault.com
  • User: The username you use to login to your account.
  • Password: The password you use to login to your account.

PowerShell

  1. Install the module:

    Install-Module VeevaCmdlets
  2. Connect:

    $veeva = Connect-Veeva -User "$User" -Password "$Password" -Server "$Server" -Database "$Database"
  3. Search for and retrieve data:

    $categoryid = "5" $northwindproducts = Select-Veeva -Connection $veeva -Table "NorthwindProducts" -Where "CategoryId = `'$CategoryId`'" $northwindproducts

    You can also use the Invoke-Veeva cmdlet to execute SQL commands:

    $northwindproducts = Invoke-Veeva -Connection $veeva -Query 'SELECT * FROM NorthwindProducts WHERE CategoryId = @CategoryId' -Params @{'@CategoryId'='5'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Veeva\lib\System.Data.CData.Veeva.dll")
  2. Connect to Veeva:

    $conn= New-Object System.Data.CData.Veeva.VeevaConnection("User=myuser;Password=mypassword;Server=localhost;Database=mydatabase;") $conn.Open()
  3. Instantiate the VeevaDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ProductId, ProductName from NorthwindProducts" $da= New-Object System.Data.CData.Veeva.VeevaDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.productid $_.productname }

Update Veeva Data

PowerShell

Update-Veeva -Connection $Veeva -Columns @('ProductId','ProductName') -Values @('MyProductId', 'MyProductName') -Table NorthwindProducts -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Veeva.VeevaCommand("UPDATE NorthwindProducts SET CategoryId='5' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Veeva.VeevaParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Veeva Data

PowerShell

Add-Veeva -Connection $Veeva -Table NorthwindProducts -Columns @("ProductId", "ProductName") -Values @("MyProductId", "MyProductName")

ADO.NET

$cmd = New-Object System.Data.CData.Veeva.VeevaCommand("INSERT INTO NorthwindProducts (CategoryId) VALUES (@myCategoryId)", $conn) $cmd.Parameters.Add(new System.Data.CData.Veeva.VeevaParameter("@myCategoryId","5")) $cmd.ExecuteNonQuery()

Delete Veeva Data

PowerShell

Remove-Veeva -Connection $Veeva -Table "NorthwindProducts" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Veeva.VeevaCommand("DELETE FROM NorthwindProducts WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Veeva.VeevaParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()