VMware Cloud Community
lElOUCHE_79
Enthusiast
Enthusiast

Show Progress Barre in console

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"

Reply
0 Kudos
3 Replies
lElOUCHE_79
Enthusiast
Enthusiast

Got it and solved the issue

Reply
0 Kudos
RDPetruska
Leadership
Leadership

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

Reply
0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

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

Reply
0 Kudos