Getting GIT tips online

Here is an example that illustrates how you access a REST API online. The script retrieves GIT tips. GIT is an open-source control system. Even if you are not particularly interested in GIT, the code may still be valuable to access other similar REST APIs available on the internet:

#requires -Version 3 

$url = ''
$tips = Invoke-RestMethod -Uri $url 
$tips | Out-GridView -Title 'Tips from git-tips' -OutputMode Multiple

Twitter This Tip! ReTweet this Tip!

Creating Shortcut Drives

All PowerShell Versions

Simply add a new drive to one of the file locations you often visit:

# create folder if it does not exist yet
$path = "$homeDocumentsScripts"
$exists = Test-Path -Path $path
if (!$exists)
  $null = New-Item -ItemType Directory -Path $path

# create new scripts: drive
New-PSDrive -Name scripts -PSProvider FileSystem -Root "$homeDocumentsScripts"

dir scripts:

New-PSDrive creates drives to all the locations you need to access frequently. Note that drives created with New-PSDrive are available in PowerShell only. The new drive is available only in the current PowerShell session. You may want to place this command into your profile script (path to a profile script is found in $profile and may need to be created if it does not yet exist).

Twitter This Tip! ReTweet this Tip!

Running PowerShell Tasks with Progress Bar

PowerShell 2+

Sometimes it may take some time for a PowerShell command to complete, and while the command is working, the user gets no visual clue.

Here is a simple function that uses a background thread to execute long-running commands. In the foreground, it displays a progress bar. If the user decides to abort by pressing CTRL+C, the function terminates the background thread.

function Invoke-WithProgressBar
    $ps = [PowerShell]::Create()
    $null = $ps.AddScript($Task)
    $handle = $ps.BeginInvoke()
    $i = 0
      Write-Progress -Activity 'Hang in...' -Status $i -PercentComplete ($i % 100)
      Start-Sleep -Milliseconds 300
    Write-Progress -Activity 'Hang in...' -Status $i -Completed

Just try it:

PS> Invoke-WithProgressBar -Task { Get-Hotfix }

Twitter This Tip! ReTweet this Tip!