Solved

Power script a Beginner need help

Posted on 2013-12-02
8
275 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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