View console output from powershell

PowerShell script exchange

View console output from powershell

Veeam Logoby benjos » Wed Apr 23, 2014 8:47 pm

I have set up a script to run after a back up is done on the "Post Job Activity" the command calls for c:\users\ben\desktop\test.cmd the cmd file has the command
Code: Select all
start powershell.exe c:\users\ben\desktop\test1.ps1
the powershell script is executed correctly but the console does not open so I can see the output from the script. Is there a way to call the script from veeam and be able to see the console so I can see the write-host output of the powershell script?
benjos
Novice
 
Posts: 3
Liked: never
Joined: Wed Apr 23, 2014 8:39 pm
Full Name: Benjamin Perez

Re: View console output from powershell

Veeam Logoby v.Eremin » Thu Apr 24, 2014 8:10 am

You mean you want to see the PS pipeline and what is output to it during script execution? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: View console output from powershell

Veeam Logoby tdewin » Thu Apr 24, 2014 8:52 am

You could create a logfile in your script and then pipeline your commands to outfile

Code: Select all
$logfile = ("{0}\logfile{1}.txt" -f "c:\d",(Get-Date -format "yyyyMMddhhmmss"))

"hello" | Out-File -Append $logfile
get-process | Out-File -Append $logfile
tdewin
Veeam Software
 
Posts: 1043
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: View console output from powershell

Veeam Logoby benjos » Thu Apr 24, 2014 1:33 pm

v.Eremin wrote:You mean you want to see the PS pipeline and what is output to it during script execution? Thanks.

Correct, I would like to see the output during script execution. The scrip copies my backups to an external drive and while it is executing I have not idea of how far in the process the script is. So how do I see output during script execution?
benjos
Novice
 
Posts: 3
Liked: never
Joined: Wed Apr 23, 2014 8:39 pm
Full Name: Benjamin Perez

Re: View console output from powershell

Veeam Logoby v.Eremin » Thu Apr 24, 2014 1:59 pm

Can you try to run this very command from the command line ("Run")? Will you see corresponding PS window or not? Does adding -noexit parameter make any difference (start powershell.exe -noexit)? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: View console output from powershell

Veeam Logoby benjos » Thu Apr 24, 2014 2:44 pm

I have tried to use (start powershell.exe -noexit) but I still don't see the output. I can tell the script is running because under task manager I see the process but I don't see a window with output. If I double click the cmd file that calls (start powershell.exe) I see the window but not when called by Veeam from the Post Job Activity.
benjos
Novice
 
Posts: 3
Liked: never
Joined: Wed Apr 23, 2014 8:39 pm
Full Name: Benjamin Perez

Re: View console output from powershell

Veeam Logoby v.Eremin » Thu Apr 24, 2014 7:21 pm

May be there is some account issue, since post job activity is executed under veeam service account? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: View console output from powershell

Veeam Logoby tdewin » Mon Apr 28, 2014 7:38 am

Checked it with Process Explorer. Powershell is executed as service account as expected and it is not possible to bring the window to the front. Again I would advise you to write to a log file in your script.

Then from another window you can monitor the process with the tail and wait option in powershell v3
Get-Content -Tail 10 -wait E:\logs\jobjob.log


Apparently (if you are not using v3), you can find a similar command in the ps community extensions:
Get-FileTail

http://pscx.codeplex.com/
tdewin
Veeam Software
 
Posts: 1043
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests