Reputation: 525
I try remote execute powershell script like this:
psexec -i \\host -u user -p pass PowerShell C:\tst\tst.ps1
Source code for 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
When a run command to remote execute this script, script locate on remote machine, in local machine in output nothing. Command running in cmd.exe. How i can get output to local console?
Upvotes: 1
Views: 3157
Reputation: 525
PsExec.exe \\host -u domain\user -p pass cmd /c "echo . | %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\WINDOWS\system32\Hello.ps1"
This construction help you to run remote powershell script, but script should be locate on remote computer.
and second construction
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
but i don't know how i can pass args string for execute remote script with param
Upvotes: 1