I need a huge help. I have an Oracle database and I’m trying to get instance name with powershell.
Does anyone know how can i do this?
Here is the script:
##########################
[System.Reflection.Assembly]::LoadWithPartialName(“System.Data.OracleClient”) | Out-Null
#########################
#Connecting to Oracle DB:
###########################
$connection = New-Object System.Data.OracleClient.OracleConnection($connectionString);
$connection.Open();
##Check Status:
try {
### sql query command ###
$OracleSQLQuery = "select instance name from v$Instance";
### create object ###
$SelectCommand = New-Object System.Data.OracleClient.OracleCommand;
$SelectCommand.Connection = $connection
$SelectCommand.CommandText = $OracleSQLQuery
$SelectCommand.CommandType = [System.Data.CommandType]::Text
### create datatable and load results into datatable ###
$SelectDataTable = New-Object System.Data.DataTable
$SelectDataTable.Load($SelectCommand.ExecuteReader())
}
catch
{
write-error " An Exception has occured. See the following for the details : ";
write-host "The exception is " $_.Exception.ToString();
}
$connection.Close();