Hiding write-progress when non-interactive

Welcome Forums General PowerShell Q&A Hiding write-progress when non-interactive

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5354

    Points: 0
    Rank: Member

    by davidski at 2012-12-16 07:58:37

    I have a script that takes a while to run (>30 minutes). When running interactively (usually via the ISE), I have a number of write-progress indicators to provide feedback as to the script's progress. The challenge is when scheduling the script as a job (using the PoSH V3 scheduled job cmdlets), as the output captured and displayed via receive-job also contains the progress bars, which is hard to look through.

    Is there a better solution to not display the write-progress indicators when run as a scheduled task? I thought about adding in checks for whether powershell.exe is being run with the -noninteractive flag and wrapping all the write-progress with logic tests, but that's a lot of code and obfuscation for a simple need. Hoping there's a more clever way of approaching this!


    by MattG at 2012-12-16 17:07:31

    Hi David,

    Assuming you run your commands either from the ISE or via a scheduled job, the following would be a simple solution:
    if ($psISE -eq $null)
    $ProgressPreference = 'Continue'
    $ProgressPreference = 'SilentlyContinue'
    The $psISE variable will only be populated if you're in the ISE. Otherwise, Write-Progress output will be ignored.

    by davidski at 2012-12-17 13:00:33

    Whoa. I never noticed that variable before. Good stuff. That should be perfect for this solution. Thanks!

    by nohandle at 2012-12-18 03:22:09

    Another way is to read the value from$host.name

The topic ‘Hiding write-progress when non-interactive’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort