Install-PowerShell6Shortcut.ps1

function Install-PowerShell6Shortcut
{
  <#
      .SYNOPSIS
      Short Description
      .DESCRIPTION
      Detailed Description
      .EXAMPLE
      Install-PowerShell6Shortcut
      explains how to use the command
      can be multiple lines
      .EXAMPLE
      Install-PowerShell6Shortcut
      another example
      can have as many examples as you like
  #>

  $sp = { Out-GridView -Title 'Progress' }.GetSteppablePipeline()
  $sp.Begin($true)
  $sp.Process('Setting variables')
  
  # define the place to download to
  $destinationFile = "$env:temp\PS6\powershell6.zip"
  $destinationFolder = Split-Path -Path $destinationFile
  $ShortcutPath = "$Home\Desktop\powershell6.lnk"
  
  $sp.Process('Enabling SSL')
  Enable-SSL
  
  $sp.Process('Resolving URLs')
  # get the URL for the latest PowerShell 6 release:
  $url = Resolve-URL "https://github.com/PowerShell/PowerShell/releases/latest?dummy=$(Get-Random)" |
  Get-ReleaseUrlForWinx64
  $sp.Process("Download url is $url")
  $sp.Process('Cheecking Download')
  $exists = Test-Path -Path $destinationFile -PathType Leaf
  if ($exists)
  {
    $downloadLength = Get-DownloadSize -Url $url
    $sp.Process("Download length is $downloadLength bytes")
    $item = Get-Item -Path $destinationFile
    $isDifferent = $item.Length -ne $downloadLength
    $sp.Process("Existing download different? $isDifferent")
  }
  else
  {
    $sp.Process('Not yet downloaded, downloading...')
    $isdifferent = $true
  }
  # download file if different
  if ($isDifferent)
  {
    Assert-FolderExists -Path $destinationFolder
    Invoke-WebRequest -Uri $url -OutFile $destinationFile
    # unblock downloaded file
    Unblock-File -Path $destinationFile
  }
  
  
  # extract file
  $exists = @(Get-ChildItem -Path $destinationFolder -File).Count -gt 1
  if (!$exists)
  {
    $sp.Process('Extracting downloaded ZIP...')
    Expand-Archive -Path $destinationFile -DestinationPath $destinationFolder -Force
  }
  
  
  $sp.Process('Creating Shortcut...')
  $exists = Test-Path -Path $ShortcutPath -PathType Leaf
  if (!$exists) { New-Shortcut -ShortcutPath $ShortcutPath -TargetPath "$destinationFolder\pwsh.exe" -WorkingDirectory "$home\Documents" }

  explorer.exe /select,$ShortcutPath
  
  $sp.Process('Done')
  $sp.End()
}