Skip to content

Instantly share code, notes, and snippets.

@jrotello
Last active September 25, 2019 09:18
Show Gist options
  • Save jrotello/2b9cd552e764e1cf364a3535b1dcc315 to your computer and use it in GitHub Desktop.
Save jrotello/2b9cd552e764e1cf364a3535b1dcc315 to your computer and use it in GitHub Desktop.
Side load Team Foundation Server Power Tools 2015 without the need to have Visual Studio 2015 installed
work/
InstallUtil.InstallLog

Team Foundation Power Tools 2015 Sideloader

Usage

WARNING: Please review the scripts prior to executing them. They are working well on my machine, but I accept no responsibility for the changes that are made on your machine.

Install

./Install-TFPT.ps1 -InstallDirectory <path>

Uninstall

./Uninstall-TFPT.ps1 -InstallDirectory <path>

Import the PSSnapin Into Your Session

Add-PSSnapin Microsoft.TeamFoundation.PowerShell

Problem Description

We are still using TFVC at work for the time being, and we have a number of PowerShell scripts that utilize the PowerShell cmdlets that are installed with Team Foundation Power Tools 2015. Unfortunately, the power tools installer requires Visual Studio 2015 to be installed. Now that I have repaved my machine moved completely over to Visual Studio 2017, I didn't want Visual Studio 2015 to be installed on my machine.

Solution

The install script will download the installer msi, extract it and register the PowerShell Snapin on the system.

The uninstall script will unregister the PowerShell Snapin, delete the passed in install directory and remove the working folder created when the install script was originally run.

Works On My Machine Disclaimer

WARNING: Please review the scripts prior to executing them. They are working well on my machine, but I accept no responsibility for the changes that are made on our machin

Dependencies

  • Chocolatey - Must be present on the machine.
  • lessmsi - Install script will install it via Chocolatey if it is not already installed.

YouTube Demo

Team Foundation Power Tools Sideloader

param(
[Parameter(Mandatory = $true)]
[string]$InstallDirectory,
[Parameter()]
[string]$TfptDownloadUrl = 'https://visualstudiogallery.msdn.microsoft.com/898a828a-af00-42c6-bbb2-530dc7b8f2e1/file/177107/1/tfpt.msi',
[string]$InstallUtilPath = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\installutil.exe",
[Parameter()]
[switch]$Force = $false
)
$ErrorActionPreference = 'Stop'
$InstallerAssembly = "$InstallDirectory\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
where.exe /Q choco.exe
if ($LASTEXITCODE -ne 0) {
Write-Warning "Chocolately is missing. Please install it from chocolatey.org...exiting"
return
}
where.exe /Q lessmsi.exe
if ($LASTEXITCODE -ne 0) {
Write-Information "Installing 'lessmsi' from Chocolatey..." -InformationAction Continue
choco install lessmsi
}
$WorkPath = "$PSScriptRoot\work"
mkdir $WorkPath -Force | Out-Null
if (Test-Path "$WorkPath\tfpt") {
Remove-Item "$WorkPath\tfpt" -Recurse -Force
}
$MsiPath = "$WorkPath\tfpt.msi"
if ((-not (Test-Path $MsiPath)) -or ($Force)) {
Write-Information "Downloading Team Foundation Power Tools installer..." -InformationAction Continue
Invoke-WebRequest -Method Get -Uri $TfptDownloadUrl -OutFile $MsiPath
}
if (Test-Path $InstallDirectory) {
if (-not $Force) {
Write-Warning "Install directory already exists. Run with the '-Force' option to overwrite." -InformationAction Continue
return
} else {
Remove-Item $InstallDirectory -Force -Recurse
}
}
mkdir $InstallDirectory -Force | Out-Null
Push-Location $WorkPath
try {
Write-Information "Extracting tfpt.msi..." -InformationAction Continue
lessmsi.exe x $MsiPath | Out-Null
Write-Information "Copying to install directory..." -InformationAction Continue
Copy-Item -Recurse '.\tfpt\SourceDir\PFiles\Microsoft Team Foundation Server 2015 Power Tools\*' $InstallDirectory
Write-Information "Registering PS Snapin..." -InformationAction Continue
& $InstallUtilPath $InstallerAssembly
} finally {
Pop-Location
}
Write-Host "SUCCESS!" -ForegroundColor Green
param(
[Parameter(Mandatory = $true)]
[string]$InstallDirectory,
[string]$InstallUtilPath = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\installutil.exe"
)
$ErrorActionPreference = 'Stop'
$WorkDirectory = "$PSScriptRoot\work"
$InstallerAssembly = "$InstallDirectory\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
if (Test-Path $InstallerAssembly) {
Write-Information "Removing PowerShell Snapin registration..." -InformationAction Continue
& $InstallUtilPath /u $InstallerAssembly
}
if (Test-Path $InstallDirectory) {
Write-Information "Removing installation directory..." -InformationAction Continue
Remove-Item $InstallDirectory -Force -Recurse
}
if (Test-Path $WorkDirectory) {
Write-Information "Removing working directory..." -InformationAction Continue
Remove-Item $WorkDirectory -Recurse -Force
}
Write-Host "SUCCESS!" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment