Extremely Serious

Month: August 2020

Usefull HTML Entities for Tracking Tasks

Entity Display Description
☐ Ballot box
◻ Empty Box
◻ Empty Box
□ Square
□ Square
☑ Ballot box with check
✓ Check
✓ Check
☒ Ballot box with cross
⊠ Box with cross
⊠ Box with cross
✗ Cross
✗ Cross

Sample Show Balloon Notification for PowerShell

A sample implementation of windows balloon notification for powershell is as follows:

Add-Type -AssemblyName System.Windows.Forms

function FnShowBalloon {

    [CmdLetBinding()]
    param($title, 
           $message, 
           [string] $icon = 'info', 
           [int] $delay = 20000, 
           [int] $sleep=0)

    Switch($icon.ToString().ToLower()) {
        'warn' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Warning}
        'error' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Error}
        'info' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Info}
        default {$iconInstance = [System.Windows.Forms.ToolTipIcon]::None}
    }

    $notification = New-Object System.Windows.Forms.NotifyIcon
    $path = (Get-Process -id $pid).Path
    $notification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
    $notification.BalloonTipIcon = $iconInstance
    $notification.BalloonTipTitle = $title
    $notification.BalloonTipText = $message
    $notification.Visible = $true
    $notification.ShowBalloonTip($delay)

    if ($sleep -gt 0) {
        Start-Sleep -s $sleep
        $notification.Dispose()
    }
}

The FnShowBalloon  function can be used as follows:

FnShowBalloon -title "Hello World" -message "This is a sample message" -icon info

Recommended Way to Redirect the Output to a Text File in PowerShell

Instead of using > to redirect the output into a file, pipe it to out-file cmdlet.

The out-file cmdlet allows some useful parameters as follows:

Parameter Argument Description
-Append Adds the output to the end of an existing file.
-Encoding Encoding Specifies the type of encoding for the target file. The default value is utf8NoBOM.

The acceptable values for this parameter are as follows:

ascii: Uses the encoding for the ASCII (7-bit) character set.
bigendianunicode: Encodes in UTF-16 format using the big-endian byte order.
oem: Uses the default encoding for MS-DOS and console programs.
unicode: Encodes in UTF-16 format using the little-endian byte order.
utf7: Encodes in UTF-7 format.
utf8: Encodes in UTF-8 format.
utf8BOM: Encodes in UTF-8 format with Byte Order Mark (BOM)
utf8NoBOM: Encodes in UTF-8 format without Byte Order Mark (BOM)
utf32: Encodes in UTF-32 format.

-FilePath Path Specifies the path to the output file.

To redirecting the output of the dir command to dir.txt file, use the following command:

dir | out-file -encoding ascii -filepath "dir.txt"