Showing posts with label ISE. Show all posts
Showing posts with label ISE. Show all posts

26 February, 2020

Add PID to Powershell Window - To quickly fix lock ups.


This should come in handy…
If you are like me, and have a few different ISE windows open at any given time…
And one of them locks-up on you

Knowing which one to kill from the task manager, is almost impossible… 
But if you know its PID…
Get-Process -Id 15868 | Stop-Process -Force

You can kill the frozen window, and when you re-open ISE, its session saving feature will restore it.

 The work is done here:
(Get-Process -ID $PID).Id

Adding the PID to the title of the PowerShell window is done in the Profile…
  • Profile.ps1
  • Microsoft.PowerShell_profile.ps1
  • Microsoft.PowerShellISE_profile.ps1
Here is an example:
function Test-IsAdmin {([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")}
if (!(Test-IsAdmin)){$Host.UI.RawUI.WindowTitle = "STANDARD Emetic Gyroscopic Discombobulator - PLEBE Edition - (PID - $((Get-Process -ID $PID).Id))"}
else {$Host.UI.RawUI.WindowTitle = "DELUXE Emetic Gyroscopic Discombobulator - God Mode (PID - $((Get-Process -ID $PID).Id))"}

That whole Test-IsAdmin is not needed – I just have my window tricked out (I’ve even changed the icon for the Admin sessions).

The only thing needed would be something like this:
Host.UI.RawUI.WindowTitle = "PowerShell ISE - (PID - $((Get-Process -ID $PID).Id))"

17 January, 2020

Powershell ISE, HEX colors - Me make pretty!

This is just a way to add more color to the output in ISE.
Note that: There is no '-NoNewLine' available - 'PrivateData.' Does not include it.




# Note that in that '#AABBCCDD' pattern used below -
    # The 'AA' portion is the 'transparency' (followed by the HEX color value 'BBCCDD') - So;
        # FF, is the HEX equvalent of 255, full value, NO 'transparency' - Full color.
        # 80, in HEX, is equal to 128 (about half of 255), so would be about 50% 'transparency'
        # 00, in HEX, is 00 (zero), so would be completley transparent - No color.

# If that 'AA' portion is omitted, and just the #Hex value is used, it still works just fine.
    ## So, For example, on that '$host.PrivateData.ErrorBackgroundColor' line -
    ### '#7B00FF' and '#FF7B00FF' - Mean the same thing. NO 'transparency' - Full color.
   
If (($host.Name) -match "ISE") {
    # This just gathers the current / default Error reporting colors, so they can be restored.
    $ErrFgCol = (((((($host.privatedata) | Out-String).Split("`n|`r",[System.StringSplitOptions]::RemoveEmptyEntries))[13]).Split(':'))[1]).Trim()
    $ErrBgCol = (((((($host.privatedata) | Out-String).Split("`n|`r",[System.StringSplitOptions]::RemoveEmptyEntries))[14]).Split(':'))[1]).Trim()
        $host.PrivateData.ErrorForegroundColor  = '#FFFF8C00' # Set the color to Orange, for example.
        $host.PrivateData.ErrorBackgroundColor  = '#FF7B00FF' # Set the color to Purple, for example
            $host.UI.WriteErrorLine('▒▒▒▒▒▒▒▒▒▒▒▒▒▒')
            $host.UI.WriteErrorLine('         WORDS         ')
            $host.UI.WriteErrorLine('▒▒▒▒▒▒▒▒▒▒▒▒▒▒')
        $host.PrivateData.ErrorForegroundColor  = $ErrFgCol # Set the color back to its default - Red / '#FFFF0000'
        $host.PrivateData.ErrorBackgroundColor  = $ErrBgCol # Set the color back to its default - Red / '#00FFFFFF'
} Else {
Write-Host " This will only work in Powershell ISE." -ForegroundColor Yellow -BackgroundColor DarkRed
Write-Host "  Any key, to continue..." -NoNewline -ForegroundColor Green -BackgroundColor DarkCyan
Read-Host
}

break
# List all Hex values 0 - 255
0..255 | % {Write-Host "$_`: $((('{0:x2}' -f $_).ToString()).ToUpper())"}