Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell scripting question

Posted on 2011-03-14
5
Medium Priority
?
605 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 1600 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

670 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