1

次のようなリモート実行powershellスクリプトを試します:

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

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 で実行されているコマンド。ローカル コンソールへの出力を取得するにはどうすればよいですか?

4

1 に答える 1

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スクリプトを実行するのに役立ちますが、スクリプトはリモートコンピューターに配置する必要があります。

と2番目の建設

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を使用してリモートスクリプトを実行するためにargs文字列を渡す方法がわかりません

于 2012-10-29T07:53:08.127 に答える