Write-log shell output of a command/exe

Hello,

I execute in my script various commands and would like to get into the main script log the output I get when executing it from a command prompt/PS shell, how could I achieve this correctly ?

here are examples of commands :

Execute-process -Path “control.exe” -Parameters “intl.cpl, /f:”$dirFiles\CopyInternationalSettings.xml"" -IgnoreExitCodes 1

	Dism /online /Get-Capabilities /Limitaccess

Thank you in advance

oops forgot the execute-process format on that Dism command sorry :slight_smile:

<code>Execute-process -Path &quot;$env:windir\system32\control.exe” -Parameters &quot;intl.cpl,, /f:&quot;$dirFiles\CopyInternationalSettings.xml&quot;” -IgnoreExitCodes 1 
Execute-process -path &quot;Dism&quot; -parameters &quot;/online /Get-Capabilities /Limitaccess&quot;</code>

Are you running your script in interactive mode?
You may use write-logs to show what is happening in your script.
I don’t know if there are any parameters with DISM to create a log file.

Ok let me clarify :

here is what happens when I launch one of those commands in prompt

<code>
C:\WINDOWS\system32&gt;Dism /online /Get-Capabilities /Limitaccess

Deployment Image Servicing and Management tool
Version: 10.0.14393.0

Image Version: 10.0.14393.0

Capability listing:

Capability Identity : App.Support.ContactSupport~~~~0.0.1.0
State : Installed

Capability Identity : App.Support.QuickAssist~~~~0.0.1.0
State : Installed

Capability Identity : Language.Basic~~~en-US~0.0.1.0
State : Installed

Capability Identity : Language.Handwriting~~~en-US~0.0.1.0
State : Installed

Capability Identity : Language.OCR~~~en-US~0.0.1.0
State : Installed</code>

I want to get back the the ouptu in write log

and yes dism can log in a seperate log, but I want it inside the PSADT script log, just like SCCM does with the smsts.log for task sequences

Sorry,

I want to get back the the ouptut in script log

use the -passthru switch.

Something like this:
$variable = execute-process -path(join-path -path $dirfiles -childpath “Dism”) parameters “/online /Get-Capabilities /Limitaccess” -passthru

$variable object will have properties stdout, stderr & ExitCode

Hi, thanks a lot, I didn’t think of that

we are almost there :slight_smile:

I used

$DismOutput = Execute-process -Path ‘Dism.exe’ -Parameters “/online /Get-Capabilities /Limitaccess” -passth
Write-Log $DismOutput

and I get all output in same line

is there a way of having the line breaks , menaing one line in log per line in the stdout?

I am thinking of using an array and doing a write-log for each line

nearer :

$DismOutput = Execute-process -Path ‘Dism.exe’ -Parameters “/online /Get-Capabilities /Limitaccess” -passthru

Write-Log “Check below output to see installed components :”

Write-Log $DismOutput.StdOut