0
0
PowerShellscripting~10 mins

Why PowerShell is object-oriented - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the type of an object in PowerShell.

PowerShell
$obj = Get-Process
$obj.[1]
Drag options to blanks, or click blank then click option'
AGetObjectType()
BType
CTypeName
DGetType()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Type' property which does not exist.
Confusing method names like 'GetObjectType()'.
2fill in blank
medium

Complete the code to access the 'Id' property of a process object.

PowerShell
$proc = Get-Process -Name notepad
$proc.[1]
Drag options to blanks, or click blank then click option'
AName
BId
CProcessId
DPID
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PID' which is not a direct property.
Using 'ProcessId' which is incorrect.
3fill in blank
hard

Fix the error in the code to call the 'ToString()' method on an object.

PowerShell
$obj = Get-Date
$obj.[1]
Drag options to blanks, or click blank then click option'
AtoString()
Bto_string()
CToString()
DToString
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses causes the method not to execute.
Using incorrect method name casing.
4fill in blank
hard

Fill both blanks to create a custom object with properties 'Name' and 'Age'.

PowerShell
$person = [PSCustomObject]@{
  Name = [1]
  Age = [2]
}
Drag options to blanks, or click blank then click option'
A'Alice'
B30
C25
D'Bob'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes makes them strings, not numbers.
Using wrong quotes or missing quotes for strings.
5fill in blank
hard

Fill all three blanks to filter processes with CPU usage greater than 1 and select their names.

PowerShell
Get-Process | Where-Object { $_.[1] [2] [3] } | Select-Object Name
Drag options to blanks, or click blank then click option'
ACPU
B>
C1
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Id' instead of 'CPU' property.
Using wrong comparison operators.