Establishing a Connection
With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our Domino Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.
Installing and Connecting
If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.
Install-Module DominoCmdlets
The following line is then added to your profile, loading the cmdlets on the next session:
Import-Module DominoCmdlets;
You can then use the Connect-Domino cmdlet to create a connection object that can be passed to other cmdlets:
$conn = Connect-Domino -URL "http://dominoserver:3002/" -DataSource "names" -TableTypes "Tables" -AuthScheme "OAuthPassword" -User "MyUser" -Password "MyPassword"
Connecting to Domino
To connect to Domino data, set the following properties:- URL: The host name or IP of the server hosting the Domino database. Include the port of the server hosting the Domino database. For example: http://sampleserver:1234/
- DatabaseScope: The name of a scope in the Domino Web UI. The cmdlet exposes forms and views for the schema governed by the specified scope. In the Domino Admin UI, select the Scopes menu in the sidebar. Set this property to the name of an existing scope.
Authenticating to Domino
Domino supports authenticating via login credentials or an Azure Active Directory OAuth application:
Login Credentials
Set AuthScheme to OAuthPassword and set the following properties:- User: The username of the authenticating Domino user.
- Password: The password associated with the authenticating Domino user.
The cmdlet uses the login credentials to automatically perform an OAuth token exchange.
AzureAD
This authentication method uses Azure Active Directory as an IdP to obtain a JWT token. You need to create a custom OAuth application in Azure Active Directory and configure it as an IdP. To do so, follow the instructions here.Set AuthScheme to AzureAD and set the following properties:
- OAuthClientId: The Client ID obtained when setting up the custom OAuth application.
- OAuthClientSecret: The Client secret obtained when setting up the custom OAuth application.
- CallbackURL : The redirect URI defined when you registered your app. For example: https://localhost:33333
- AzureTenant The Microsoft Online tenant being used to access data. Supply either a value in the form companyname.microsoft.com or the tenant Id.
- The tenant Id is the same as the directory Id shown in the Azure Portal's Azure Active Directory > Properties page.
Retrieving Data
The Select-Domino cmdlet provides a native PowerShell interface for retrieving data:
$results = Select-Domino -Connection $conn -Table "Person" -Columns @("unid, FirstName") -Where "City='Miami'"The Invoke-Domino cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.
Piping Cmdlet Output
The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:
Select-Domino -Connection $conn -Table Person -Where "City = 'Miami'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myPersonData.csv -NoTypeInformation
You will notice that we piped the results from Select-Domino into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.
However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:
PS C:\> $conn = Connect-Domino -URL "http://dominoserver:3002/" -DataSource "names" -TableTypes "Tables" -AuthScheme "OAuthPassword" -User "MyUser" -Password "MyPassword" PS C:\> $row = Select-Domino -Connection $conn -Table "Person" -Columns (unid, FirstName) -Where "City = 'Miami'" | select -first 1 PS C:\> $row | ConvertTo-Json { "Connection": { }, "Table": "Person", "Columns": [ ], "unid": "Myunid", "FirstName": "MyFirstName" }