Skip to content

Instantly share code, notes, and snippets.

@ctigeek
Last active December 11, 2015 20:55
Show Gist options
  • Select an option

  • Save ctigeek/7ca3fde06e55197fe6b8 to your computer and use it in GitHub Desktop.

Select an option

Save ctigeek/7ca3fde06e55197fe6b8 to your computer and use it in GitHub Desktop.
Get the versions and SPs on the current machine (default), or an array of machines piped in.
function Get-DotNetVersion {
[cmdletbinding()]
Param(
[Parameter(ValueFromPipeline=$True)] [object] $ComputerName
)
BEGIN {
}
PROCESS {
if (-not $ComputerName) {
$ComputerName = $env:COMPUTERNAME
}
$command = {
function Get-NetCommonName([string]$version, $release) {
if (-not $version) {
""
}
elseif ($version.StartsWith("2.0")) {
"2.0"
}
elseif ($version.StartsWith("3.0")) {
"3.0"
}
elseif ($version.StartsWith("3.5")) {
"3.5"
}
elseif ($version.StartsWith("4.0")) {
"4.0"
}
elseif ($release -eq 378389) {
"4.5.0"
}
elseif ($release -eq 378675 -or $release -eq 378758) {
"4.5.1"
}
elseif ($release -eq 379893) {
"4.5.2"
}
elseif ($release -eq 393295 -or $release -eq 393297) {
"4.6.0"
}
elseif ($release -eq 394254 -or $release -eq 394271) {
"4.6.1"
}
elseif ($release -gt 394271) {
"> 4.6.1"
}
else {
""
}
}
$properties = (Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release,SP -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}' -and -not $_.PSChildName.StartsWith("Windows")})
$properties | ?{ $_.Version -ne $null } | %{ $_ | Add-Member -NotePropertyName CommonName -NotePropertyValue $(Get-NetCommonName $_.Version $_.Release) }
$properties | ft PSChildName, Version, SP, Release, CommonName
}
Invoke-Command -ComputerName $computerName -ScriptBlock $command
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment