Solved

Powershell scripting question

Posted on 2011-03-14
5
601 Views
Last Modified: 2012-06-27
I was writing a little script to tell which versions of .net framework are installed.  In powershell I wrote the following but am getting an error stating that there is nothing to match with the -eq operator.  I am new to powershell.  What am I doing wrong?

$NETv4 = "hklm:\software\microsoft\Net Framework Setup\NDP\v4"
$NETv35 = "hklm:\software\microsoft\Net Framework Setup\NDP\v3.5"
$NETv30 = "hklm:\software\microsoft\Net Framework Setup\NDP\v3.0"
$NETv20 = "hklm:\software\microsoft\Net Framework Setup\NDP\v2.0"
$NETv11 = "hklm:\software\microsoft\Net Framework Setup\NDP\v1.1.4322"


IF (Test-Path -Path $NETv4 -eq $True) {Write-Host ".Net Framework Version 4 is installed"}
IF (Test-Path -Path $NETv35 -eq $true) {Write-Host ".Net Framework Version 3.5 is installed"}
IF (Test-Path -Path $NETv30 -eq $true) {Write-Host ".Net Framework Version 3.0 is installed"}
IF (Test-Path -Path $NETv20 -eq $true) {Write-Host ".Net Framework Version 2.0 is installed"}
IF (Test-Path -Path $NETv11 -eq $true) {Write-Host ".Net Framework Version 1.1 is installed"}

Is there a way to either loop the values through or use an array so I don't have to write a different line for each version?
0
Comment
Question by:childersj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Accepted Solution

by:
MarkXIII earned 400 total points
ID: 35129231
Hi Childersj,
You do not need the $true variable.
Just test like this:
IF (Test-Path -Path $NETv4) {Write-Host ".Net Framework Version 4 is installed"}

And it will work fine.
0
 
LVL 13

Expert Comment

by:soostibi
ID: 35129526
Try this one:
dir "hklm:\software\microsoft\Net Framework Setup\NDP\v*" | %{
    if($_.name -match "Net\sFramework\sSetup\\NDP\\v(\d.\d)"){
        ".Net Framework Version $($matches[1]) is installed"
    }
}

Open in new window

0
 
LVL 13

Assisted Solution

by:soostibi
soostibi earned 100 total points
ID: 35129555
Actually in your original code the parentheses are missing:
IF ((Test-Path -Path $NETv4) -eq $True) {Write-Host ".Net Framework Version 4 is installed"}

But as MarkXIII mentioned, you can omit the "-eq $true".
0
 

Author Closing Comment

by:childersj
ID: 35131788
Thanks!
0
 
LVL 13

Expert Comment

by:soostibi
ID: 35132870
Have you tried the code in my first comment? It's a solution without enumerating the current .net framework versions, and still gives all that iare installed.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question