Is .Net 3.5 Installed?

A quick-and-dirty way to determine if .NET 3.5SP1 is installed.

$path = “\\$myComputer\c$\windows\Microsoft.NET\Framework\v3.5\csc.exe”;
if((Get-WmiObject -ComputerName $myComputer -Query “select * from Win32_OperatingSystem”).OsArchitecture -eq ’64-bit’) { $path = $path -replace “Framework”, “Framework64”; }
if (!(Test-Path $path)) {
    $return = $false;
} elseif (!( (Get-Command $path).FileVersionInfo.ProductVersion -match ‘3\.5\.30729\.’)) {
    $return = $false;

Two caveats.

  1.  This doesn’t account for $env:windir on the remote machine.  Our labs have a very set layout, so we don’t have to worry about that.  Otherwise, we’d have to do something along the lines of

    $winDir = (Get-WmiObject -ComputerName $myComputer -Query “select * from Win32_Environment where username='<system>’ and name=’windir'”).VariableValue -replace “:”, “$”;

    However, this doesn’t address the case where $env:windir is actually set to %systemroot%, which is then interpolated.  Ouch.

    This is why I prefer our lab setup.

  2. 3.5.30729 is the major.minor.micro version, but there’s a sub-micro version value as well.  That sub-micro version value varies between 2008 and below (“.1”) and 2008R2, (‘.4926’).

Comments (2)

  1. Abc says:

    Maybe extract info from this..…/9763379.aspx

  2. timdunn says:

    It looks at HKLMSoftwareMicrosoftNET Framework SetupNDP, so we could just do the same thing and see what subkeys exist under it.  Thanks!