Oracle启动和closures与Powershell

我试图用PowerShell自动启动和closures一些Oracle实例。

下面我已经提出了最好的

param( [String]$Instance = $(Throw 'Instance required' ), [String]$Password = $(Throw 'Password required'), [String]$ShutdownMode = 'IMMEDIATE' ) $validShutdownModes = ('IMMEDIATE', 'NORMAL', 'ABORT') if($validShutdownModes -notcontains $ShutdownMode) { Throw 'Invalid ShutdownMode: [IMMEDIATE | NORMAL | ABORT]' } #Prepare the connection statement based on the Password and Instance name $sqlConnect = 'connect sys/{0}@{1} as sysdba;' -f ($Password, $Instance) #Prepare the shutdown statement based on the ShutdownMode $sqlShutdown = 'shutdown {0};' -f ($ShutdownMode) #Prepare the exit statement $sqlExit = 'exit;' #Get a temporary file for storing the SQLPLUS commands $tmpFile = [System.IO.Path]::GetTempFileName() #Write the commands to the file Set-Content -path $tmpFile -value $sqlConnect Add-Content -path $tmpFile -value $sqlShutdown Add-Content -path $tmpFile -value $sqlExit #Execute the commands $output = &'sqlplus.exe' '/NOLOG' '@' $tmpFile #Remove the temporary file Remove-Item -path $tmpFile #Dump the ouput of SQLPLUS to the console $output 

这个工作,但它不能处理任何意想不到的事情和密码写入临时文件是不是很理想。

有没有我可以用来closuresOracle实例的编程接口,或者更好的方式来使用SQLPLUS来完成这种任务?

一般来说,对PowerShell的一般批评也是值得赞赏的。

谢谢

我没有使用PowerShell的经验。

但是,如何使用Oracle内置的Windows特定命令行ORADIM启动/停止数据库呢? 它可以停止/启动数据库实例和ASM实例。

使用它比你的解决方法更清洁:)

这里请参阅Oracle文档。 它有启动和closures的例子。

或者使用PowerShell来停止/启动OracleServiceSID。