Table of Contents
Remove NuGet Package Provider
In some cases, you want to remove the NuGet Provider for PowerShell. This package provider is being installed automatically then you install some modules to connect to Microsoft 365.
You can get the list of all installed package provider on your system with Get-PackageProvider cmdlet.
PS C:\> Get-PackageProvider | select Name, Version
Name Version
---- -------
msi 3.0.0.0
msu 3.0.0.0
NuGet 2.8.5.208
PowerShellGet 1.0.0.1
Programs 3.0.0.0
We do a check the PackageManagement module and still has no Uninstall-PackageProvider command. But we found a cmdlet Uninstall-Package then we give it a try.
PS C:\> Get-Command -Module PackageManagement
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Find-Package 1.4.7 PackageManagement
Cmdlet Find-PackageProvider 1.4.7 PackageManagement
Cmdlet Get-Package 1.4.7 PackageManagement
Cmdlet Get-PackageProvider 1.4.7 PackageManagement
Cmdlet Get-PackageSource 1.4.7 PackageManagement
Cmdlet Import-PackageProvider 1.4.7 PackageManagement
Cmdlet Install-Package 1.4.7 PackageManagement
Cmdlet Install-PackageProvider 1.4.7 PackageManagement
Cmdlet Register-PackageSource 1.4.7 PackageManagement
Cmdlet Save-Package 1.4.7 PackageManagement
Cmdlet Set-PackageSource 1.4.7 PackageManagement
Cmdlet Uninstall-Package 1.4.7 PackageManagement
Cmdlet Unregister-PackageSource 1.4.7 PackageManagement
As you can see in the below out, it’s not the cmdlet to remove a package provider.
PS C:\> Uninstall-Package -Name NuGet
Uninstall-Package : No package found for 'NuGet'.
On Windows systems
Step-by-step instructions for removing the NuGet package provider:
1️⃣ Copy the path of the NuGet package-provider assembly (DLL) to the clipboard.
(Get-PackageProvider NuGet).ProviderPath | Set-Clipboard
Below are three locations that the NuGet provider can be installed in. In your machine, it could be difference, but you don’t need to care about it because it’s stored in the clipboard.
C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll
C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.8.1\fullclr\Microsoft.PackageManagement.NuGetProvider.dll
C:\Users\admin\Documents\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.NuGetProvider.dll
2️⃣ Before continuing, close all opening PowerShell sessions, which may include needing to exit Visual Studio Code. Deleting the DLL will only succeed if no session has it currently loaded. If that isn’t ensured, you’ll get an Access denied error, even with elevation.
PS C:\> (Get-PackageProvider NuGet).ProviderPath | Set-Clipboard
PS C:\> Remove-Item -Path $(Get-Clipboard)
Remove-Item : Cannot remove item C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll: Access to the path 'C:\Program
Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll' is denied.
At line:1 char:1
+ Remove-Item -Path $(Get-Clipboard)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Program File...GetProvider.dll:FileInfo) [Remove-Item], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
3️⃣ Open a new elevated PowerShell console, in which you must not have submitted any PackageManagement commands. Then submit the following command to delete the NuGet package-provider assembly (DLL):
Remove-Item -Path $(Get-Clipboard)
The NuGet package provider should be removed without any issue. You can check it got removed with Get-PackageProvider cmdlet as below:
PS C:\Users\bonben> Get-PackageProvider | select Name, Version
Name Version
---- -------
msi 3.0.0.0
msu 3.0.0.0
PowerShellGet 1.0.0.1
Programs 3.0.0.0
On macOS and Linux:
1️⃣ Start a PowerShell session with sudo.
2️⃣ Submit the following command to delete the NuGet package-provider assembly (DLL):
(Get-PackageProvider NuGet).ProviderPath | Remove-Item -Force
Not a reader? Watch this related video tutorial: