Organizing cmdlet operations in a sequence

There is no fixed sequence in which cmdlets must be called. There is, however, a logical sequence to follow to make information available from one to another. For example, to get all of the audit roles in an installation, you might first want to identify the installation object you want to work with before you call the Get-CdaAuditRole cmdlet, To accomplish this, you could organize the calls in the following sequence:

$site = Get-CdaInstallation -Name "production"
Get-CdaAuditRole $site

Similarly, before converting an active database into an attached database, you might organize the calls to create a new audit store database, then set the new database to be the active audit store database:

$install = Get-CdaInstallation -Name "site1"
$auditStore = Get-CdaAuditStore -Installation $install -Name "auditstore1"
// Use New-CdaDatabase to create and attach the new database
$newDB = New-CdaDatabase -AuditStore $auditStore -Name "audit-us-Oct2014" -Server "\da" -Database "audit-us-Oct2014"
// Set the newly created database as the active database for this audit store
Set-CdaActiveDatabase -AuditStore $auditStore -Database $newDB
// Create another new database
$newDB2 = New-CdaDatabase -AuditStore $auditStore -Name "audit-us-Nov2014" -Server "\da" -Database "audit-us-Nov2014"
// Set the second database as active database
Set-CdaActiveDatabase -AuditStore $auditStore -Database $newDB2
// Detach the first database if it is no longer needed
Detach-CdaDatabase -Database $newDB

In most cases, you can determine from the parameters of a cmdlet whether you need to call another cmdlet first. For example, most Set-CdaXxx or Remove-CdaXxx cmdlets, you must call the corresponding Get‑CdaXxx cmdlet to obtain the object first. For example, to delete the "forensics" audit role from the "production" audit installation, you could call the cmdlets as follows:

Get-CdaAuditRole -Installation "production" -Name "forensics" | Remove‑CdaAuditRole

In this example, the Get-CdaAuditRole cmdlet retrieves “forensics” from the specified installation and passes it to the Remove-CdaAuditRole cmdlet.