Solved

Power script a Beginner need help

Posted on 2013-12-02
8
274 Views
Last Modified: 2013-12-11
Hi All,

Am a beginner to Powershell..
Can some one please explain whats wrong with the below powershell script


$strcom = read-host "Enter the name"

if ($strcom = 2)
{
      Write-host "You are the best"
}
Elseif ($strcom = 1)
{
        Write-host "You ugly hell"      
}
Else
{
  Write-host "You have entered the wrong number we got only 1 & 2 choices"

}
0
Comment
Question by:sekar_raj32
  • 3
  • 2
  • 2
8 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39689342
Instead of $strcom = 2 use $strcom -eq 2

'$strcom = 2' means you are assigning value 2 to var $strcom

$strcom = read-host "Enter the name"

if ($strcom -eq 2)
{
  Write-host "You are the best"
}
Elseif ($strcom -eq 1)
{
  Write-host "You ugly hell"       
}
Else
{
  Write-host "You have entered the wrong number we got only 1 & 2 choices"
}

Open in new window

0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39689346
In powershell type:

help about_comparison_operators

This will get you a very long and thorough description of comparison operators.

PS: unlike batch, PS has a very well done help system that's available in command line.
Run update-help first to download a copy of help files on your computer.

HTH,
Dan
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39689374
@sekar_raj32, Could you please explain, why you have selected DanCraciun's comment as the sole answer?
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 7

Author Comment

by:sekar_raj32
ID: 39694671
@subsun am really sorry..it was my mistake..i have wrongly given it ..
Am extramely sorry..Actually you helped me but my bad..Am sorry again..
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39694715
@sekar_raj32: then contact a moderator and ask him to correct the situation.

I actually thought you preferred to read the help file and get a thorough understanding, instead of a "do this" solution :)
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 39707971
Thanks All
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39712525
Thank you sekar_raj32 for accepting the solution. Any specific reason for 'B' grade?

Please see the EE guidelines on grading..
Http://support.experts-exchange.com/customer/portal/articles/481419
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Set OWA language and time zone in Exchange for individuals, all users or per database.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now