Created
September 25, 2013 21:29
-
-
Save altrive/6706315 to your computer and use it in GitHub Desktop.
Sample Cmdlet to set PowerShell ISE status bar text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Main | |
| { | |
| $sw = [Diagnostics.Stopwatch]::StartNew() | |
| 1..10 | % { | |
| Set-ISEStatusText ("Step.{0}: Executing operation..." -f $_) | |
| sleep 1 | |
| } | |
| Set-ISEStatusText ("Elapsed: {0}[ms]" -f $sw.ElapsedMilliseconds) -Force | |
| } | |
| function Set-ISEStatusText | |
| { | |
| param ( | |
| [Parameter(Mandatory)] | |
| [string] $Message, | |
| [switch] $Force | |
| ) | |
| if ($host.Name -ne "Windows PowerShell ISE Host"){ | |
| return | |
| } | |
| #Set ISE StatusTest by reflection | |
| [Microsoft.PowerShell.Host.ISE.PowerShellTab].GetProperty("StatusText").SetValue($psise.CurrentPowerShellTab, $Message) | |
| if ($Force) | |
| { | |
| #GetNewClosure don't work in Register-EngineEvent context. Need to evaluate before use by [ScriptBlock]::Create | |
| #https://connect.microsoft.com/PowerShell/feedback/details/541754/getnewclosure-doesnt-work-on-register-objectevent | |
| $action = [ScriptBlock]::Create('[Microsoft.PowerShell.Host.ISE.PowerShellTab].GetProperty("StatusText").SetValue($psise.CurrentPowerShellTab, "{0}")' -f $Message) | |
| #Register OnIdele event | |
| $null = Register-EngineEvent -SourceIdentifier ([Management.Automation.PsEngineEvent]::OnIdle) -MaxTriggerCount 1 -Action $action | |
| } | |
| } | |
| . Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment