반응형
● 특정 명령 실행
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
Get-Command -Module Posh-SSH # Check that the module is installable
Install-Module -Name Posh-SSH -RequiredVersion 1.7.6 # Install ssh Module
# 비밀번호 설정
$sshPwd = ConvertTo-SecureString -String "Remote_ssh_password" -AsPlainText -Force
# 자격증명 생성
$sshCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist "your_account", $sshPwd
# 대상 서버 접속
$SSHSession = New-SSHSession -ComputerName "Remote_ssh_hostip" -Credential $sshCredential -AcceptKey:$true
# 대상 서버에 명령 실행
Invoke-SSHCommand -SSHSession $SSHSession -Command "ifconfig"
# 연결 끊기
$sftpSession.Disconnect()
Remove-SSHSession -SSHSession $SSHSession
Remove-variable SSHSession
|
cs |
● 파일 전송
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
Get-Command -Module Posh-SSH # Check that the module is installable
Install-Module -Name Posh-SSH -RequiredVersion 1.7.6 # Install ssh Module
# 비밀번호 설정
$sshPwd = ConvertTo-SecureString -String "Remote_ssh_password" -AsPlainText -Force
# 자격증명 생성
$sshCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist "Remote_ssh_account", $sshPwd
# 대상 서버 접속
$SSHSession = New-SSHSession -ComputerName "Remote_ssh_hostip" -Credential $sshCredential -AcceptKey:$true
# 대상 서버에 파일 전송
$sftpSession = New-SFTPSession -ComputerName "Remote_ssh_hostip" -Credential $sshCredential
Set-SFTPFile -SFTPSession $sftpSession -LocalFile "C:\Users\Linux_Shell.sh" -RemotePath "/"
# 연결 끊기
$sftpSession.Disconnect()
Remove-SSHSession -SSHSession $SSHSession
Remove-variable SSHSession
|
cs |
반응형
'OS-서버 > 윈도우' 카테고리의 다른 글
VBS 문법 (0) | 2018.10.05 |
---|---|
Powershell 엑셀 사용 (0) | 2018.10.05 |
Powershell XML (0) | 2018.03.20 |
Powershell 잡지식 (0) | 2018.03.20 |
Powershell 원격 제어 (0) | 2018.03.20 |