Hi,
I have the following line in Deploy-Application.ps1.
<pre class=“brush: text; gutter: true; first-line: 1; highlight: []; html-script: false”>Execute-Process -Path ‘powershell.exe’ -Parameters “-ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File "$dirFiles\script.ps1
” > C:\Windows\Logs\Software\script.log"
When I execute ‘Deploy-Application.exe Install’, in the log I can see the following line is executed.
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File "C:\Users\admin\Desktop\script\Files\script.ps1" > C:\Windows\Logs\Software\script.log
But ‘script.log’ doesn’t get created. If I execute that line manually, it works fine.
Any help appreciated.
I did some tracing with ProcMon to find the difference, when running the command below via PSADT vs directly.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File “C:\Users\user\Desktop\test\Files\test.ps1” > “C:\users\user\desktop\out.txt”
Directly
PID: 10280, Command line: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -File C:\Users\user\Desktop\test\Files\test.ps1
PID: 12480, Command line: “C:\Windows\system32\PING.EXE” localhost
PSADT
PID: 14220, Command line: “C:\Users\user\Desktop\test\Deploy-Application.exe” Install
PID: 2832, Command line: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -File “C:\Users\user\Desktop\test\Files\test.ps1” > “C:\users\user\desktop\out.txt”
PID: 17328, Command line: “C:\Windows\system32\PING.EXE” localhost
For whatever reason, the direct command doesn’t output to file right away, while PSADT tries to. Anyway, I got around the issue by redirecting the output directly in a powershell script I was executing via PSADT (example below).
$command = “ping.exe”
$args = “localhost | out-file C:\temp\out.txt”
$args = $args.Split(" ")
$output = cmd /c $command $args 2>
&1
$output | out-file C:\temp\out.txt