i just want to edit my oracle listener.ora file, so that when i deploy a new virtual machine, that it edit this file with the new hostname / computername, but i am not sure how i do that with powershell. i have this line in the listener.ora file:
Here’s a function that will create a computername-listerner.ora file for each computer name supplied. Let us know if you’re unsure of how to use a function in PowerShell.
Function New-OracleListenerFile {
[CmdletBinding()]
Param (
[string[]]$ComputerName = 'localhost'
)
Begin {
} # End Begin.
Process {
ForEach ($Computer in $ComputerName) {
$FileStructure = @"
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $Computer)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
"@
$Path = "$Computer-listener.ora"
New-Item -Path $Path -ItemType File | Out-Null
Set-Content -Path $Path -Value $FileStructure
}
} # End Process.
End {
} # End End.
} # End Function: New-OracleListenerFile
big thx, only one question, where can i say or define the $PATH? i mean where does it write this file now? sorry, complete newbie in this powershell things! and yes i am unsure how to use a function!
As it’s written, it’s going to create the file(s) in the current directory – the same location where the function is run. Copy and paste the function to your PowerShell console while the prompt is indicating you’re at the root of the C:\ drive (PS C:>), and it’ll create your files there. Here’s a minor modification that will create the file(s) at the root of the system drive (the C:), unless you include the Path parameter, like so: New-OracleListenerFile -Computer server1,server2 -Path ‘C:\OracleFiles’
Function New-OracleListenerFile {
[CmdletBinding()]
Param (
[string[]]$ComputerName = 'localhost',
[string]$Path = $env:SystemDrive
)
Begin {
} # End Begin.
Process {
ForEach ($Computer in $ComputerName) {
$FileStructure = @"
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $Computer)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
"@
$FullPath = "$Path\$Computer-listener.ora"
New-Item -Path $FullPath -ItemType File | Out-Null
Set-Content -Path $FullPath -Value $FileStructure
}
} # End Process.
End {
} # End End.
} # End Function: New-OracleListenerFile