2018. 5. 25. 15:39
Powershell
1. AD 등록된 서버
AD 관리자 계정으로 스크립트 실행
Invoke-Command -ComputerName host1, host2 -ScriptBlock {Invoke-Expression 'C:\script.bat'}
2.AD에 등록되지 않은 서버
(1) 로컬 서버의 "신뢰할 수 있는 호스트 목록" 에 원격 서버 추가하기.
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "원격서버IP 혹은 호스트네임"
여러개의 원격 서버를 지정해야할 경우
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "host1, host2"
(2)원격서버에서 스크립트 실행
$password='p@ssword'|convertto-securestring -asplaintext -force;
$cred=new-object -typename system.management.automation.pscredential('Domain\Username',$password);
$s = New-PSSession -computer "127.0.0.1" -credential $cred;
Invoke-Command -Session $s -ScriptBlock { cmd /c "c:\myfile.bat" };
Remove-PSSession $s;
'Powershell' 카테고리의 다른 글
AD계정 정보 가져오기 (0) | 2018.12.26 |
---|---|
Powershell 방화벽 관리하기 (0) | 2018.10.27 |
TCP 소켓 통신 예제 (0) | 2018.10.27 |
로컬( local)계정 생성후 Administrator 그룹에 넣기 (0) | 2018.10.27 |