Recall & Review
beginner
What is the purpose of the automatic variable $_ in PowerShell?
The $_ variable represents the current object in the pipeline. It is used inside loops and commands like ForEach-Object to refer to each item being processed.
Click to reveal answer
beginner
What information does the $PSVersionTable automatic variable provide?
$PSVersionTable contains details about the PowerShell environment, including the version number, edition, and platform information.
Click to reveal answer
intermediate
How would you use $_ to filter files larger than 1MB in a directory?
You can use Get-ChildItem and Where-Object with $_.Length to filter files: <br>
Get-ChildItem -File | Where-Object { $_.Length -gt 1MB }Click to reveal answer
intermediate
Explain why $PSVersionTable is useful when writing scripts.
It helps scripts check the PowerShell version and environment to ensure compatibility or enable version-specific features.
Click to reveal answer
beginner
In a ForEach-Object loop, what does $_ represent and why is it important?
$_ represents the current item being processed in the loop. It is important because it allows you to access properties or perform actions on each item individually.
Click to reveal answer
What does the automatic variable $_ represent in PowerShell?
✗ Incorrect
The $_ variable always holds the current object being processed in the pipeline or loop.
Which automatic variable contains PowerShell version and environment details?
✗ Incorrect
$PSVersionTable holds detailed information about the PowerShell version and environment.
How would you access the size of a file in a pipeline using $_?
✗ Incorrect
The Length property of a file object gives its size in bytes, accessed via $_.Length.
Why might a script check $PSVersionTable before running?
✗ Incorrect
Scripts check $PSVersionTable to ensure the PowerShell version supports required commands or syntax.
In which scenario is $_ most commonly used?
✗ Incorrect
$_ is commonly used inside ForEach-Object or Where-Object to represent the current pipeline item.
Describe how the automatic variable $_ works in a PowerShell pipeline and give an example of its use.
Think about how you process each item one by one in a list.
You got /3 concepts.
Explain what information $PSVersionTable provides and why it is useful in scripting.
Consider why a script might want to know which PowerShell version is running.
You got /3 concepts.