2012-10-24 2 views
1

psexec에 파워 쉘 : tst.ps1에 대한이 같은 PowerShell 스크립트 실행 원격 시도 출력

psexec -i \\host -u user -p pass PowerShell C:\tst\tst.ps1 

소스 코드를 원격으로 실행 명령이 스크립트를 실행하면

$TempLogFilePath = "$(Get-Date -u "%Y-%m-%d")-LogFileEventLog.log" 
Start-Transcript -Path "$TempLogFilePath" -Append 
echo (Get-Date –f o) 

Stop-Transcript 
Exit 0 

, 스크립트가 원격에 위치 기계, 출력에 로컬 머신에서 아무것도. cmd.exe에서 실행중인 명령입니다. 어떻게 로컬 콘솔에 출력을 얻을 수 있습니까?

+0

와 원격 스크립트를 실행하기위한 내가 인수 문자열을 전달하는 방법을 모르는 C'합니까 : \ TST \ tst.ps1' 원격에 존재 숙주? 스크립트 실행이 허용됩니까 ('Get-ExecutionPolicy')? –

+0

예, 스크립트 존재 "원격 시스템에서 스크립트 찾기"실행 허용됨 .PsExec v.1.98. – Shampoo

+0

'psexec ... powershell -NoLogo -File C : \ tst \ tst.ps1' 해 보셨습니까? –

답변

1
PsExec.exe \\host -u domain\user -p pass cmd /c "echo . | %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\WINDOWS\system32\Hello.ps1" 

이 구성은 원격 powershell 스크립트를 실행하는 데 도움이되지만 스크립트는 원격 컴퓨터에서 찾아야합니다.

및 초 건설

Param(
[alias("sp")] 
[string]$script_path, 
[alias("u")] 
[string]$user_name, 
[alias("p")] 
[string]$password, 
[alias("h")] 
[string]$host_name 
) 
$pass = convertto-securestring $password -asplaintext -force 
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user_name,$pass 
invoke-command -credential $mycred -computername $host_name -filepath $script_path 

하지만 난 PARAM

관련 문제