Progress Barre in console

Hello

I created the following function and I have problems when displaying in the console and loading the modules.
I don’t want to see the loading of modules in the console, so I only want to see the progress bar.
Is there someone who could help me correct that?

function Modulescheck ($m) {
    foreach ($Module in $m){
    # If module is imported say that and do nothing
    if (Get-Module | Where-Object {$_.Name -eq $m}) {
        write-host "Module $m "  -f Magenta -NoNewLine  
        write-host "`nis already imported." -f Green
    } else {
        # If module is not imported, but available on disk then import
        Write-Warning "Module $m is NOT imported (must be installed before starting)."
        if (Get-Module -ListAvailable | Where-Object {$_.Name -eq $m}) {
            Write-Progress -Activity "Importing module $m" -Status "Importing module $m" -PercentComplete (($Module.IndexOf($m) + 1) / ($Module.Count) * 100)
            Import-Module -Name $m -ProgressAction SilentlyContinue
            start-sleep -Seconds 2            
        } else {
            # If module is not imported, not available on disk, but is in online gallery then install and import
            if (Find-Module -Name $m | Where-Object {$_.Name -eq $m}) {
                Install-Module -Name $m -Force -Verbose -Scope CurrentUser
                Write-Progress -Activity "Importing module $m" -Status "Importing module $m" -PercentComplete (($Module.IndexOf($m) + 1) / ($Module.Count) * 100)
                Import-Module $m -Verbose
            } else {
                # If module is not imported, not available and not in online gallery then abort
                Write-Warning "Module $m not imported, not available and not in online gallery, exiting."
                EXIT 1
            }
        }
    }
    }
}
Modulescheck "CredentialManager"
Modulescheck "VMware.PowerCLI"

I’m unsure about what your question actually is. The default behaviour of Import-Module is to load the module without any verbose output. So

Import-Module -Name <ModuleName> 

should do the trick.

In your code line 19 you’re running

That produces verbose output. If you don’t want that you should omit the parameter -Verbose. :man_shrugging:t3:

Regardless of all that: In line 2

you create the loop variable “$module” from the array “$m” - what’s BTW a really bad variable name for this purpose. A much more logical way would be to use

foreach ($Module in $ModuleList){

anyway … you create the loop variable $Module but you use the array variable $m
inside your loop !! That might not be an issue as long as you only provide a single module to your function. But it will cause problems when you actually provide a list of modules. :point_up:t3: :point_up:t3: