Last active
August 2, 2024 02:36
-
-
Save gabriel-vanca/cc47e781a24f063098c8e8306e82c4da to your computer and use it in GitHub Desktop.
Clean-DotNet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-InstalledDotNetFrameworkFromRegistry { | |
<# | |
.SYNOPSIS | |
Display version of .net installed on a system | |
.DESCRIPTION | |
Query the registry on a local or remote system to display the version of .net installed | |
.PARAMETER ComputerName | |
The name of the computer to run the query on | |
#> | |
PARAM([String]$ComputerName = $ENV:COMPUTERNAME) | |
IF ($ComputerName -ne $ENV:COMPUTERNAME) { | |
[array]$netTypes = Invoke-CommandName { Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\" -Recurse | Get-Item | Get-ItemProperty } | |
} | |
else { | |
$netTypes = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\" -Recurse | Get-Item | Get-ItemProperty | |
} | |
Foreach ($item in $netTypes) { | |
IF ($item.InstallPath) { | |
$Type = $item.PSChildName | |
$Version = $item.Version | |
$Release = $item.Release | |
$InstallPath = $item.InstallPath | |
$DotNet = New-Object -TypeName psobject | |
$DotNet | Add-Member -MemberType NoteProperty -Name Type -Value $Type | |
$DotNet | Add-Member -MemberType NoteProperty -Name Version -Value $Version | |
$DotNet | Add-Member -MemberType NoteProperty -Name Release -Value $Release | |
$DotNet | Add-Member -MemberType NoteProperty -Name InstallPath -Value $InstallPath | |
$DotNet | |
} | |
} | |
} | |
function Test-CommandExists { | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] $command | |
) | |
$exists = $null -ne (Get-Command $command -ErrorAction SilentlyContinue) | |
return $exists | |
} | |
function GetDotNetCoreUninstallTool { | |
if(Test-CommandExists dotnet-core-uninstall) { | |
Write-Verbose "DotNetCoreUninstall tool already present" | |
return | |
} | |
Write-Verbose "DotNetCoreUninstall tool not present. Installing tool." | |
} | |
#Requires -RunAsAdministrator | |
# Force use of TLS 1.3 for all downloads. | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13 | |
Param ( | |
[Parameter(Mandatory = $False)] [Alias('uninstall')] [Switch] $FullUninstall = $False, | |
[Parameter(Mandatory = $False)] [Alias('list')] [Switch] $ListOnly = $False | |
) | |
if($IsWindows -or ($NULL -eq $IsWindows)) { | |
Write-Verbose "Windows Detected" | |
} else { | |
Write-Host "Not Windows. Other operating systems not yet supported. Please run dotnet-core-uninstall for Mac/Linux manually" -ForegroundColor DarkRed | |
throw "Not Windows." | |
} | |
Write-Output "Finding .Net installs... `n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment