[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Power script a Beginner need help

Posted on 2013-12-02
8
Medium Priority
?
303 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
  • 3
  • 2
  • 2
7 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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
Screencast - Getting to Know the Pipeline

873 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