Challenge - 5 Problems
PowerShell File Writer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output file content after running this script?
Consider this PowerShell script that writes text to a file using Set-Content. What will be the content of 'output.txt' after running it?
PowerShell
Set-Content -Path output.txt -Value "Hello, World!"Attempts:
2 left
💡 Hint
Set-Content writes the exact string given to the file without adding quotes.
✗ Incorrect
Set-Content writes the string value directly to the file. It does not add quotes or commands, just the text provided.
💻 Command Output
intermediate2:00remaining
What will be the content of 'log.txt' after this script runs?
This script appends text to a file using Out-File. What will 'log.txt' contain after running both commands?
PowerShell
Out-File -FilePath log.txt -InputObject "Start Log" -Encoding utf8 Out-File -FilePath log.txt -InputObject "End Log" -Encoding utf8 -Append
Attempts:
2 left
💡 Hint
Out-File overwrites by default unless -Append is used.
✗ Incorrect
The first Out-File writes "Start Log" and overwrites any existing content. The second Out-File appends "End Log" on a new line.
📝 Syntax
advanced2:00remaining
Which option correctly writes multiple lines to a file using Set-Content?
You want to write these three lines to 'notes.txt': Line1, Line2, Line3. Which command does this correctly?
Attempts:
2 left
💡 Hint
Set-Content accepts an array of strings to write multiple lines.
✗ Incorrect
Option C passes an array of strings, so each string is written as a separate line. Option C writes a single string with literal \n, not new lines. Option C syntax is invalid. Option C runs separate commands but only the first writes to the file.
🔧 Debug
advanced2:00remaining
Why does this Out-File command fail to append text?
This script is supposed to append "New Entry" to 'data.txt' but overwrites it instead. Why?
PowerShell
Out-File -FilePath data.txt -InputObject "New Entry"Attempts:
2 left
💡 Hint
Check the parameters for appending with Out-File.
✗ Incorrect
Out-File overwrites the file by default. To add text without deleting existing content, you must use -Append.
🚀 Application
expert3:00remaining
How to write a UTF8 BOM encoded file with Set-Content?
You want to write the text "Data Export" to 'export.txt' with UTF8 encoding including BOM using Set-Content. Which command does this correctly?
Attempts:
2 left
💡 Hint
UTF8 BOM encoding requires the special encoding name 'utf8bom'.
✗ Incorrect
The -Encoding parameter 'utf8bom' writes UTF8 with BOM. 'utf8' writes UTF8 without BOM. ASCII is a different encoding. Omitting encoding uses default (usually UTF16).