使用powershell脚本批量更新客户端配置文件
2013-01-11 23:21
447 查看
2012-1-11
背景:
Oracle升级并且服务器和IP地址同时更新,系统架构是2层C/S架构的,面临的是客户端200+需要更新tnsnames.ora,且Oracle安装目录不一致,稍让安心的是Oracle客户端版本是统一的, OS都是windows 系统,并且都加入域。
解决方案:
使用powershell脚本在服务器端推送新版的tnsnames.ora
实施步骤:
结合.Net 框架编写远程读写注册表测试脚本
View Code
背景:
Oracle升级并且服务器和IP地址同时更新,系统架构是2层C/S架构的,面临的是客户端200+需要更新tnsnames.ora,且Oracle安装目录不一致,稍让安心的是Oracle客户端版本是统一的, OS都是windows 系统,并且都加入域。
解决方案:
使用powershell脚本在服务器端推送新版的tnsnames.ora
实施步骤:
结合.Net 框架编写远程读写注册表测试脚本
View Code
write-output "Replace TNSNames.ora now`nPlease Wait..." #Create/format Excel #$erroractionpreference = "SilentlyContinue" $a = New-Object -comobject Excel.Application $a.visible = $True $b = $a.Workbooks.Add() $b.workSheets.item(3).delete() $b.WorkSheets.item(2).delete() $b.WorkSheets.item(1).Name = "File_Delete" $P = $b.WorkSheets.Item("File_Delete") $c = $b.Worksheets.Item(1) $c.Cells.Item(1,1) = "Machine Name" $c.Cells.Item(1,2) = "PC Status" $c.Cells.Item(1,3) = "Delete Status" $d = $c.UsedRange $d.Interior.ColorIndex = 40 $d.Font.ColorIndex = 9 $d.Font.Bold = $True #define parameter $intRow = 2 #get pc arrary $strComputers = get-content .\pclist.txt foreach ($strComputer in $strComputers) { $ping = new-object System.Net.NetworkInformation.Ping $Reply = $ping.Send($strComputer) if ($Reply.status -eq "success") { $reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strComputer) [System.String]$name="SOFTWARE\Oracle\KEY_OraClient10g_home1" $regKey= $reg.OpenSubKey($name).GetValue("ORACLE_HOME") $regKey=$regKey.Replace(":","$") $tnsfilepath="\\"+$strComputer+"\"+$regKey+"\network\admin\" $sourcetnsname=$tnsfilepath+"\tnsnames.ora" $oldtnsfile=$tnsfilepath+"\tnsnames_Bak_"+[System.DateTime]::Now.ToString('yyyyMM')+".ora" #backup cp $sourcetnsname $oldtnsfile $newtnsfile="\\"+"**.**.**.**\tnsnames.ora" #upload the new version cp $newtnsfile $sourcetnsname $c.Cells.Item($intRow, 1) = $strComputer.ToUpper() $c.Cells.Item($intRow, 2) = "Online" $c.Cells.Item($intRow, 3) = "Replace Success" $intRow = $intRow + 1 } else { $c.Cells.Item($intRow, 1) = $strComputer.ToUpper() $c.Cells.Item($intRow, 2) = "Offline" $c.Cells.Item($intRow, 3) = "Delete failure" $intRow = $intRow + 1 } } $d.EntireColumn.AutoFit() write-output "TNSNames Modification finished`nComplete!"
相关文章推荐
- FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码
- 在cxf中使用配置避免增加字段导致客户端必须更新的问题
- 组策略配置客户端计算机使用WSUS服务器进行更新
- FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码
- 在cxf中使用配置避免增加字段导致客户端必须更新、同步实体属性的问题
- [Linux]FTP/VSFTP/配置文件/本地匿名虚拟用户访问/ftp客户端使用
- 使用Linux shell脚本实现FTP定时执行批量下载指定文件
- FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码(转)
- FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码
- 使用PowerShell脚本更新数据库
- Azure PowerShell (7) 使用CSV文件批量设置Virtual Machine Endpoint
- FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码
- bootstrap File Input 多文件上传插件使用记录(一)配置及批量同步上传
- 使用Rancher-Gen动态更新配置文件
- shell脚本中使用iconv实现批量文件转码的代码分享
- Mycat使用篇: Mycat启动脚本及脚本配置文件详解
- 使用shell进行网络设备的批量备份、配置更新
- Mybatis+Oracle批量插入与更新的配置文件
- 使用Rancher-Gen动态更新配置文件
- .Net Reomting 在WEB客户端里使用配置文件方法