Guest User

Untitled

a guest
Jan 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. ##
  2. ## 複数サーバ管理用スクリプト
  3. ##
  4.  
  5.  
  6. ##### ユーザ変数定義 #####
  7.  
  8. # RLoginのパス
  9. $rlogin_path = ".\RLogin.exe"
  10.  
  11. # サーバ情報テーブル(CSV形式)
  12. # 記載順:Name, IP, Port, User, Password, UseEntry
  13.  
  14. ## 直接定義する場合
  15. #$records = @(
  16. #"Webサーバ_01,192.168.1.11,22,root,password,Default_SSH"
  17. #"Webサーバ_02,192.168.1.12,22,root,password,Default_SSH"
  18. #"Appサーバ_01,192.168.1.21,22,root,password,Default_SSH"
  19. #"Appサーバ_02,192.168.1.22,22,root,password,Default_SSH"
  20. #"DBサーバ_01,192.168.1.31,22,root,password,Default_SSH"
  21. #"DBサーバ_02,192.168.1.32,22,root,password,Default_SSH"
  22. #"dev01_開発用サーバ,192.168.1.101,22,root,password,Default_SSH"
  23. #"dev01_Webサーバ,192.168.1.11,22,root,password,Bastion_dev01_SSH"
  24. #"dev01_Appサーバ,192.168.1.21,22,root,password,Bastion_dev01_SSH"
  25. #"dev01_DBサーバ,192.168.1.31,22,root,password,Bastion_dev01_SSH"
  26. #"dev02_開発用サーバ,192.168.1.102,22,root,password,Default_SSH"
  27. #"dev02_Webサーバ,192.168.1.11,22,root,password,Bastion_dev02_SSH"
  28. #"dev02_Appサーバ,192.168.1.21,22,root,password,Bastion_dev02_SSH"
  29. #"dev02_DBサーバ,192.168.1.31,22,root,password,Bastion_dev02_SSH"
  30. #)
  31.  
  32. ## CSVファイルから読み込ませる場合
  33. $csv_path = ".\server_list.csv"
  34. $records = (Get-Content $csv_path)
  35. $records = $records[1..($records.Length-1)] # ヘッダ除去
  36.  
  37.  
  38. ##### メイン処理 #####
  39.  
  40. # 処理用変数定義(CSV形式の記載順と同じ順で定義すればよい)
  41. enum ReferenceIndex {
  42. Name
  43. IP
  44. Port
  45. User
  46. Password
  47. UseEntry
  48. }
  49.  
  50. $objs = @()
  51. $no = 0
  52.  
  53. # 表示用オブジェクト作成
  54. $records | %{
  55. $no += 1
  56.  
  57. # 取得情報を変数に格納
  58. $record = $_.ToString().Split(",")
  59. $name = $record[[int]([ReferenceIndex]::Name)]
  60. $ip = $record[[int]([ReferenceIndex]::IP)]
  61. $port = $record[[int]([ReferenceIndex]::Port)]
  62. $user = $record[[int]([ReferenceIndex]::User)]
  63. $pass = $record[[int]([ReferenceIndex]::Password)]
  64. $entry = $record[[int]([ReferenceIndex]::UseEntry)]
  65.  
  66. # ウィンドウやタブに表示される文字列(任意で変更可)
  67. $title = "$name[$ip]"
  68.  
  69. # 上記情報から作成したコマンド
  70. $cmd = "$rlogin_path /ip $ip /port $port /user $user /pass '$pass' /title '$title' /entry '$entry' /inuse"
  71.  
  72. # 最終的に表示されるオブジェクトの作成
  73. $obj = New-Object PSCustomObject
  74. $obj | Add-Member -NotePropertyMembers @{
  75. No = $no
  76. Name = $name
  77. IP = $ip
  78. Port = $port
  79. User = $user
  80. Password = $pass
  81. UseEntry = $entry
  82. 接続コマンド = $cmd
  83. }
  84. $objs += $obj
  85. }
  86.  
  87. # テーブル表示
  88. $objs | Out-GridView -PassThru -Title "接続先を選択して下さい" | %{
  89. Invoke-Expression $_.接続コマンド
  90. echo $_.接続コマンド
  91. }
Add Comment
Please, Sign In to add comment