locked
How to hide all PS code and results from the screen while running except for Write-Host? RRS feed

  • Question

  • Hi All,

    I have a script that works well which I wrote for my helpdesk staff to use to prep new PCs.

    I'd like to change the user experience to "hide" all the code and code execution output results while running...so as to display only what I specify is written to the screen making it easier for them to see which stage / step the machine prep is busy with...

    E.G...

    How do I get the below code to run...and while running only output the Write-Host parts to the PS shell window showing nothing else during execution.

    Write-Host "IMAC Script Ver 2.3 running $Date" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "Step 1 - Setting up the OEM Support Information..." -ForegroundColor Yellow
    $path = "HKLM:\Software\Microsoft\Windows\CurrentVersion"
    New-Item -Path $path -Name OEMInformation –Force
    New-ItemProperty -Path $path\OEMInformation -Name "HelpCustomized" -Value 0 -PropertyType "DWord"
    ...
    ..
    .
    Write-Host "Step 1 complete" -ForegroundColor Green
    Write-Host ""
    Write-Host "Step 2 - Configuring 'Intel NIC' wake on LAN settings..."
    Set-NetAdapterAdvancedProperty Ethernet -DisplayName "Wake on Magic Packet" -DisplayValue "Enabled"
    ...
    ..
    .

    As always, thank you for you time in advance!

    durrie.

    Thursday, June 6, 2019 7:51 AM

Answers

  • Assign any line you don't want output from to a variables.  You can also pipe any command to "Out-Null".


    \_(ツ)_/

    • Marked as answer by durrie Thursday, June 6, 2019 9:12 AM
    Thursday, June 6, 2019 7:55 AM

All replies

  • Assign any line you don't want output from to a variables.  You can also pipe any command to "Out-Null".


    \_(ツ)_/

    • Marked as answer by durrie Thursday, June 6, 2019 9:12 AM
    Thursday, June 6, 2019 7:55 AM
  • Thank you JRV I was using | Out-Null which hides the results of the code lines but each line was obviously still being displayed.

    I can confirm I have the desired affect by assigning a variable to each line...however...assigning each of the MANY lines to a variable will be a very tedious task!

    My plan to address that is below...I'd appreciate you advice if I'm on the right track or not?

    1. Create functions for each of the steps in the script. Adding MANY lines of code to each "functional step"

    2. Assign variables to each function

    3. Execute each function as it's assigned variable | Out-Null

    Will this work? Or will the script syntax from setting up each function be returned to the PS window defeating the desired outcome?

    Thursday, June 6, 2019 8:44 AM
  • Code executed from a PS1 file does not display.

    What you are claiming only occurs if you copy and paste code.

    Code executed in ISE will display.  ISE is an edit tool and is  not intended as an execution environment.


    \_(ツ)_/

    Thursday, June 6, 2019 8:51 AM