PowerTip: Find if Computer has .NET Framework 4.5

PowerTip: Find if Computer has .NET Framework 4.5

  • Comments 4
  • Likes

Summary: Use Windows PowerShell to find if a computer has .NET Framework 4.5.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find if my machine has .NET Framework 4.5 (required for Windows PowerShell 4.0)?

Hey, Scripting Guy! Answer Here's a little function that finds this information for you:

function Test-Net45

{

    if (Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full')

    {

if (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release -ErrorAction SilentlyContinue)

{

    return $True

}

return $False

    }

}

You can run it remotely, too:

PS C:\ps-test> Invoke-Command -ComputerName Server01 -ScriptBlock {

function Test-Net45

{

>> if (Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full')

>> {

>> if (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release -ErrorAction SilentlyContinue)

>> {

>>     return $True

>> }

>> return $False

>> }

>> }
>> #Run it now

>> Test-Net45}

True

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Acceleration is a fast growing start-up which is having their ERP Web solutions for Education, Finance & Hospitality domain.

  • Apparently, this function has not been tested on a computer equipped *neither* with .NET Framework 4.0 *nor* 4.5.
    The code suggests it would return "False" in this case — which it doesn't, in fact it returns nothing at all.
    The 'return $False' statement should be better placed *between* the last two closing braces, not before them.

  • @joachimt

    A return of nothing is the same as a return of $false. Here is an example:

    PS C:\scripts> function foonothing{if($args[0] -eq 1){$true}}
    PS C:\scripts> if(foonothing 1){$true}else{$false}
    True
    PS C:\scripts> if(foonothing 0){$true}else{$false}
    False
    PS C:\scripts> foonothing 1
    True
    PS C:\scripts> foonothing 0
    PS C:\scripts>

    Note that foonothing 0 returns nothing yet it is still $false..

  • @jrv

    And yet, joachimt is right. Running against some computers that have a combo of all 3 cases mentioned, I received:

    Z148 results:
    J167 results: True
    B112 results:
    P453 results: True
    A106 results: False
    A135 results: True
    K191 results: True

    So I can now tell you that 2 of them are not even v4, and 1 is v4.