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!

Autosynchronizacja projektu poprzez Onedrive dla firm | Visual Studio

Jeśli chcemy aby nasz projekt typu Visual Studio Installer był po zbudowaniu automatycznie synchronizowany do Sharepointa poprzez OneDrive dla firm możemy ustawić w w trybie Release Visual Studio PostBuildEvent kompresje do wskazanego folderu używając np 7-zip.

Czytaj dalej Autosynchronizacja projektu poprzez Onedrive dla firm | Visual Studio