Working with many app/dev teams it is hard to find which version of Dot Net an application was designed or made in.
Now if your application server has multiple drives and depending on which drive the application resides it may be hard to find this information.
Let’s assume there are two drives C: and D:.
We will start with D: drive as it is easy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#Check DotNet Framework for .EXE & .DLL #====================================# #====================================# #Files residing on any other drive except C: (OS Drive) #=====================================================# #Uncomment the line below to surpress any errors #$ErrorActionPreference = "SilentlyContinue" #Specifiy the filepath (I am using the root) $filepath=’D:\’ #Get All files and filter .exe and .dll files $files=Get-ChildItem -Path $filepath -Recurse -include *.dll,*.exe #Loop through each file foreach($file in $files) { #Check the version of .NET for the file $version = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($file.FullName).ImageRuntimeVersion; #Write the Output on Screen + Capture to a file Write-Output "$file,$version" | Out-File D:\DotNetFiles_D.txt -Append } |
Now the C: drive is a little more work. The above method wont work because C:Â drive has system files and depending on your rights you may not have access to them.
You may get the following error:
But there is a way we can get this accomplished. Good old dos commands to the rescue! We are basically going to get a list of .exe and .dll files from the C: drive and then run the above code against it.
Lets capture the files:
1 2 3 4 5 6 7 |
#For files residing on C: (OS Drive) #====================================# #Get a list of .exe files on the C: Drive and store to a file dir C:\*.exe /s /b | findstr /e .exe > C_Executable_Paths.txt #Get a list of .dll files on the C: Drive and store to a file dir C:\*.dll /s /b | findstr /e .dll > C_DLL_Paths.txt |
Now we have the .EXE files stored in C_EXE_Paths.txt and we query it for .NET versions and save the output to DotNetFiles_C_EXE.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#Query each .EXE file capture in C_Executable_Paths.txt $files=Get-Content D:\C_Executable_Paths.txt #Looping through each file entry foreach($file in $files) { #Getting .NET version number for each file $version = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($file).ImageRuntimeVersion; #Writing output to an external file Write-Output "$file,$version" | Out-File D:\DotNetFiles_C_EXE.txt -Append } |
Similarly we have the .DLLfiles stored in C_DLL_Paths.txt and we query it for .NET versions and save the output to DotNetFiles_C_DLL.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#Query each .DLL file capture in C_DLL_Paths.txt $files=Get-Content D:\C_DLL_Paths.txt #Looping through each file entry foreach($file in $files) { #Getting .NET version number for each file $version = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($file).ImageRuntimeVersion; #Writing output to an external file Write-Output "$file,$version" | Out-File D:\DotNetFiles_C_DLL.txt -Append } |
You might get errors for files that do not meet criteria or fails to list .Net version.
This can be surpressed by using:
1 |
$ErrorActionPreference = "SilentlyContinue" |
The output would be similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
C:\Program Files\IBM\SQLLIB\BIN\db2dascmn.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2dascmn64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2daskrb.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2daskrb64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2daswrap.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2daswrap64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2g11n.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2g11n64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2genreg.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2genreg64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2hrec.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2ica.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2ica64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2install.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2install64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2isys.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2jcct2.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2jdbc.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2jdbc64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2kbc.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2kbc64.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2ldap.dll,v4.0.30319 C:\Program Files\IBM\SQLLIB\BIN\db2ldap64.dll,v4.0.30319 |
Now you can import this in Excel and go crazy! 😉
Additionally, if you want to detect what version of .NETis installed on your server here is a cool utility (ASoft .NET Version Detector) to get you the info, as well as download links to the installer in case you need to download and install.