Write-log shell output of a command/exe

//Write-log shell output of a command/exe
Write-log shell output of a command/exe 2017-08-08T11:19:13+00:00

The Toolkit Forums General Write-log shell output of a command/exe

  • Author
    Posts
  • jaegermaster
    Participant
    Post count: 29
    #2221 |

    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

  • jaegermaster
    Participant
    Post count: 29

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

  • Francois
    Participant
    Post count: 101
    <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.

  • jaegermaster
    Participant
    Post count: 29

    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

  • jaegermaster
    Participant
    Post count: 29

    Sorry,

    I want to get back the the ouptut in script log

  • Adrian
    Participant
    Post count: 1

    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

  • jaegermaster
    Participant
    Post count: 29

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

    we are almost there 🙂

    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

  • jaegermaster
    Participant
    Post count: 29

    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

    • This reply was modified 3 months, 1 week ago by  jaegermaster.

You must be logged in to reply to this topic.