Write-Progress in my profile

Powershell 5.1
Windows 10

I setup a $profile and this is my code

# directory where my scripts are stored


Get-ChildItem "${psdir}\*.ps1" 

Cd \util 

get-service nscp

get-service teamviewer


Write-Host "Welcome to Tom's Custom PowerShell Environment" 

All works fine

Now I want to add this
Import-Module VMware.PowerCLI So it loads every time I start powershell
Since the import-module takes awhile to load I would like to put a progress bar on the screen

I tried this

For ($i=0; $i -le 100; $i++) {
    Import-Module VMware.PowerCLI 
    Write-Progress -Activity "ActivityString" -Status "StatusString" -PercentComplete $i -CurrentOperation "CurrentOperationString"

I do not see the bar

It take this long to run
Loading personal and system profiles took 34953ms.

Any ideas

Thank you


I changed this around

For ($i=0; $i -le 100; $i++) {
    Write-Progress -Activity "Load VMware PowerCLI" -Status "Current Count: $i" -PercentComplete $i -CurrentOperation "Please wait ..."
    Import-Module VMware.PowerCLI

The process bar shows now but the counter stays at 0 and between the { } nothing should be something displayed.



just as an aside: properly installed modules do autoload if needed since Powershell version 3.0. And even if you want to make sure a script does not run without a desired module you could use the #requires statement at the beginning of your script.

In your for loop the Import-Module command blocks anything else until it’s finished loading the module. Then it writes the Progress, continues with the next iteration of the loop and tries to import the module again. And again and again and again … and this 100 times. :wink:

You should have read the help for Import-Module completely. Then you’d know that you can use the parameter -Verbose to ask the cmdlet to show a progress. :wink:


#Requires is that not a comment line:

The verbose option gives details that I am not interested in seeing

This code is almost working as I would like

For ($i=0; $i -le 100; $i++) {
Write-Progress -Activity “Load VMware PowerCLI” -Status “Current Count: $i” -PercentComplete $i -CurrentOperation “Please wait …”
Import-Module VMware.PowerCLI

Just does not count or show bar I have a screen shoot but can not paste in this message how can I add images to here also

Why don’t you click on the link I posted and read the documentation?

Tom … it cannot work this way at all … never.

You would need to offload the task of loading the module and parse the verbose output to get a progress bar. I’d recommend to save your energy for something really useful. :wink: