Solved

Power script a Beginner need help

Posted on 2013-12-02
8
273 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This article will help you understand what HashTables are and how to use them in PowerShell.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

12 Experts available now in Live!

Get 1:1 Help Now