0
0
PowerShellscripting~10 mins

Reading file content (Get-Content) in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read the content of a file named 'data.txt'.

PowerShell
Get-Content [1]
Drag options to blanks, or click blank then click option'
A-File data.txt
Bdata.txt
C-Path data.txt
D'data.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the file name in quotes.
Using parameters that don't exist for Get-Content.
2fill in blank
medium

Complete the code to read the content of 'log.txt' and store it in a variable named $content.

PowerShell
$content = [1] 'log.txt'
Drag options to blanks, or click blank then click option'
ARead-File
BRead-Content
CGet-Content
DGet-File
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existing cmdlets like Read-File or Get-File.
Confusing with other cmdlets.
3fill in blank
hard

Fix the error in the code to correctly read all lines from 'notes.txt'.

PowerShell
Get-Content -Path [1]
Drag options to blanks, or click blank then click option'
A'notes.txt'
Bnotes
Cnotes.txt
D-File notes.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the file name.
Using incorrect parameter values.
4fill in blank
hard

Fill both blanks to read the first 5 lines of 'report.txt' and store them in $lines.

PowerShell
$lines = Get-Content [1] -TotalCount [2]
Drag options to blanks, or click blank then click option'
A'report.txt'
B10
C5
D'report.log'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file names.
Using wrong number for lines.
5fill in blank
hard

Fill all three blanks to read 'summary.txt', skip the first 2 lines, and store the rest in $content.

PowerShell
$content = Get-Content [1] | Select-Object -Skip [2] | [3]
Drag options to blanks, or click blank then click option'
A'summary.txt'
B2
COut-String
DOut-File
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the file name.
Using wrong cmdlet to convert output.
Skipping wrong number of lines.