Automation

 View Only
  • 1.  Show Progress Barre in console

    Posted Dec 10, 2023 12:42 PM

    Hello

    Not sure if it's the right place to post my question here. 

    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"



  • 2.  RE: Show Progress Barre in console

    Posted Dec 10, 2023 05:06 PM

    Got it and solved the issue



  • 3.  RE: Show Progress Barre in console

    Posted Dec 11, 2023 12:51 PM

    So, for others searching the same problem, what WAS the solution?



  • 4.  RE: Show Progress Barre in console

    Posted Dec 11, 2023 05:10 PM

    I completely changed my approach. I was making mistakes in my actions.