6

I am trying to find version of .NET installed on a list of servers. What would be a PowerShell script to do the same where servers are provided as a .txt file and they are enumerated to find the .NET version on the servers?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nipiv
  • 332
  • 1
  • 5
  • 18
  • 1
    Maybe you have tried something already that you had problems with you would like to ask about? Or you are purely expecting someone writing the script for you? – Darin Dimitrov Jul 12 '11 at 21:32

4 Answers4

4

Refer to Stack Overflow question PowerShell script to return versions of .NET Framework on a machine? on how to find the framework.

For doing it on many servers, the list being from a .txt, you can use Get-Content to read the file, pipe it to Invoke-Command and pass the command that you select from the above linked answers to get the framework.

$script = {gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | select -fi 1 -exp pschildname}
gc list.txt | %{ Invoke-Command -comp $_ -ScriptBlock $script}
Community
  • 1
  • 1
manojlds
  • 290,304
  • 63
  • 469
  • 417
2

Here is one way:

dir $env:windir\Microsoft.NET\Framework\v* | 
   sort lastwritetime -desc | 
       select -First 1
Doug Finke
  • 6,675
  • 1
  • 31
  • 47
1

Alternative using Get-WmiObject, but seems rather slow:

foreach ($server in (Get-Content serverlist.txt))
{
   $version = Invoke-Command -Computer $server -ScriptBlock {
      (Get-WmiObject Win32_SoftwareElement | ? { $_.name -eq "system.net.dll_x86" }).Version
   }
   Write-Output "$server is using .Net Framework version $version"
}
Torbjörn Bergstedt
  • 3,359
  • 2
  • 21
  • 30
0

The esiest way is to use the Variable $PSVersionTable

PS C:\> $PSVersionTable.CLRVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      30319  17929   
laalto
  • 150,114
  • 66
  • 286
  • 303