Share via

Amending PowerShell commands in the inline section of provisioners

Varma 1,620 Reputation points
2024-02-16T05:43:30.31+00:00

 

provisioner "powershell" {
   inline = [
     # Visual Studio build tools
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Cyan

cd $env:USERPROFILE

$exePath = "$env:TEMP\vs_buildtools.exe"

Download the installer

Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath

Write-Host "Starting installation with selected components..." -ForegroundColor Cyan

Install the specified workloads

$arguments = @(
    "--installPath", "$env:USERPROFILE\vs_BuildTools2022",
    "--quiet",
    "--norestart",
    "--nocache",
    "--wait",
    "--noUpdateInstaller",
    "--noWeb",
    "--add", "Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools",
    "--add", "Microsoft.VisualStudio.Workload.WebBuildTools",
    "--add", "Microsoft.VisualStudio.Workload.AzureBuildTools",
    "--add", "Microsoft.VisualStudio.Workload.DataBuildTools",
    "--includeRecommended"
)

Start-Process $exePath -ArgumentList $arguments -Wait

Set the environment variable for the path

[Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));$env:USERPROFILE\vs_BuildTools2022", 'Machine')

Write-Host "Installation complete." -ForegroundColor Green

   ]
}            
}

Windows for business | Windows Server | User experience | PowerShell

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.