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...

  • In this step, you will list all available commands in Windows PowerShell. 1. To view the...

    In this step, you will list all available commands in Windows PowerShell. 1. To view the list of available commands, at the Windows PowerShell command prompt, type the following command, and then press ENTER. PS >Get-Command 2. Review the list of commands available. Take note of the naming convention for commands with a CommandType of Cmdlet. 3. At the command prompt, type the following command, but do not press ENTER. PS >Get-C 4. Press TAB. Windows PowerShell expands the command...

  • 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...

  • WITH SCREENSHOTS PLEASE Linux+ Guide to Linux Certification Project 9-3 In this hands-on project, you run...

    WITH SCREENSHOTS PLEASE Linux+ Guide to Linux Certification Project 9-3 In this hands-on project, you run processes in the background, kill them using the kill and killall commands, and change their priorities using the nice and renice commands. 1. On your Fedora Linux virtual machine, switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and log in to the terminal using the user name of root and the password of LNXrocks!. 2. At the command prompt, type sleep 6000 and...

  • 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...

  • 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...

  • 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...

  • 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...

  • Description For this assignment, you will maintain an array of bank accounts. You will declare a...

    Description For this assignment, you will maintain an array of bank accounts. You will declare a struct type called bankAcct and have an array of bankAcct with maximum size of 20, the members of the struct are shown below struct bankAcct { string first , last ; double amount ; long acctNo ; short pin ; }; Each member is described below • string first stores the user’s first name • string last stores the user’s last name • double...

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