LoginSignup
2
2

More than 5 years have passed since last update.

Powershellでsshチックなことをする

Last updated at Posted at 2017-04-25

経緯

aws で、最近 iam role の付け替えが出来るようになりました。
早速 windows の iam role を起動したまま切り替えたのですが、その際に ssm が connection timeout になってしまいました。
Restart-Service Ec2ConfigOnline になるのですが、対象サーバがそれなりにあったので、もう少し楽にできないかと思い、 powershell を使うことにしました。

方法

winrm を使用すれば、 powershell でリモート接続しコマンドを叩ける。
ざっくりと二通りあったのでメモしておきます。

wirm でリモート接続するためには、 Enable-PSRemoting で有効化する必要があるので、詳しくは参考 URL を見ていただければと。。。

方法其ノ一

セッションをはる

New-PSSession -ComputerName
Public DNS , Private DNS どちらでも行けました。検証済み

下記でリモート接続しているサーバに対してコマンドを叩く

Invoke-Command -Session $sess -ScriptBlock {ls;}

添付画像のように、変数でうけるのがベターっぽいです。

jump.png

補足

New-PSSession を使用すると、サインアウトしても session は残るので、 Remove-Session してあげましょう。

方法其ノ弐

New-PSSession だけではなく、 Enter-PSSession でも出来るようです。

Enter-PSSession -ComputerName <Public DNS or Private DNS>

jump 2.png

ほぼ見えてませんが、下記のようになってます。
多段sshしている気分になります

[Public DNS]: PS C:¥Users¥hoge¥Documents>

まとめ
RDP したくないから、ssm使ってるのになんでやねん!ってなりました。
ただ、一つ知見が増えて良かったです。

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2