Using ConnectIds in Script

When a Cloudbridge script is run, the Cloudbridge platform defines several variables to store the Connect IDs that were assigned to that script. Those variables are as follows:  

Name 

Type 

Details 

$ConnectId 

Hashtable 

Contains details for the "RunAs" Connect Id for the script. The credentials for the "RunAs" Connect ID can be retrieved by using Get-Credential. 

$ConnectIds 

Hashtable 

Contains details for all Connect Ids that are available to the script (including the "RunAs" Connect Id). This variable also contains the credentials for each Connect Id that can be used to connect to systems within the script. 

 How you retrieve credentials a Connect Id depends on whether or not you want the credentials for the "RunAs" Connect Id, or for one of the available Connect Ids. 

Using the “RunAs” ConnectId

To access/use the current Run As ConnectID, either call Get-Credential cmdlet or use $ConnectId.Credentials in your script. For scripts with multiple Run As ConnectIDs bound, the credential associated with the "current" ConnectID of the current script run will be provided.

$ConnectId is a global variable made available automatically to all scripts; it holds the current ConnectID.

Get-Credential is intercepted by the platform and returns $ConnectId.Credentials

For example: 

# This command would retrieve the credentials for the "RunAs" Connect Id  $runAsCredentials = Get-Credential 

Using an “Available” Connect Id

For any available Connect Id, you can retrieve the credentials by accessing them from the $ConnectIds hashtable. The $ConnectIds hashtable stores the Connect Id names as the keys, and the Connect Id properties in a hashtable stored in the value associated with that key. If you know the name of the Connect Id for which you want credentials, you can do the following to access the credentials in your script: 

Retrieving an “Available” Connect Id By Name

# This command would retrieve the credentials for the Connect Id called "Azure"  $availableCredentials = $connectIds['Azure'].Credentials 

Retrieving an “Available” Connect Id by Property value

Connect Ids also have other properties that can be used from within a script. For example, to obtain the credentials from an available Connect Id based on its Type, you could do the following: 

# Do something with Connect Ids based on their type  foreach ($genericConnectId in $connectIds.Values | Where-Object {$_.Type -eq 'Generic'}) {      $genericCredentials = $genericConnectId.Credentials 

All credentials retrieved in this manner are of type System.Management.Automation.PSCredential, and they can be used the same way any PSCredential is used within PowerShell. 

 

$ConnectIds is a global variable made available automatically to all scripts.

The key used to store each Connect Id in $connectIds is the name of that Connect Id. 

ConnectId Properties

Below is a list of all properties available on a $connectId, along with a description of the property and the type of Connect Id for which property is applicable.

Property Name 

Description 

Connect Id Type

Name

The name of the Connect Id. This is used as the key for connect Ids stored in the $connectIds collection.

All

Type

The type of Connect Id. 

All 

URL

The URL associated with the Connect Id. 

Email, Generic 

Username

Username on the Connect Id.

All

Credentials

The credentials stored in the Connect Id. 

All 

SmtpServer

The (domain) name of the SMTP server. 

Email 

Port

The port to use for the SMTP server. 

Email 

ServiceNowUrl

The URL to use to connect to ServiceNow. 

Service Now 

RunUser

 

All RunAs

variableName

Any variable name created on the Connect Id.

All

https://ucclearly.atlassian.net/wiki/spaces/CK/pages/491522