[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Power script a Beginner need help

Posted on 2013-12-02
8
Medium Priority
?
293 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
[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
  • 2
  • 2
8 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 1500 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 35

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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 
LVL 7

Author Comment

by:Kamalasekar Parthasarathy
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 35

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:Kamalasekar Parthasarathy
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 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