Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##
- ## 複数サーバ管理用スクリプト
- ##
- ##### ユーザ変数定義 #####
- # RLoginのパス
- $rlogin_path = ".\RLogin.exe"
- # サーバ情報テーブル(CSV形式)
- # 記載順:Name, IP, Port, User, Password, UseEntry
- ## 直接定義する場合
- #$records = @(
- #"Webサーバ_01,192.168.1.11,22,root,password,Default_SSH"
- #"Webサーバ_02,192.168.1.12,22,root,password,Default_SSH"
- #"Appサーバ_01,192.168.1.21,22,root,password,Default_SSH"
- #"Appサーバ_02,192.168.1.22,22,root,password,Default_SSH"
- #"DBサーバ_01,192.168.1.31,22,root,password,Default_SSH"
- #"DBサーバ_02,192.168.1.32,22,root,password,Default_SSH"
- #"dev01_開発用サーバ,192.168.1.101,22,root,password,Default_SSH"
- #"dev01_Webサーバ,192.168.1.11,22,root,password,Bastion_dev01_SSH"
- #"dev01_Appサーバ,192.168.1.21,22,root,password,Bastion_dev01_SSH"
- #"dev01_DBサーバ,192.168.1.31,22,root,password,Bastion_dev01_SSH"
- #"dev02_開発用サーバ,192.168.1.102,22,root,password,Default_SSH"
- #"dev02_Webサーバ,192.168.1.11,22,root,password,Bastion_dev02_SSH"
- #"dev02_Appサーバ,192.168.1.21,22,root,password,Bastion_dev02_SSH"
- #"dev02_DBサーバ,192.168.1.31,22,root,password,Bastion_dev02_SSH"
- #)
- ## CSVファイルから読み込ませる場合
- $csv_path = ".\server_list.csv"
- $records = (Get-Content $csv_path)
- $records = $records[1..($records.Length-1)] # ヘッダ除去
- ##### メイン処理 #####
- # 処理用変数定義(CSV形式の記載順と同じ順で定義すればよい)
- enum ReferenceIndex {
- Name
- IP
- Port
- User
- Password
- UseEntry
- }
- $objs = @()
- $no = 0
- # 表示用オブジェクト作成
- $records | %{
- $no += 1
- # 取得情報を変数に格納
- $record = $_.ToString().Split(",")
- $name = $record[[int]([ReferenceIndex]::Name)]
- $ip = $record[[int]([ReferenceIndex]::IP)]
- $port = $record[[int]([ReferenceIndex]::Port)]
- $user = $record[[int]([ReferenceIndex]::User)]
- $pass = $record[[int]([ReferenceIndex]::Password)]
- $entry = $record[[int]([ReferenceIndex]::UseEntry)]
- # ウィンドウやタブに表示される文字列(任意で変更可)
- $title = "$name[$ip]"
- # 上記情報から作成したコマンド
- $cmd = "$rlogin_path /ip $ip /port $port /user $user /pass '$pass' /title '$title' /entry '$entry' /inuse"
- # 最終的に表示されるオブジェクトの作成
- $obj = New-Object PSCustomObject
- $obj | Add-Member -NotePropertyMembers @{
- No = $no
- Name = $name
- IP = $ip
- Port = $port
- User = $user
- Password = $pass
- UseEntry = $entry
- 接続コマンド = $cmd
- }
- $objs += $obj
- }
- # テーブル表示
- $objs | Out-GridView -PassThru -Title "接続先を選択して下さい" | %{
- Invoke-Expression $_.接続コマンド
- echo $_.接続コマンド
- }
Add Comment
Please, Sign In to add comment