Avatar of David Johnson, CD
David Johnson, CD
Flag for Canada asked on

clear-host doesn't close Write-Progress

here is my Powershell default configuration in which I set up my PowerShell ise.. while it is adding in the modules I have a progress bar running lines 23-26 and after they are loaded I do a clear-host in line 41 which should close the progress bar.. but The Progress bar is still there
$time = Get-Date 
$user = get-content env:username
Write-Output ( 'Hi, '+ $user +' Welcome Back! It is now '+$time)
$mydocuments = [environment]::getfolderpath('mydocuments')
$mytemp = '$mydocuments\windowsPowerShell\ScriptScratch'
$mydoc = $mydocuments + '\WindowsPowerShell\Scripts\'
Set-Variable -name HOME -value $mydoc -Force
write-output('Enumerating Modules')
$modules = get-module -listavailable
Write-Output ('There are ' + {0} + ' Available' -f $modules.count)
$modules.name
Write-Output ('Hang on While I import modules')
Write-Output ('Importing ' + {0} +' Modules' -f $modules.Count)
if ([System.Windows.Input.Keyboard]::IsKeyDown('Ctrl') -eq $false)
{
 
$counter = 0
foreach ($module in $modules) 
    { 
    $counter ++
    $total = $modules.Count
    $activity = "Importing Module: $module.name "
    Write-Progress -Activity $activity `
        -status "Module: $counter of $total" `
        -percentComplete ($counter / $modules.count*100)
    import-module -name $module.Name -erroraction SilentlyContinue -WarningAction SilentlyContinue
    }
#
  Start-Steroids
}
#Leave any comments with the # sign
#Install Quest Active Directory CMDLets
Write-Output 'Installing Quest Active Directory Tools.  Please wait...'
Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
Write-Output 'Installing Exchange Management Tools.  Please wait...'
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -ErrorAction SilentlyContinue
Write-Output 'Installing MDT Tools... Please wait..'
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue
Write-Output 'Installing TFS Tools... Please wait..'
Add-PSSnapin Microsoft.TeamFoundation.PowerShell -ErrorAction Continue
Clear-Host
#TFS only on Windows 10
$version = get-wmiobject -class win32_operatingSystem | select-object version
if ($version.version -gt '10.0.0') {
    get-tfsserver -Name 'http://localhost:8080/tfs/Windows Powershell'
    #Script Browser Begin
    #Version: 1.3.2
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\System.Windows.Interactivity.dll'
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\ScriptBrowser.dll'
    Add-Type -Path 'C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\BestPractices.dll'
    $scriptBrowser = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add('Script Browser', [ScriptExplorer.Views.MainView], $true)
    $scriptAnalyzer = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add('Script Analyzer', [BestPractices.Views.BestPracticesView], $true)
    $psISE.CurrentPowerShellTab.VisibleVerticalAddOnTools.SelectedAddOnTool = $scriptBrowser
    #Script Browser End
    }
$time2 = Get-Date
$time3 = $time2 - $time
Write-Output ('It took  ' + $time3.Minutes.ToString() + ' Minutes and ' + $time3.seconds.ToString() + ' Seconds to load the '+ $modules.Count + ' Modules')
Write-Output ('The Current Time is:' +$time2)
cd $mydoc

Open in new window

Powershell

Avatar of undefined
Last Comment
David Johnson, CD

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Johnson, CD

ASKER
Thank you, I didn't know about that and it was bugging me for a while
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy