2012-10-24 52 views
1

我嘗試遠程執行PowerShell腳本是這樣的:對於tst.ps1PSEXEC 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

是的,腳本存在「位於遠程機器上的腳本」執行allowed.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 

,但我不知道我可以通過ARGS字符串與PARAM