Fix PowerShell $Host reserved variable conflict in ROA setup scripts
- Rename $Host parameter to $DbHost in oracle-functions.ps1 (Invoke-SqlPlus,
Test-OracleConnection, Get-OracleVersion, Test-PDB, Get-ServiceName)
- Update all function calls in 01-setup-database.ps1 to use -DbHost instead of -Host
- Fix ${Host} -> ${DbHost} in log message (line 147)
- Fix Write-Log "" -> Write-Host "" to avoid empty string parameter error
- Add DbHost/Port parameters and config.ps1 support to setup script
- Update sys-updates/README.md to clarify folder is for future patches only
Tested successfully on ROACENTRAL (10.0.20.130) with Oracle XE 21c.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -131,6 +131,12 @@ function Get-OracleVersion {
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$DbHost,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Port = 1521,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$Username = "SYSTEM",
|
||||
|
||||
@@ -149,6 +155,7 @@ EXIT;
|
||||
"@
|
||||
|
||||
$result = Invoke-SqlPlus -OracleHome $oraHome -ServiceName $ServiceName `
|
||||
-DbHost $DbHost -Port $Port `
|
||||
-Username $Username -Password $Password -SqlCommand $sql -Silent
|
||||
|
||||
$versionInfo = [PSCustomObject]@{
|
||||
@@ -201,6 +208,12 @@ function Get-ServiceName {
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$OracleHome,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$DbHost,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Port = 1521,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$SystemPassword
|
||||
)
|
||||
@@ -210,6 +223,7 @@ function Get-ServiceName {
|
||||
# First try to connect to XE and check if it's CDB
|
||||
try {
|
||||
$version = Get-OracleVersion -OracleHome $oraHome -ServiceName "XE" `
|
||||
-DbHost $DbHost -Port $Port `
|
||||
-Password $SystemPassword -ErrorAction Stop
|
||||
|
||||
if ($version.IsCDB) {
|
||||
@@ -224,6 +238,7 @@ function Get-ServiceName {
|
||||
# Try ROA as service name
|
||||
try {
|
||||
$null = Test-OracleConnection -OracleHome $oraHome -ServiceName "ROA" `
|
||||
-DbHost $DbHost -Port $Port `
|
||||
-Username "SYSTEM" -Password $SystemPassword -ErrorAction Stop
|
||||
return "ROA"
|
||||
}
|
||||
@@ -270,6 +285,12 @@ function Test-OracleConnection {
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$DbHost,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Port = 1521,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$Username = "SYSTEM",
|
||||
|
||||
@@ -286,6 +307,7 @@ function Test-OracleConnection {
|
||||
|
||||
try {
|
||||
$result = Invoke-SqlPlus -OracleHome $oraHome -ServiceName $ServiceName `
|
||||
-DbHost $DbHost -Port $Port `
|
||||
-Username $Username -Password $Password -SqlCommand $sql -AsSysdba:$AsSysdba -Silent
|
||||
|
||||
return $result -match "CONNECTED"
|
||||
@@ -330,6 +352,12 @@ function Test-PDB {
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$DbHost,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Port = 1521,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$Username = "SYSTEM",
|
||||
|
||||
@@ -347,6 +375,7 @@ EXIT;
|
||||
"@
|
||||
|
||||
$result = Invoke-SqlPlus -OracleHome $oraHome -ServiceName $ServiceName `
|
||||
-DbHost $DbHost -Port $Port `
|
||||
-Username $Username -Password $Password -SqlCommand $sql -Silent
|
||||
|
||||
$containerInfo = [PSCustomObject]@{
|
||||
@@ -428,6 +457,12 @@ function Invoke-SqlPlus {
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$DbHost,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[int]$Port = 1521,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$Username = "SYSTEM",
|
||||
|
||||
@@ -454,9 +489,13 @@ function Invoke-SqlPlus {
|
||||
throw "SQL*Plus not found at: $sqlplus"
|
||||
}
|
||||
|
||||
# Build connection string
|
||||
# Build connection string (EZConnect format if DbHost is provided)
|
||||
$sysdba = if ($AsSysdba) { " as sysdba" } else { "" }
|
||||
$connString = "$Username/`"$Password`"@$ServiceName$sysdba"
|
||||
if ($DbHost) {
|
||||
$connString = "$Username/`"$Password`"@${DbHost}:${Port}/${ServiceName}$sysdba"
|
||||
} else {
|
||||
$connString = "$Username/`"$Password`"@$ServiceName$sysdba"
|
||||
}
|
||||
|
||||
$tempFile = $null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user