Bird
Raised Fist0
PowerShellscripting~20 mins

Why file management is core to scripting in PowerShell - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
File Management Mastery
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 PowerShell command?
Consider the following command that lists files in a directory and filters by extension. What output will it produce?
PowerShell
Get-ChildItem -Path . -Filter *.txt | Select-Object -ExpandProperty Name
AOutputs the full path of all files in the current directory
BLists all files and folders in the current directory, including subdirectories
CShows an error because -Filter cannot be used with Get-ChildItem
DLists all filenames with .txt extension in the current directory, one per line
Attempts:
2 left
💡 Hint
Think about what -Filter and Select-Object do in this command.
🧠 Conceptual
intermediate
1:30remaining
Why is file management important in scripting?
Which of the following best explains why file management is a core skill in scripting?
ABecause scripts often need to read, write, or organize files to automate tasks
BBecause scripts only work with files and cannot interact with other system parts
CBecause file management is the only way to run scripts on a computer
DBecause scripts must always delete files to free up space
Attempts:
2 left
💡 Hint
Think about what tasks scripts automate in daily computer use.
🔧 Debug
advanced
2:30remaining
Identify the error in this PowerShell script snippet
This script tries to copy all .log files from one folder to another but fails. What is the error?
PowerShell
Copy-Item -Path C:\Logs\*.log -Destination C:\BackupLogs -Recurse
AThe -Recurse parameter is invalid here because wildcards with -Path do not support recursion
BThe destination path must be enclosed in quotes
CThe script is missing a -Force parameter to overwrite files
DThe source path should use forward slashes instead of backslashes
Attempts:
2 left
💡 Hint
Check how wildcards and recursion work together in Copy-Item.
🚀 Application
advanced
2:30remaining
Which script snippet correctly renames all .txt files by adding a prefix?
You want to add the prefix 'OLD_' to all .txt files in a folder. Which snippet does this correctly?
AGet-ChildItem -Filter *.txt | Rename-Item -NewName {"OLD_" + $_.Name}
BGet-ChildItem -Filter *.txt | Rename-Item -NewName {"OLD_" + $_.BaseName + $_.Extension}
CGet-ChildItem -Filter *.txt | Rename-Item -NewName {"OLD_" + $_}
DGet-ChildItem -Filter *.txt | Rename-Item -NewName {"OLD_" + $_.FullName}
Attempts:
2 left
💡 Hint
Consider how to build the new filename correctly including extension.
📝 Syntax
expert
2:00remaining
What error does this PowerShell script produce?
Analyze this script that attempts to create a directory if it doesn't exist: if (!(Test-Path -Path C:\Data)) { New-Item -ItemType Directory -Path C:\Data } What happens when you run it?
AIt throws a runtime error because New-Item requires -Force
BIt throws a syntax error due to missing semicolon
CIt runs successfully and creates the directory if missing
DIt fails because Test-Path cannot be negated with !
Attempts:
2 left
💡 Hint
Check if the syntax and commands are valid PowerShell.

Practice

(1/5)
1. Why is file management considered a core part of scripting in PowerShell?
easy
A. Because it slows down script execution
B. Because it only works with text files
C. Because it requires no commands to manage files
D. Because it automates organizing and handling many files efficiently

Solution

  1. Step 1: Understand the role of file management in scripting

    File management commands help automate organizing and changing files, which is essential for handling many files quickly and correctly.
  2. Step 2: Evaluate the options

    Because it automates organizing and handling many files efficiently correctly states the benefit of automating file handling. Options A, B, and C are incorrect because it does not slow down script execution, is not limited to text files, and requires commands.
  3. Final Answer:

    Because it automates organizing and handling many files efficiently -> Option D
  4. Quick Check:

    File management automates file handling = D [OK]
Hint: File management automates tasks to save time and reduce errors [OK]
Common Mistakes:
  • Thinking file management only works with text files
  • Believing file management slows down scripts
  • Assuming no commands are needed to manage files
2. Which of the following is the correct PowerShell command to list all files in the current directory?
easy
A. Get-ChildItem
B. Get-FileList
C. List-Files
D. Show-Files

Solution

  1. Step 1: Identify the standard command for listing files

    In PowerShell, the command to list files and folders is Get-ChildItem.
  2. Step 2: Check the options

    Only Get-ChildItem matches the correct PowerShell command. The others are invalid or do not exist.
  3. Final Answer:

    Get-ChildItem -> Option A
  4. Quick Check:

    List files command = Get-ChildItem [OK]
Hint: Remember: Get-ChildItem lists files and folders [OK]
Common Mistakes:
  • Using non-existent commands like Get-FileList
  • Confusing commands with similar names
  • Assuming 'List-Files' is a valid PowerShell command
3. What will be the output of this PowerShell command?
Get-ChildItem -Path . -Filter '*.txt' | Select-Object -ExpandProperty Name
medium
A. Lists all file names with .txt extension in the current directory
B. Lists all folders in the current directory
C. Shows full file paths of all files
D. Deletes all .txt files in the current directory

Solution

  1. Step 1: Understand the command parts

    Get-ChildItem with -Filter '*.txt' selects files ending with .txt. Select-Object -ExpandProperty Name extracts just the file names.
  2. Step 2: Determine the output

    The command outputs a list of .txt file names in the current directory, not folders or full paths, and does not delete files.
  3. Final Answer:

    Lists all file names with .txt extension in the current directory -> Option A
  4. Quick Check:

    Filter '*.txt' + expand Name = list of .txt file names [OK]
Hint: Filter '*.txt' lists text files; expand Name shows just names [OK]
Common Mistakes:
  • Thinking it lists folders instead of files
  • Assuming it shows full file paths
  • Confusing it with a delete command
4. Identify the error in this PowerShell script snippet that tries to move all .log files to a Logs folder:
Move-Item -Path *.log -Destination Logs
medium
A. The wildcard *.log is not allowed in Move-Item
B. The destination folder 'Logs' must be a full path or exist beforehand
C. Move-Item cannot move files, only folders
D. The command needs -Recurse to work

Solution

  1. Step 1: Analyze Move-Item usage

    Move-Item can move files using wildcards, but the destination folder must exist or be a full path.
  2. Step 2: Check the options

    The destination folder 'Logs' must be a full path or exist beforehand correctly points out the need for the destination folder to exist or be a full path. Options A, C, and D are incorrect because wildcards are allowed, Move-Item moves files, and -Recurse is not needed here.
  3. Final Answer:

    The destination folder 'Logs' must be a full path or exist beforehand -> Option B
  4. Quick Check:

    Destination folder must exist for Move-Item [OK]
Hint: Ensure destination folder exists before moving files [OK]
Common Mistakes:
  • Assuming wildcards are not allowed in Move-Item
  • Thinking Move-Item only moves folders
  • Adding -Recurse unnecessarily
5. You want to automate cleaning up old backup files in PowerShell. Which script snippet correctly deletes all .bak files older than 30 days in the Backup folder?
hard
A.
Get-ChildItem Backup | Remove-Item -Filter '*.bak' -OlderThan 30
B.
Remove-Item -Path Backup\*.bak -OlderThan 30
C.
Get-ChildItem -Path Backup -Filter '*.bak' | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item
D.
Remove-Item Backup -Filter '*.bak' -DateOlderThan 30

Solution

  1. Step 1: Understand filtering by date and file type

    Get-ChildItem with -Filter '*.bak' selects backup files. Where-Object filters files older than 30 days using LastWriteTime compared to current date minus 30 days.
  2. Step 2: Confirm deletion command

    Remove-Item deletes the filtered files. Options B, C, and D use invalid parameters or incorrect syntax.
  3. Final Answer:

    Get-ChildItem -Path Backup -Filter '*.bak' | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -> Option C
  4. Quick Check:

    Filter by date + Remove-Item = correct cleanup script [OK]
Hint: Use Get-ChildItem + Where-Object for date filtering before Remove-Item [OK]
Common Mistakes:
  • Using non-existent parameters like -OlderThan
  • Trying to filter inside Remove-Item
  • Not filtering files by date before deletion
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard