0% found this document useful (0 votes)
8 views9 pages

Ipt1 Reviewer

The document contains quizzes related to PowerShell, covering topics such as command usage, variable types, execution policies, and scripting features. It includes identification questions, true or false statements, and output tracing exercises to assess knowledge of PowerShell functionalities. Additionally, it provides examples of array assignment and user input prompts using the Read-Host cmdlet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Ipt1 Reviewer

The document contains quizzes related to PowerShell, covering topics such as command usage, variable types, execution policies, and scripting features. It includes identification questions, true or false statements, and output tracing exercises to assess knowledge of PowerShell functionalities. Additionally, it provides examples of array assignment and user input prompts using the Read-Host cmdlet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

IPT1 – FT | QUIZ 1

1.0 | IDENTIFICATION (QUIZ 1)


Scheduled Job 1. It is a task that PowerShell starts at a specific time
Write-output 2. What is the alias of the “echo” command in Windows PowerShell scripting language?
3. In PowerShell, you can type a few letters of a command and press the "______" key, and
TAB
PowerShell will finish the word for you.
PS1 4. This file is a script, or "cmdlet," used by Windows PowerShell.
| 5. What is a pipeline operator?
Restricted 6. It permits individual commands but does not allow scripts.
Windows Powershell
7. It is a host application for Windows PowerShell.
ISE
echo 8. It is a command is used to print the variables or strings on the console.
9. It runs scripts that are downloaded from the internet and not signed, if the scripts are unblocked,
RemoteSigned
such as by using the Unblock-File cmdlet.
Remoting 10. It lets you run any PowerShell command on one or more remote computers.
11. It is a cross-platform task automation solution made up of a command-line shell, a scripting
Powershell
language, and a configuration management framework.
12. If you're unsure about a command, you can type “______” followed by the command to get
Get-Help
help.

1. It is the name of the new way for managing the command line that is created by Microsoft in
Monad
2002.
Background Job 2. It is a feature of PowerShell that runs a command without interacting with the current
session.
Powershell 3. It is a feature of PowerShell that lets you run any Windows PowerShell command on one or
Remoting more remote computers.
4. Who published the white paper in 2002?
Jeffrey Snovcr

Monad Manifesto 5. What is the white paper published in 2002?


6. It is a feature of PowerShell that can be started automatically on a one-time or recurring
Scheduled Job
schedule.
7. It is a feature of PowerShell where it is a concrete form of metaprogramming, where one script
Steppable Pipeline
has precise control over the sequence of operations in another.
8. It is a feature of PowerShell that provides completions on input to provide hints, enable
Tab Expansion
discovery, and speed up input entry.
Three/3 9. How many beta versions is released of the shell Microsoft?
September 2005 10. When did the second version of the beta released? Give the month and year.
Command-line 11. It is a standout features where in PowerShell remembers the commands you've recently used,
History so you can scroll back and re-run them easily.
12. When did Microsoft renamed the first name of shell to a Windows PowerShell? Give the year
2006 April
and month.
Tab Key 13. It is the default key binding on Windows PowerShell.
Windows Powershell
14. It is a host application for Windows PowerShell, where you can run commands.
ISE
15. it is a cross-platform task automation solution made up of a command-line shell, a scripting
Powershell
language and a configuration man.
1.1 | TRUE OR FALSE (QUIZ 1)
True 1. Answer on #4, is a Windows shell program built on Microsoft’s .NET Framework.
2. In small companies, PowerShell scripts are often used to help develop, test, and deliver software.
True

False 3. Echo and its alias provide different outputs.


False 4. PowerShell forgets the commands you used.
False 5. A pipeline is a series of commands connected by a coma (,).
True 6. Jeffrey Snover wrote the Monad Manifesto.
False 7. In April 2007, Monad was renamed into Windows Powershell.
False 8. In pipeline, the commands are processed in order from right to left.

1. When you start a background job, a job object does not return immediately, even if the job takes
False an extended time to finish. You can continue to work in the session without interruption while the
job runs.
2. Scheduled jobs are stored on file and registered in Task Scheduler. The jobs can be managed in
False
Task Scheduler or by using the Scheduled Job cmdlets in Windows PowerShell.
3. In the ISE, you can run commands and write, test, and debug scripts in a single Windows-based
True
graphic user interface.
4. You can establish persistent connections, start interactive sessions, and can't run scripts on
False
remøte computers.
5. Command names, parameter names, argument values and file paths can all be completed by
False
pressing the Enter key. The Tab key is the default key binding on Windows.

IPT1 – FT | QUIZ 2

2.1 | IDENTIFICATION (QUIZ 2)


1. Variable names begin with a _____ sign and can include alphanumeric characters and special
$
characters.
[datetime] 2. What will you use to convert a string into date time object?
Global 3. These variables are valid everywhere, even outside the scripts and functions.
Preference 4. These are special variables that control how PowerShell behaves during a session.
Get-Date 5. A Get-Process where you will get the date today.
clear-variable 6. Command used to delete the value of a variable.
null 7. Once the value of the variable is cleared, its value will be?
split 8. It is used in PowerShell to divide a substrings
2 9. In Write-error, the cmdlet sends messages to the stream ___?.
or 10. It returns true if at least one of the conditions is true; otherwise, it returns false.

Echo 1. What is the command that is used to print the variables or strings on the console?
Variable 2. It is a unit of memory in which the data is stored.
3. It is the default execution policy for windows client computers that permits individual
Restricted
commands, but does not allow scripts.
4. It is the default execution policy for non-windows computers and cannot be changed, there is a
Unrestricted
risk of running malicious scripts
Set-Execution
5. What is the command that is used to set the execution policy to run the scripts?
Policy
ps1 6. What is the extension file for the scripts of the PowerShell to run the scripts?
get-process 7. It is a command that get the processes that are running on the local computer.
clear-variable 8. What is the command that is used to delete the value of the variable?
$ 9. In Windows PowerShell, the name of a variable starts with what sign?
Concatenation 10. What operator can we use to join two strings together?
null 11. What is the default value of the variable if we didn't assign anything?
12. It requires that all scripts and configuration files be signed by a trusted publisher, including
AllSigned
scripts that you write on the local computer.
13. It is default execution policy for windows server computers in which it requires a digital
RemoteSigned
signature from a trusted publisher on scripts and configuration file.
Assignment 14. What kind of operator do we use to assign a specified value to the variable?
none of the above 15. Which of the following is the not a valid variable name (excluding the sign)?

2.2 | TRUE OR FALSE (QUIZ 2)


True 1. "Write-Output command is used to print the variables or strings on the console.
2. There are three ways to execute the PowerShell scripts, there is the windows powershell
False
cmdlets, integrated scripting environment of the PowerShell and the command prompt.
3. Variable names that include spaces and other special characters, are difficult to use and should
True
be avoided.
4. You can use a type attribute and cast notation to ensure that a variable can contain only specific
True
object types or objects that can be converted to that type.
5. In PowerShell scripts, we need to assign the data type first before using and naming the
False
variables.
False 6. Aside on assigning single values, we also cannot assign multiple values.
7. If you didn't assign any value in a variable by default, the value of all the variables in a
True
PowerShell is null
False 8. The variable name length is not limited by the available memory of the local storage.
9. If you try to assign a value of another type, PowerShell tries to convert the value to its type. If
True
the type can't be converted, the assignment statement fails.
10. The name of the variables are not case sensitive, and they include spaces and special characters.
True

2.3 | OUTPUT TRACING (QUIZ 2)


1. What is the output of the following code?
$a = 10
5 $b = 5
$result = $a - $b
$result
2. What is the output of the following code?
$global:name =
Powershell
"PowerShell"
Write-Output $global:name

3. What is the output of the following code?


apple banana $string = "apple,banana,cherry"
cherry $array = $string -split ","
$array
4. What is the output of the following code?
$x = 20
if ($x -gt 15) {
Greater than 15 Write-Output "Greater than 15"
} else {
Write-Output "15 or less" }

5. What is the output of the following code?


$y = $false
True
$result = -not $y $result

6. What is the output of the following code?


$a = 8
2 $b = 3
$result = $a % $b
$result
7. What is the output of the following code?
$script:version = "1.0.0"
1.0.0 Write-Output
$script:version

8. What is the output of the following code?


$val = 5
8
$val += 3
$val
9. What is the output of the following code?
$array = @("red", "green",
red:green:blue "blue")
$joined = $array -join ";"
$joined
10. What is the output of the following code?
$trueVal = $true
$falseVal = $false
False
$result = $trueVal -and
$falseVal
$result
11. What is the output of the following code?
$greeting = "Hello"
$name = "World"
Hello World
$message = $greeting + " " +
$name
$message
12. What is the output of the following code?
$array = @("apple", "banana",
banana
"cherry")
Write-Output $array[1]
13. What is the output of the following code?
$num1 = 10
$num2 = 5
False
$result = $num1 -eq
$num2
$result
14. What is the output of the following code?
$a = $true
$b = $false
True
$result = ($a -and $b) -or (-not
$b)
$result
15. What is the output of the following code?

True $a = $true
$b = $false
$c = $a -and (-not $b) -or $b
$c

IPT1 – FT | QUIZ 3
3.1 | IDENTIFICATION

Scope 1. It is where which determines where the variable is available.


Global 2. They are variables that are those variables that are valid everywhere.
User-created
3. Variables which are created and maintained by the user.
Variables
Local 4. They are variables that are inside a function and is limited.
Preference Variable 5. Variables that store the user preferences for the Windows PowerShell.
Operators 6. The building blocks of the Windows PowerShell.
Script 7. These variables are only available to that script in which they are created.
Automatic Variables 8. Variables which store the state of PowerShell, users cannot change the value.
Arithmetic 9. It is used in a PowerShell to perform the calculation of the numeric values
Assignment 10. It is used in a PowerShell to assign, change, or append the values in a variable.
Redirection 11. It is used in PowerShell to redirect the output of one command as an input to another command.
Boolean 12 Expressions which contain the logical operators usually result in what?
Logical 13. It is used in PowerShell to connect expressions or statements together to form a single expression.
Split & Join 14. It is used in PowerShell to divide and combine the substrings.
Modulus % 15. It is an operator to calculate the remainder of the division operation
Comparison 16. It is used in PowerShell to compare the values.
-join 17. It is an operator that is used to concatenate the multiple strings into a single string.
Verb-noun 18. PowerShell uses what kind of naming pair to name?
-split 19. It is an operator that is used to break a string into substrings.
cmdlets 20. They are native PowerShell commands, not stand-alone executables.

ADDITIONAL

➢ In PowerShell, you can assign multiple variables in one line using array assignment or the Set-Variable cmdlet.

EXAMPLE OF ARRAY ASSIGNMENT


# Assign multiple variables using array assignment
$a, $b, $c = 1, 2, 3
# Output the variables
Write-Output "a: $a, b: $b, c: $c"
EXAMPLE USING SET-VARIABLE CMDLET
# Assign multiple variables using Set-Variable
Set-Variable -Name 'a' -Value 1
Set-Variable -Name 'b' -Value 2
Set-Variable -Name 'c' -Value 3
# Output the variables
Write-Output "a: $a, b: $b, c: $c"

➢ You can use PowerShell to prompt for user input with the Read-Host cmdlet. This cmdlet allows you to get input
from the user during script execution.

EXAMPLE OF SIMPLE INPUT


# Prompt for a simple input
$name = Read-Host -Prompt 'Enter your name'
Write-Output "Hello, $name!"
EXAMPLE OF INPUT WITH CONFIRMATION
# Prompt for a password (secure input)
$password = Read-Host -Prompt 'Enter your password' -AsSecureString
Write-Output "Password entered successfully."
EXAMPLE OF INPUT WITH VALIDATION
# Prompt for input and validate it
function Get-ValidatedInput {
param (
[string]$Prompt,
[scriptblock]$ValidationScript
)

do {
$input = Read-Host -Prompt $Prompt
$valid = & $ValidationScript $input
if (-not $valid) {
Write-Host "Invalid input, please try again." -ForegroundColor Red
}
} while (-not $valid)

return $input
}

# Use the function to get a valid number


$number = Get-ValidatedInput -Prompt 'Enter a number between 1 and 10' -
ValidationScript {
param ($input)
return ($input -match '^\d+$' -and $input -ge 1 -and $input -le 10)
}
Write-Output "You entered: $number"
EXAMPLE OF CHOICE INPUT
# Prompt the user to choose from a set of options
$choices = @("Option1", "Option2", "Option3")
$selectedChoice = $null

while ($selectedChoice -eq $null) {


$selectedChoice = $choices | Out-GridView -Title "Select an option" -PassThru
}

Write-Output "You selected: $selectedChoice"


EXAMPLE OF SCRIPT WITH ARITHMETIC OPERATION (TRY TO ANSWER ALSO THE
OUTPUTS)
# Prompt the user for the first number
$number1 = [int](Read-Host "Enter the first number")

# Prompt the user for the second number


$number2 = [int](Read-Host "Enter the second number")

# Perform arithmetic operations


$sum = $number1 + $number2
$difference = $number1 - $number2
$product = $number1 * $number2

if ($number2 -ne 0) {
$quotient = $number1 / $number2
} else {
$quotient = "undefined (cannot divide by zero)"
}

$modulus = $number1 % $number2

# Display the results


Write-Output "The sum of $number1 and $number2 is: $sum"
Write-Output "The difference between $number1 and $number2 is: $difference"
Write-Output "The product of $number1 and $number2 is: $product"
Write-Output "The quotient of $number1 divided by $number2 is: $quotient"
Write-Output "The remainder of $number1 divided by $number2 is: $modulus"

ACTIVITY

➢ TRY TO CREATE A SCRIPT

Steps:
1. Open Windows PowerShell ISE. Create a script that will display a greeting and a random name of your
groupmate with today’s date.
2. Create a variable that will hold this greeting, “Hello World! Welcome to IPT1.”
3. Create a variable that will hold today’s date.
4. Create an array of your names in your group.
5. Create a variable that will hold the random name.
6. Print/display the greeting, random name, and today’s date.
7. Run the script 3 times.
➢ Variable is a unit of memory in which the data is stored. In PowerShell, the name of a variable starts with a dollar
sign $. The name of variables is not case sensitive and can include spaces and special characters. When you
assign a value for a variable, you must use the assignment or equal operator =.
o Example:
o $firstName = Diwata
o $lastName = Pares
o $123
o $extension_Name
➢ Array is a data structure that can hold a collection of items. The code below is the basic syntax in creating an
array in PowerShell:
o $arrayName = @ (arrayItem1, arrayItem2, arrayItem3…..arrayItem10)
➢ “Get-Date” is a command where it returns the date today.
➢ “Get-Random” is a command where it will return a random value.

➢ TRY TO CREATE A SCRIPT

Part 1:
1. Create a variable called $studentName and assign it with a value "Juan Dela Cruz".
2. Create another variable called $subjectScore with a floating-point number representing a grade 85.5.
3. Combine $studentName and $subjectScore into a sentence like "Juan Dela Cruz scored 85.5 in the subject." and
store it in a new variable called $result.
Part 2:
1. Create a variable called $scoreString and set it to "92".
2. Convert $scoreString to an integer and store it in a new variable called $scoreInt.
3. Multiply $scoreInt by 2 and store the result in $finalScore. Ensure $finalScore is an integer.
Part 3:
1. Create three variables, $num1, $num2, and $num3, and assign them the values 10, 15.5, and 20, respectively.
2. Calculate the average of these three numbers and store it in a variable called $average. Ensure the average is a
floating-point number.
Part 4:
1. Create a variable called $grade and set it to 78.
2. Use an if-statement to check:
3. If $grade is greater than or equal to 90, set $gradeLevel to "A".
4. If $grade is greater than or equal to 80, set $gradeLevel to "B".
5. If $grade is greater than or equal to 70, set $gradeLevel to "C".
6. Otherwise, set $gradeLevel to "D".
Part 5:
1. Use $gradeLevel and $studentName variables to create a sentence: "Juan Dela Cruz received a _ grade."
2. Store this sentence in a new variable called $finalResult and display it in uppercase letters. Use ToUpper() method.

➢ PowerShell does not have built-in symbolic operators like >, <, >=, or <=. You muse the named comparison
operators for numeric and string comparisons. Use “-gt” to check a value is greater than another, and “-ge” to
check if a value is greater than or equal to another. On the other hand, use “-lt” to check if a value is less than
another, and “-le” to check if a value is less than or equal to another. Lastly, “-eq” to check if two values are
equal, and “-ne” to check if two values are not equal.

"Why did the programmer go broke? Because he lost his cache!"

You might also like