PowerShell 2 min read

How to Install Visual Studio Code and Configure with Azure Repos for PowerShell Scripts

Michael Wu ·

I previously managed PowerShell scripts using ISE and Dropbox, but found this approach lacked change tracking. Visual Studio Code with Azure Repos integration became the preferred solution.

Installation Steps

Install Visual Studio Code

  1. Download the latest version from Visual Studio Code
  2. Choose between User Installer or System Installer
  3. Install PowerShell Extension via Extensions marketplace
  4. Install Azure Repos extension (VSTS)

Install Git for Windows

  1. Download Git for Windows
  2. Configure VSCode as Git’s default editor
  3. Select OpenSSH option
  4. Use native Windows Secure Channel library

Install Posh-Git Module

Install-Module posh-git -Scope AllUsers

Verify installation:

Get-Module posh-git -ListAvailable

Clone Azure Repos in VSCode

  1. Sign into Azure Repos and select “Clone in VS Code”
  2. Choose repository location on local drive
  3. If encountering fatal access errors, rename project to remove spaces
  4. Authenticate via Team section in VSCode

Configure PowerShell Profile

code $profile.CurrentUserAllHosts

Add this custom prompt function:

function prompt {
    $curUser = (Get-ChildItem Env:\USERNAME).Value
    $curComp = (Get-ChildItem Env:\COMPUTERNAME).Value
    Write-Host -NoNewLine $curUser -ForegroundColor Cyan
    Write-Host -NoNewLine " @ " -ForegroundColor Magenta
    Write-Host -NoNewLine $(Get-Location) -ForegroundColor Yellow
    Write-Host -NoNewLine "[" -ForegroundColor Yellow
    Write-Host -NoNewLine ("{0:HH}:{0:mm}:{0:ss}" -f (Get-Date)) -ForegroundColor White
    Write-Host -NoNewLine "]" -ForegroundColor Yellow
    Write-Host -NoNewLine ">" -ForegroundColor Red

    $host.UI.RawUI.WindowTitle = "PowerShell -- $curUser @ $curComp "
    Write-VcsStatus
    return " "
}

After reopening VSCode, the terminal will display colorful Git status information with the custom prompt.