사용자 도구

사이트 도구


powershell

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
powershell [2020/04/09 02:30] rex8312powershell [2024/03/23 02:38] (현재) – 바깥 편집 127.0.0.1
줄 5: 줄 5:
  
 <code powershell> <code powershell>
 +# ps remoting 기능 활성화
 Enable-PSRemoting -Force Enable-PSRemoting -Force
 Set-Item wsman:\localhost\client\trustedhosts * Set-Item wsman:\localhost\client\trustedhosts *
 Restart-Service WinRM Restart-Service WinRM
  
 +# 연결 테스트
 Test-WsMan COMPUTER Test-WsMan COMPUTER
 +
 +# 명령어 한개 실행
 Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME
 +# 예) Invoke-Command -ComputerName IP -ScriptBlock { cmd /c "명령어1 && 명령어2" } -credential 유저
 +
 +# 세션 연결
 Enter-PSSession -ComputerName COMPUTER -Credential USER Enter-PSSession -ComputerName COMPUTER -Credential USER
 </code> </code>
  
 +  * credential 생성
 +    * https://talsu.net/?p=2108
 +
 +<code powershell>
 +# 암호입력
 +$secureString = Read-Host -AsSecureString 
 +# 문자열로 변환
 +$secureString | ConvertFrom-SecureString  
 +
 +# credential.txt에 저장
 +Read-Host -AsSecureString | ConvertFrom-SecureString | Set-Content "credential.txt"
 +# creadential.txt에서 credential 복원
 +Set-Variable -Name user -Value 유저
 +Set-Variable -Name ip -Value ???.???.???.???
 +$secureString = Get-Content "credential.txt" | ConvertTo-SecureString
 +$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secureString
 +$session = New-PSSession -ComputerName $ip -Credential $cred
 +# Invoke-Command -ComputerName $ip -ScriptBlock { cmd /c "activate base && where python && ipconfig" } -credential $cred
 +</code>
  
  
powershell.1586399425.txt.gz · 마지막으로 수정됨: (바깥 편집)