Navcontainerhelper: Suppress Module Load Messages

Created on 4 Feb 2021  路  8Comments  路  Source: microsoft/navcontainerhelper

Describe the issue
We use bccontainerhelper to execute various tasks from a vscode extension and other applications. We do this by invoking the commands in a powershell process and capturing the output.
This worked fine with navcontainerhelper but since bccontainerhelper introduces itself upon module loading with a write-host output, we have issues capturing what we actually want to.

Scripts used to create container and cause the issue

Import-Module bccontainerhelper

Full output of scripts

BcContainerHelper version 2.0.1

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

Workaround
Works but very ugly...

function global:Write-Host() {}
import-module bccontainerhelper
remove-item function:\write-host -ea 0

Proposal
Please change all module load messages from write-host to a write-output so we can capture the output with Out-Null or introduce a parameter -Silent that we can pass to the import-module command.

Fix Ready Ships in a future version

Most helpful comment

Not for the load-module thing - for the rest, yes.

All 8 comments

For this specific set of messages, it could make a lot of sense to use Write-Output I think - I will investigate.
I am also considering changing the remaining write-hosts to write-information, write-verbose and write-warning and then setting the preferences for these settings accordingly, but that might be a risky operation, that I will check thoroughly first.

Just a quick note that this indeed would be risky... :)

Not for the load-module thing - for the rest, yes.

@marknitek - have you tried your suggestion yourself?
I cannot get import-module bccontainerhelper | out-null to avoid printing stuff which is sent to output.

No that suggestion was based on previous experience with write-host and write-output.

I tried it now myself in one of my modules and i have it the other way around: write-output does not print anything at all no matter if i'am using out-null or not...

Ok then here is a not so elegant but working approach:

Add Parameter Silent to .psm1

param([switch]$Silent)

...

if (!$Silent) {
    Write-Host "BcContainerHelper version ..."
}

Importing:

import-module bccontainerhelper -ArgumentList $true

Thanks, I learned something new.
I had no idea you could transfer arguments to a module.

Fix shipped in 2.0.5

Was this page helpful?
0 / 5 - 0 ratings