KB: Automate the adding / removing / updating of a Oracle connection (Using the powershell DevOps module)

Automate Oracle connections using PowerShell

In some situations you may need to manage many Oracle database connections. Ordinarily you would use the "Opslogix Oracle Configuration Dashboard" for adding and removing connections, however this can be very time consuming using the GUI.

Since V21.09.x.x we have shipped a PowerShell module to manage connection. By using the Opslogix Oracle PowerShell module you can add and remove connections and you are able to assign instance licenses. All examples are based on adding or modifying 1 connection. But you can easily change the script to handle multiple connections if needed.

The following command are implemented:

Add-SCOMOracleConnection Add or update an Oracle connection
Get-SCOMOracleConnections Lists all current Oracle connections
Get-SCOMOracleInstanceLicences Lists all current instance license assignments
Remove-SCOMOracleConnection Deletes an Oracle connection
Set-SCOMOracleInstanceLicences Assigns an instance license 

You will need already to have a valid Oracle license imported using the licensing dashboard.

This module is part of the software bundle. You will need to copy and import this module on the SCOM Management server where the Collector is installed.

Example script how to add a Oracle connection

## Automate the adding / removing / updating of an Oracle connection (Using the powershell module)
## Notice: Execute on a SCOM server were the Opslogix Oracle collector is installed.
## Notice: Copy from the installation media the folder "OpsLogix Oracle PowerShellModule"
## Michel Kamp

# load the module
# change the path to the oracle installation package
Import-Module "C:\Install\OpsLogix Oracle PowerShellModule\OpsLogix.IMP.Oracle.PowerShellModule.dll"

# check if the module is loaded
get-module 'OpsLogix.IMP.Oracle.PowerShellModule'
# get the commands that can be used
Get-Command -Module 'OpsLogix.IMP.Oracle.PowerShellModule'

# supply the connection details
$ServerName = "oralinux06.contoso.com"
$InstanceName = "DB11G06"
$Port = 1521
$Username = "opslogix"
$PlainPassword = "secretpassword"
$Role = "SYSDBA" # [SYSDBA | SYSOPER | SYSDG] or set to "" for normal user
$ResourcepoolName = "OpsLogix Resource Pool for the Oracle Management Pack"

# now we add the connection
# Note: if the connection already exists it will be updated
Add-SCOMOracleConnection -ServerName $ServerName -InstanceName $InstanceName -Port $Port -Username $Username -PlainPassword $PlainPassword -Role $Role -ResourcepoolName $ResourcepoolName

# lets wait to give SCOM the time to process
sleep 120

## get current added oracle connection information
$instances = Get-SCOMOracleConnections
## get a specific instance
$instances | where -Property MonitoringObject -match 'oralinux06.contoso.com:DB11G06' | select MonitoringObject

# lets assign the instance licenses
# you can use a Regex to filter the connections / instances using ConnectionRegEx
# below example will assign only the DB11G06 instance
Set-SCOMOracleInstanceLicences -ConnectionRegEx "(DB11G06)"
# or
# when you don't use the filter by default every connection is assigned as long you have licenses left.
Set-SCOMOracleInstanceLicences

# if you want to unassign you can use the parameter Assign = $false
# below we will only unassign the instance DB11G06 using the regex
Set-SCOMOracleInstanceLicences -ConnectionRegEx "(DB11G06)" -Assign $false

# get the current license assignments
Get-SCOMOracleInstanceLicences

# if you want to remove a Oracle connection
Remove-SCOMOracleConnection -ServerName oralinux06.contoso.com -InstanceName DB11G06