Skip to content

Instantly share code, notes, and snippets.

@contactbrenton
Last active June 24, 2025 00:30
Show Gist options
  • Save contactbrenton/feb02fe920ca92351bbffa5cf8e16c42 to your computer and use it in GitHub Desktop.
Save contactbrenton/feb02fe920ca92351bbffa5cf8e16c42 to your computer and use it in GitHub Desktop.
Installs NuGet + VcRedist module, removes selected VC++ versions, and lists installed ones. Ideal for sysadmins automating system cleanups. Tags: PowerShell VcRedist Visual C++ Automation Cleanup
<#
.SYNOPSIS
This script configures the PowerShell environment for removing Visual C++ Redistributables.
It installs the NuGet package provider and the VcRedist module, and then removes specific versions of Visual C++ Redistributables.
.DESCRIPTION
The script sets the execution policy to Bypass for the current process, installs NuGet and VcRedist modules, and uninstalls specific versions of Visual C++ Redistributables (2005, 2008, 2010, 2012). It ends by listing all installed Visual C++ Redistributables.
.NOTES
Requires administrative permissions
#>
# Use Try-Catch block for better error handling
try {
# Bypass the execution policy for the current process
Set-ExecutionPolicy Bypass -Scope Process -Force -ErrorAction Stop
# Install NuGet package provider
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -ErrorAction Stop
Write-Host "Nuget Installed" -ForegroundColor White -BackgroundColor Yellow
# Install VcRedist module
Install-Module -Name VcRedist -Force -ErrorAction Stop
Write-Host "VcRedist Installed" -ForegroundColor White -BackgroundColor Blue
# Import VcRedist module
Import-Module -Name VcRedist -ErrorAction Stop
# Uninstall specified releases of Visual C++ Redistributables
Uninstall-VcRedist -Release 2005, 2008, 2010, 2012 -Confirm:$false -ErrorAction Stop
Write-Host "Specified Visual C++ Redistributables Uninstalled" -ForegroundColor White -BackgroundColor Magenta
# List all installed Visual C++ Redistributables
Get-InstalledVcRedist
# Remove the VcRedist module
Remove-Module -Name VcRedist
# Uninstall the VcRedist module from the system
Uninstall-Module -Name VcRedist -AllVersions -Force
Write-Host "VcRedist module removed and uninstalled" -ForegroundColor White -BackgroundColor Green
}
catch {
# Catch and display the error
Write-Host "An error occurred: $_" -ForegroundColor Red
exit 1
}
# End of script
@tahayparker
Copy link

heya, why is nuget installed please? that line doesn't work on my pc but everything else does

@contactbrenton
Copy link
Author

nuget is like the app store for Powershell - Try running the script with administrator permissions to see if that works? You may also need to run this too
Set-ExecutionPolicy Bypass -Scope Process -Force

@tahayparker
Copy link

tahayparker commented Jun 18, 2025

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -ErrorAction Stop

Install-PackageProvider: No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.

@contactbrenton
Copy link
Author

contactbrenton commented Jun 19, 2025

Try
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

@tahayparker
Copy link

still the same 😢

@contactbrenton
Copy link
Author

Are you trying to run it with intune or some type of tooling?

@tahayparker
Copy link

i'm running it on my personal pc. no microsoft account. i did debloat it using ctt's debloater.

@contactbrenton
Copy link
Author

Hmm, not entirely sure then sorry, maybe some dependencies were stripped out through the process.

@tahayparker
Copy link

no worries, i'm going to re-install windows soon. do you by any chance know how to install all possible versions of VC++?

@contactbrenton
Copy link
Author

The purpose of this script is to remove them. I don't know anything about installing them sorry,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment