I have a PowerShell script that has really good console status and progress information (using Write-Host) when I run it from PowerShell ISE. However, the script will be normally called by a batch command file (.cmd) as part of a larger process.
Currently, I call Script1.ps1 from the Command1.cmd like this:
FOR /f "delims= USEBACKQ" %%i in (`powershell.exe -file "C:\Powershell\Script1.ps1" -_Parm1 "!_Parm1!" -_Parm2 "!_Parm2!"`) DO SET ResponseMessage=%%i
FOR /f "tokens=1,2 delims=;" %%i in ("!ResponseMessage!") DO SET "ReturnCode=%%i" &SET "ResponseMessage=%%j"
IF !ReturnCode! NEQ 0 (
@ECHO Error in Script1.ps1. ReturnCode=!ReturnCode!. ResponseMessage=!ResponseMessage!
EXIT /B !ReturnCode!
)
It works perfectly, but I don't see any of the Write-Host status information from Script1.ps1, except the last one, which I parse into a return code and message.
I would like to see all the Write-Host status information in the command window as it is executing. I suspect Write-Host is not the right cmdlet for what I want to do. But, I haven't been able to get anything to work.
Here is a redacted sample of the Script1.ps1 console output, but it can process many files and hundreds of records within each. I don't need to extract any particular part of it, I would like to have it displayed step-by-step in its entirety.
:::Parms
[Redacted]
:::OpenSQL
:::Backing up DB
[Redacted]
:::Processing Files
[Redacted]
File Dev.Script1_Input3.xml
NameQuery: Dev.Script1_Input3
Count: 15
Updating...
10%...
20%...
30%...
40%...
50%...
60%...
70%...
80%...
90%...
100% !
Recs Added....: 3
Recs Updated..: 12
Done.
All data files processed.
Files Processed: 3
[Redacted]