Ready to get started?

Download a free trial of the Square Data Provider to get started:

 Download Now

Learn more:

Square Icon Square ADO.NET Provider

Easy-to-use Square client enables .NET-based applications to easily consume Square Transactions, Items, Subscriptions, etc.

Automate Square Integration Tasks from PowerShell

Are you in search of a quick and easy way to access Square data from PowerShell? This article demonstrates how to utilize the Square Cmdlets for tasks like connecting to Square data, automating operations, downloading data, and more.

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

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing Square data in PowerShell can be enabled in three steps.

Square uses the OAuth authentication standard. To authenticate using OAuth, you will need to register an app with Square to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL. See the "Getting Started" chapter of the help documentation for a guide to using OAuth.

Additionally, you must specify the LocationId. You can retrieve the Ids for your Locations by querying the Locations table. Alternatively, you can set the LocationId in the search criteria of your query.


  1. Install the module:

    Install-Module SquareCmdlets
  2. Connect:

    $square = Connect-Square -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -LocationId "$LocationId"
  3. Search for and retrieve data:

    $type = "FULL" $refunds = Select-Square -Connection $square -Table "Refunds" -Where "Type = `'$Type`'" $refunds

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

    $refunds = Invoke-Square -Connection $square -Query 'SELECT * FROM Refunds WHERE Type = @Type' -Params @{'@Type'='FULL'}


  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Square.SquareConnection("OAuthClientId=MyAppId;OAuthClientSecret=MyAppSecret;CallbackURL=http://localhost:33333;LocationId=MyDefaultLocation;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SquareDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Reason, RefundedMoneyAmount from Refunds" $da= New-Object System.Data.CData.Square.SquareDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.reason $_.refundedmoneyamount }

Update Square Data


Update-Square -Connection $Square -Columns @('Reason','RefundedMoneyAmount') -Values @('MyReason', 'MyRefundedMoneyAmount') -Table Refunds -Id "MyId"


$cmd = New-Object System.Data.CData.Square.SquareCommand("UPDATE Refunds SET Type='FULL' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Square.SquareParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Square Data


Add-Square -Connection $Square -Table Refunds -Columns @("Reason", "RefundedMoneyAmount") -Values @("MyReason", "MyRefundedMoneyAmount")


$cmd = New-Object System.Data.CData.Square.SquareCommand("INSERT INTO Refunds (Type) VALUES (@myType)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Square.SquareParameter("@myType","FULL"))) $cmd.ExecuteNonQuery()

Delete Square Data


Remove-Square -Connection $Square -Table "Refunds" -Id "MyId"


$cmd = New-Object System.Data.CData.Square.SquareCommand("DELETE FROM Refunds WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Square.SquareParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()