Skip to content

Instantly share code, notes, and snippets.

@neeraj9
Forked from JeffJacobson/Find-SDKTool.ps1
Created April 16, 2023 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neeraj9/aa06a6608e2c3122fb97249f54044b4e to your computer and use it in GitHub Desktop.
Save neeraj9/aa06a6608e2c3122fb97249f54044b4e to your computer and use it in GitHub Desktop.
A script that finds different versions of Windows .NET SDK tools in expected directories.
<#
.SYNOPSIS
Finds an SDK tool in .NET SDK folders
.INPUTS
Name of tool (exe filename) to search for. (E.g., svcutil.exe)
.OUTPUTS
Outputs a list of matching filenames along with properties about the directories
* Windows SDK version
* .NET version
* 32- or 64-bit exe
.EXAMPLE
.\Find-SDKTool.ps1 svcutil.exe | Select-Object -First 1 -ExpandProperty File
Find the latest version of svcutil.exe
.EXAMPLE
.\Find-SDKTool.ps1 svcutil.exe | Format-Table
WindowsVersion DotNetVersion DotNetModifier Is64Bit File
-------------- ------------- -------------- ------- ----
10.0 4.6.2 A True C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64\SvcUtil.exe
10.0 4.6.2 A False C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\SvcUtil.exe
10.0 4.6.1 A True C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\SvcUtil.exe
10.0 4.6.1 A False C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\SvcUtil.exe
10.0 4.6 A True C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64\SvcUtil.exe
10.0 4.6 A False C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\SvcUtil.exe
8.1 4.5.1 A True C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\SvcUtil.exe
8.1 4.5.1 A False C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\SvcUtil.exe
8.0 4.0 A True C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64\SvcUtil.exe
8.0 4.0 A False C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe
.NOTES
Files are not examined. Version info is based on directory structure.
#>
param(
# Parameter help description
[Parameter(Mandatory,HelpMessage="Enter a filename to search for")]
[string]$filename
)
class SdkInfo {
[version]$WindowsVersion
[version]$DotNetVersion
[string]$DotNetModifier
[bool]$Is64Bit
[System.IO.FileInfo]$File
SdkInfo([System.IO.FileInfo]$file) {
$this.File = $file
$re = [regex]"v(?<winver>[\d.]+)(?<winvermod>[A-Z])?\\bin\\NETFX\s(?<netver>[\d.]+)\sTools(?<is64bit>\\x64)?"
$match = $re.Match($file.Directory.FullName)
if ($match.Success) {
$this.WindowsVersion = New-Object version $match.Groups["winver"].Value
if ($match.Groups["winvermod"].Success) {
$this.DotNetModifier = $match.Groups["winvermod"].Value
}
$this.DotNetVersion = New-Object version $match.Groups["netver"].Value
$this.Is64Bit = $match.Groups["is64bit"].Success
}
}
}
$searchPath = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\*\bin\NETFX * Tools" # "v10.0A\bin\NETFX 4.6.2 Tools"
$files = Get-ChildItem $searchPath $filename -Recurse
return $files | ForEach-Object -Process { return New-Object SdkInfo $_ } | Sort-Object -Property DotNetVersion,Is64Bit -Descending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment