Question

Task 10: Creating functions In Windows PowerShell, you can declare functions. Functions are reusable pieces of...

Task 10: Creating functions

In Windows PowerShell, you can declare functions. Functions are reusable pieces of code that can be called as many times as you want after you declare them.

In this step, you will declare a function, learn about using different types of parameters, and specify default values for these parameters.

1. In the Windows PowerShell ISE, press CTRL+N.

2. In the script pane, type the following code.

function Get-Soup ( [switch] $please, [string] $soup = "chicken noodle" ) { if ($please) { "Here's your $soup soup" } else { "No soup for you!" } } This command declares a Get-Soup function which will receive two parameters, $please and $soup.

3. To run the script, press F5, and then click the Script arrow to hide the script pane.

It is not necessary to save a script before executing it in the ISE. This makes it easy to use the script pane to quickly test commands and code snippets.

4. To call the script with no parameters, in the command pane, type the following command, and then press ENTER.

PS >Get-Soup

Department of Computer Science Spring 2019

5. To call the Get Soup function with the $please parameter, type the following command, and then press ENTER.

To specify a parameter declared as a switch, specify –parameter name after the function name.

PS >Get-Soup -please

6. To call Get-Soup specifying a value for $soup, type the following command, and then press ENTER.

PS >Get-Soup –please tomato

SHOW ALL INPUT AND OUTPUT AS WELL AS A SCREEN SHOT WITH ALL RESULTS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

All the inputs to be inserted in the command pane are highlighted as bold text below

1. Open Windows PowerShell ISE by searching in the search bar

I the window Press ctrl+N and it would open script pane.

2. In the script Pane type the following code:

function Get-Soup ( [switch] $please, [string] $soup = "chicken noodle" )
{
if ($please) {
"Here's your $soup soup"
}
else {
"No soup for you!"
}
}

3. To run the script press F5

4. To call the script with no parameters, in the command pane, type the following command, and then press ENTER.

PS >Get-Soup

5. To call the Get Soup function with the $please parameter, type the following command, and then press ENTER.

To specify a parameter declared as a switch, specify –parameter name after the function name.

PS >Get-Soup -please

6. To call Get-Soup specifying a value for $soup, type the following command, and then press ENTER.

PS >Get-Soup –please tomato

Add a comment
Know the answer?
Add Answer to:
Task 10: Creating functions In Windows PowerShell, you can declare functions. Functions are reusable pieces of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 12: Working with Windows PowerShell ISE You can use the Windows PowerShell Integrated Scripting Environment...

    Task 12: Working with Windows PowerShell ISE You can use the Windows PowerShell Integrated Scripting Environment (ISE) to create, run, and debug commands and scripts. The Windows PowerShell ISE consists of the menu bar, Windows PowerShell tabs, the toolbar, script tabs, a script pane, a console pane, a status bar, a text-size slider and context-sensitive Help. It works for both local and remote scripts. Using the Windows PowerShell ISE gives you many different advantages when creating scripts. Although it can...

  • that is sualy identidied try what type ot mmand in W to format a disk, what...

    that is sualy identidied try what type ot mmand in W to format a disk, what switch can specify or more files totive 6 Which type of file suffix is used by both Windows 10 and the CentOS 7 GNOME desktop to identify file associations? a modifiers b extensions .sources d attributes Name: Class: Dabe: CTEC-214 Last Quiz Before Final 7. What type of attribute determines how the operating system allows processes or users to perform some functions? a group...

  • Problem 1 In this problem, you will write two functions. The first function takes in a...

    Problem 1 In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The second function takes in the first and last name and returns a string that is lastname_firstname and uses the previous function to remove any dashes (-) in the name. Note that you’ll be testing it by calling it from the command line; you’ll call it from a script in problem 3. Deliverables: Function file that...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • Lab 7: Void and Value-Returning Functions Lab 7: Void and Value-returning functions             ...

    Lab 7: Void and Value-Returning Functions Lab 7: Void and Value-returning functions              Due date: 11/6/19 Problem: Write a C++ program that calculates the areas of a rectangle and of an ellipse.                    Area = base * height             Area = π * radius a * radius b Note: all images extracted from http://www.mathsisfun.com/area-calculation-tool.html ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79...

  • Arrays in Functions 2. Arrays in Functions You can use both the array index variables and...

    Arrays in Functions 2. Arrays in Functions You can use both the array index variables and the entire array itself as arguments to functions. The following program updates the elements of the array grades, one-by-one. Thus, we have used a call-by-reference-ish mechanism to update the values (although no & was used). Note that there is a major difference between the grade in the function call and the one in the function definition. In the statement get_grade (grades[i]); "grades" is the...

  • C++ help This assignment gives you practice with inheritance and pure virtual functions. You will implement...

    C++ help This assignment gives you practice with inheritance and pure virtual functions. You will implement some code that could be part of a program to play a popular card game called “Crazy 8’s”, which is the basis for the game “Uno”. You will start to implement the rules, as described at: https://www.pagat.com/eights/crazy8s.html . Note that the inheritance relationship below is also based on the organization of card games described on that website. Requirements: your work will be split into...

  • ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions...

    ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions -Learn to use reference variables Coding Guidelines for All Labs/Assignments (You will be graded on this) -Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). -Keep identifiers to a reasonably short length. -Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables,...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • Goals: Practicing functions and parameter types. Problem: You are to create a program that will aid...

    Goals: Practicing functions and parameter types. Problem: You are to create a program that will aid in a farmer in monitoring the amount of corn to feed livestock each week. There is a template named "Labs1-5template.cpp" posted on Canvas which you should download and complete. Follow the instructions given in the template and follow the assignment guidelines for the course. Do not use global variables and do not use the same variable name in multiple functions. Your finished code should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT