Controlling The Flow Of PS Functions Flashcards

1
Q

Comparison operator syntax

A

Variables

$variable = “value”
$variable = “value”

If($variable -eq $comparevariable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Greater than comparison operator

A

Variables

$variable = “1”
$variable = “2”

If($variable -gt $comparevariable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Like comparison operator

A

Variables

$variable = “value”
$variable = “value”

If($variable -like $comparevariable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Match comparison value

A

Variables

$variable = “value”
$variable = “value”

If($variable -match $comparevariable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are collection operators?

A

Variables

Each item in collection is evaluated, and the operator returns every value that is true.

$array = 1..10
$comparevariable = 6

If($array -gt $comparevariable)

If($array -contains $comparevariable)

If($comparevariable -in $array)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are logical operators?

A

Used to invert or combine other expressions. You can connect multiple statements, allowing you to use a single expression to test for numerous conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a ternary operator?

A

IF one equals two, question mark = True and colon = False

A new syntax for IF / ELSE statements

  1. Condition
  2. IF true
  3. IF false

($variableOne -eq $variableTwo) ? $true : $false
($variableOne -eq $variableTwo) ?
(“$variableOne : $variableTwo”) : (“$variableOne ; $variableTwo”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to create an array from 1 to 10?

A

$array = 1..10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If an array is created 1 - 10, and the variable compare is created with a value of 6, how would you compare that the value in compare is found in the array in two different ways?

A

If($array -contains $compare) {
Write-Host “Compared” }

If($compare -in $array) [
Write-Host “Compared” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

You have an array of 1 to 10, and a variable compare with a value of 8. Write a script to check if variable compare is included in the array, and if the variable compare is greater than 8. If it is output Yes, if it is not, output No.

A

If(($compare -in $array) -and ($compare -gt 8)) { Write-Host “Yes” } else { Write-Host “No” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Considering variable1 = 1 and variable2 = 3, write a script using the new scripting version that determines if variable1 is equal to variable2. If it is output true, if it is not, output false.

A

If($variable1 -eq $variable2) ? $true : $false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a loop?

A

A construct that allows you to produce a sequence of instructions inside code, iterating several times as long as the defined condition is met

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a for loop?

A

Iterates through commands a specified number of time

Easy as you commonly know the number of time to loop ahead of time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a while loop?

A

Repeats a command or a group of commands when the given condition is true

Entry controlled loop

Test condition before the execution of the first iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a do-while loop?

A

Condition/Do-While is executed first, then the condition test is at the end of the loop

Exit controlled loop

Tests the condition after the execution of the first iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a do-until loop?

A

Loop repeats until the condition returns true

They are the opposite of the Do-While loop

Do { } Until ( )

17
Q

what is a foreach-object?

A
18
Q

What is a foreach statement or loop?

A
19
Q

What is a foreach() method?

A
20
Q

What happens with an entry loop?

A

Test condition is checked BEFORE entering the loop

21
Q

What happens with an exit loop?

A

Test condition is checked AFTER executing the loop

22
Q

Entry vs Exit loop

A

Variable

$number = 1

While ($number -le 10) { $number; $number++ }

Do { $number; number++ } While($number -le 10)

23
Q

What is the Do-While syntax?

A

Do squiggly brackets While parenthesis/condition

Do { command sequence } While (condition)

24
Q

What are switch statements?

A

Alternate syntax for doing multiple comparisons with a value

25
Q

If you have an IF statement with an ELSE….

A

The ELSE statement is the default is nothing matches

26
Q

What is basic switch statement syntax?

A

Switch (expression) {
Condition1 { code }
Condition2 { code }
Condition3 { code }

$number = 3
# the Switch option means in this statement variable number is the number or object you wish to test
# 5, 10, and 20 are the comparison operators or chosen values to test against
Switch ($number) {
5 { Write-Host “Number equals 5” }
10 { Write-Host “Number equals 10” }
20 { Write-Host “Number equals 20” }
Default. { Write-Host “Number is not equal to 5, 10, or 20” }
}

27
Q

What does Default mean in a Switch statement?

A
28
Q

What are foreach enumerators?

A

Scripting language construct that iterates through COLLECTIONS of items

29
Q

what is in a foreach loop statement?

A

Item - the variable contain the current item
Collection - objects such as files, numbers, or other object types
Script Block - sequence of commands to be executed against each item in the collection

30
Q

What is the base syntax for foreach?

A

ForEach (Item In Collection) {
CODE or SEQUENCE OF COMMANDS
}

31
Q

Foreach is used when sorting through a ……

A

Collection of data

32
Q

Foreach structure expanded

A

$collection = 1..3

ForEach ($number in $collection) {
Write-Host “Current Number: $collection”
}

33
Q

What is $number in:

ForEach ($number in $collection) {
Write-Host “Current Number: $collection”
}

A

A variable

34
Q

What is in called in the following:

ForEach ($number in $collection) {
Write-Host “Current Number: $collection”
}

A

An operator

35
Q

What is the syntax for a basic PS command?

A

Verb-Noun -parameter value -anotherparameter another value -switch

36
Q

What is the parameter, noun, verb, and value of?

Get-EventLog Application -Newest 5

A

Verb = Get-EventLog
Noun = Application
Parameter = -Newest
Value = 5

37
Q

What characters are required to group arrays, collections, and lists?

A

Brackets. [ ]

38
Q

When you know the command you want to use but need guidance about exactly how to use it, what do you type?

E.g. for Get-Process

A

Get-Help Get-Process | more