0
0
PowerShellscripting~5 mins

Automatic variables ($_, $PSVersionTable) in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe PowerShell version information
BThe current user's username
CThe last error message
DThe current object in the pipeline
Which automatic variable contains PowerShell version and environment details?
A$PSVersionTable
B$_
C$Error
D$Host
How would you access the size of a file in a pipeline using $_?
A$_.Length
B$_.Path
C$_.Size
D$_.Name
Why might a script check $PSVersionTable before running?
ATo get the current user's permissions
BTo verify the current directory
CTo confirm the PowerShell version supports needed features
DTo list running processes
In which scenario is $_ most commonly used?
ATo store error messages
BInside a ForEach-Object loop
CTo display PowerShell version
DTo set environment variables
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.