所以我对Powershell还是很陌生,我有一个Oracle sql Scipt,我想在Powershell循环中运行
读取文本文件以读取服务器列表的功能。
$oracleServers = "C:\Temp\oracle-servers.txt"
function Database-Servers
{
$servers = Get-Content $oracleServers
Return($servers.Trim())
}
接下来,我从该列表中读取正在运行的Oracle Services
功能已安装的数据库
$svr = $args[0]
$runningDBs = " "
$runningDBs = Get-Service -Name "OracleService*" -ComputerName $svr |
Select-Object -ExpandProperty name | Out-String | % {$_.replace("OracleService","")}
Return($runningDBs)
function ConnectString
{
$CString = " " #$args[0]
foreach ($server in Database-Servers)
{
$runningDBs = Installed-Databases $server
$rdblist = $runningDBs -split '[\n]'
foreach ( $rdb in $rdblist)
{
if(!$rdb -eq " ")
{
$CString = ' system/$rdb@$server$tnsalias$rdb'
&sqlplus $CString $scriptsql | out-file $outputfile
Write-Host $CString
Return($CString)
}
}
}
}