开发者

How to remotely find the .NET version on a server list with PowerShell?

开发者 https://www.devze.com 2023-03-20 01:24 出处:网络
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

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?


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}


Here is one way:

dir $env:windir\Microsoft.NET\Framework\v* | 
   sort lastwritetime -desc | 
       select -First 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"
}


The esiest way is to use the Variable $PSVersionTable

PS C:\> $PSVersionTable.CLRVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      30319  17929   
0

精彩评论

暂无评论...
验证码 换一张
取 消