question archive Part I: Where-Object (16 marks) Example Question: 1

Part I: Where-Object (16 marks) Example Question: 1

Subject:Computer SciencePrice: Bought3

Part I: Where-Object (16 marks) Example Question: 1..100 | ... #extract prime numbers Answer: 1..100 | where-object { -isPrime $_ } | select -first 5 1. Practice with Where-Object (alias where, ?) (a-d are worth 1 mark each; e-g: 2; total: 12) Write a where-object filter for each of the following. It is recommended that you run the provider first to check out the range of values and run the provider through get-member to note the available properties and members and then logical expression or a predicate function to test your condition. The exercise is similar to writing a series of if statements. Test your filters but in your report only show up to the 1st 5 values. For each of these you are responsible for viewing the entire output and stating that your filter worked. a. 1..100 | #extract odd #s b. get-service | ... #extract services that are running that can be stopped c. create-PersonObject 100 | ... #extract people with ages from 25-35 d. get-ChildItem | ... #extract files that have a non-zero size e. get-variable | ... #extract variables and their values that begin with a vowel (upper or lower case) and end with a consonant. f. dir -Recurse -depth 3 | ... #extract files with extensions in any of: .docx, .txt, .dat, .jpg, .gif, .png or .zip. Make sure you have a least 1 of each. Verify this time by adding | group-object -prop extension at the end of your pipeline as verification g. get-process | ... #extract process running between 2 times. Check the range of times by running: get-process | measure-object -prop StartTime -min -max to find an appropriate range for your computer. h. get-WindowsCapability -online | .. #extract the name, state and whether or not a restart is needed if the name refers to Windows or ssh. 2. Rewriting your where-object filter as a filter function (3 marks) a. Create and test any of b-d as a filter function. (1) b. Create and test any of e-h as a filter function but pass the range of values as parameters instead of fixed values. Generalizing h. 

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE