0
0
PowerShellscripting~10 mins

Automatic variables ($_, $PSVersionTable) in PowerShell - Interactive Code Practice

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

Complete the code to display the PowerShell version using the automatic variable.

PowerShell
Write-Output $[1].PSVersion
Drag options to blanks, or click blank then click option'
A$_
B$PSVersionTable
C$Version
D$PSVersion
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_ instead of $PSVersionTable
Trying to use $Version which is not automatic
Using $PSVersion which is not defined
2fill in blank
medium

Complete the code to output each item in the pipeline using the automatic variable.

PowerShell
Get-Process | ForEach-Object { Write-Output [1] }
Drag options to blanks, or click blank then click option'
A$_
B$PSVersionTable
C$this
D$item
Attempts:
3 left
💡 Hint
Common Mistakes
Using $PSVersionTable inside pipeline which is unrelated
Using $this or $item which are not automatic variables in PowerShell
3fill in blank
hard

Fix the error in the code to correctly display the PowerShell version major number.

PowerShell
Write-Output $PSVersionTable.[1].Major
Drag options to blanks, or click blank then click option'
AVersion
BVersionTable
CPSVersion
DPSVersionTable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Version' instead of 'PSVersion' property
Trying to access 'VersionTable' or 'PSVersionTable' as properties
4fill in blank
hard

Fill both blanks to filter processes with CPU time greater than 100 and output their names.

PowerShell
Get-Process | Where-Object { $_.[1] -gt 100 } | ForEach-Object { Write-Output $_.[2] }
Drag options to blanks, or click blank then click option'
ACPU
BName
CId
DHandles
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Id' or 'Handles' instead of 'CPU' for filtering
Outputting 'Id' instead of 'Name' for process names
5fill in blank
hard

Fill all three blanks to create a hashtable of process names and their IDs for processes with IDs less than 1000.

PowerShell
Get-Process | Where-Object { $_.[1] [2] 1000 } | ForEach-Object { $result[$_.[3]] = $_.Id }
Drag options to blanks, or click blank then click option'
AId
B<
CProcessName
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ProcessName' instead of 'Name' for the key
Using '>' instead of '<' for filtering
Using wrong property for filtering instead of 'Id'