0
0
PowerShellscripting~20 mins

Get-ChildItem for listing in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Get-ChildItem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Get-ChildItem command?
You run this command in a folder containing three files: file1.txt, file2.log, and file3.txt.

Get-ChildItem -Filter *.txt

What will be listed?
PowerShell
Get-ChildItem -Filter *.txt
ALists file2.log only
BNo files are listed
CLists file1.txt and file3.txt only
DLists all files: file1.txt, file2.log, file3.txt
Attempts:
2 left
💡 Hint
Think about what the filter *.txt means.
💻 Command Output
intermediate
2:00remaining
What does this command output?
You run this command in a folder with subfolders and files:

Get-ChildItem -Recurse -Directory

What will it list?
PowerShell
Get-ChildItem -Recurse -Directory
ALists only top-level folders
BLists only files recursively
CLists all files and folders recursively
DLists only folders recursively
Attempts:
2 left
💡 Hint
Look at the -Directory switch.
📝 Syntax
advanced
2:00remaining
Which command correctly lists all hidden files in the current folder?
Choose the correct PowerShell command to list hidden files only.
AGet-ChildItem -Attributes Hidden
BGet-ChildItem -Attributes +Hidden
CGet-ChildItem -Hidden
DGet-ChildItem -Filter Hidden
Attempts:
2 left
💡 Hint
Check how to filter by attributes in Get-ChildItem.
🔧 Debug
advanced
2:00remaining
Why does this command fail to list files larger than 1MB?
You try to list files larger than 1MB with:

Get-ChildItem | Where-Object { $_.Length -gt 1MB }

But it returns no files. Why?
PowerShell
Get-ChildItem | Where-Object { $_.Length -gt 1MB }
A1MB is not a valid size unit in PowerShell expressions
BGet-ChildItem does not return Length property
CWhere-Object syntax is incorrect
DFiles larger than 1MB do not exist
Attempts:
2 left
💡 Hint
Check how to specify file size in bytes.
🚀 Application
expert
2:00remaining
How to list only files modified in the last 7 days?
You want to list files changed in the last 7 days using Get-ChildItem and Where-Object. Which command does this correctly?
AGet-ChildItem | Where-Object { $_.CreationTime -lt (Get-Date).AddDays(-7) }
BGet-ChildItem | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) }
CGet-ChildItem | Where-Object { $_.LastAccessTime -gt (Get-Date).AddDays(7) }
DGet-ChildItem | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(7) }
Attempts:
2 left
💡 Hint
Think about comparing LastWriteTime to 7 days ago.