There is an uninstall tool released by .Net team. The tool lets you clean up .Net SDKs and Runtimes on a system. You can download the tool from the following URL.
https://github.com/dotnet/cli-lab/releases
To find more details about the too, refer the following URL
https://learn.microsoft.com/en-gb/dotnet/core/additional-tools/uninstall-tool?tabs=windows
Once you installed the tool, you can use the commands, few useful commands are below.
To list the .Net SDKs & runtimes that can be uninstalled >> dotnet-core-uninstall list
There is a dry-run option that will displays the SDKs / Runtimes that will be removed based on the options you provided to the command.
e.g. >> dotnet-core-uninstall dry-run
For example, the follwoing command will dry run of removing all SDKs below the version 2.2.301
dotnet-core-uninstall whatif --all-below 2.2.301 --sdk
and the following command will remove all SDKs below the version 2.2.301
dotnet-core-uninstall remove --all-below 2.2.301 --sdk