Link to home
Start Free TrialLog in
Avatar of David Johnson, CD
David Johnson, CDFlag 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 User generated image
$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

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Johnson, CD

ASKER

Thank you, I didn't know about that and it was bugging me for a while