Question

In: Computer Science

1. Write a simple batch include IFELSE statments? 2. Write a simple Powershell Script with IFELSE...

1. Write a simple batch include IFELSE statments?

2. Write a simple Powershell Script with IFELSE statements?

3. Explain this powershell script and write its output?

$x = 30

if($x -eq 10){
   write-host("Value of X is 10")
} elseif($x -eq 20){
   write-host("Value of X is 20")
} elseif($x -eq 30){
   write-host("Value of X is 30")
} else {
   write-host("This is else statement")
}

Solutions

Expert Solution

1. Write a simple batch include IFELSE statements?

syntax:If (condition) (do_something) ELSE (do_something_else)
Example 
SET /A a = 5 
SET /A b = 10
SET /A c = %a% + %b% 
if %c%==15 (echo "The value of variable c is 15") else (echo "Unknown value") 
if %c%==10 (echo "The value of variable c is 10") else (echo "Unknown value")

2. Write a simple Powershell Script with IFELSE statements?

Syntax:

Following is the syntax of an if...else statement −

if(Boolean_expression) {
   // Executes when the Boolean expression is true
}else {
   // Executes when the Boolean expression is false
}

Example

$x = 30

if($x -le 20){
   write-host("This is if statement")
}else {
   write-host("This is else statement")
}

The output ->This is else statement

3. Explain this PowerShell script and write its output?

$x = 30

if($x -eq 10){
   write-host("Value of X is 10")
} elseif($x -eq 20){
   write-host("Value of X is 20")
} elseif($x -eq 30){
   write-host("Value of X is 30")
} else {
   write-host("This is else statement")
}

Ans: output is->Value of X is 30


Related Solutions

Windows PowerShell 1) Write a PowerShell Script to monitor a file for changes. 2) Write a...
Windows PowerShell 1) Write a PowerShell Script to monitor a file for changes. 2) Write a PowerShell Script to create a user account in a specific OU.
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script that verifies the 'System' environmentvariable, 'LM_LICENSE_FILE', exists. If it exists, the scriptshould also verify that the variable [email protected] (which represents the port and server theLM points to) as one of the values in the variable. Values (if anyare present) are separated by commas "," in this variable. Finally,if the value does not exist, this script should also performremediation (add the desired value to the...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
1. How to create a group of users using a PowerShell script. 2. how to create...
1. How to create a group of users using a PowerShell script. 2. how to create a file consisting a group of 3 new user name’s and passwords, 1 to a line in power shell. 3. How to write a script in power shell to delete specific group of users. Prove that it works.
Write a Powershell script to create a Windows user account that is a non-admin user. This...
Write a Powershell script to create a Windows user account that is a non-admin user. This assignment assumes that you already have a Windows VM, with the administrator account created.. To complete the assignment, write the PowerShell script, run it on your VM, and submit the script here.
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: You are...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: You are going to create an HTML web page report from a standard processed report. You will use the text file “STUDENTS.TXT” located on Canvas. The script must meet the following requirements: The output file should be named ITS3410-{your name}.htm Every line of data that has a student number (9999-9999) must be included in the report All data must be trimmed No leading white space No...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions to get the following information Local username Local machine name Time zone Current Date Output the data that was collected to the screen Upload the script. Paste a screenshot of the results here
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
write a script named compute.sh that is used to do simple arithmetic for the user. There...
write a script named compute.sh that is used to do simple arithmetic for the user. There should be no command line arguments. Instead, all values from the user should be prompted for and read in to the script using the read command. Specifically, you need to ask the user for two integers and an operation string. The operation should be "add", "sub", "mul", "div", or "exp", for addition, subtraction, multiplication, division, and exponentiation, respectively. Your script should take the two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT