0
0
PowerShellscripting~10 mins

Report generation automation 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 list all files in the current directory.

PowerShell
Get-ChildItem [1]
Drag options to blanks, or click blank then click option'
A-Name
B-Recurse
C-Filter *.txt
D-Path .
Attempts:
3 left
💡 Hint
Common Mistakes
Using -Recurse lists files in all subfolders, not just current directory.
Using -Filter limits files by pattern, not directory.
2fill in blank
medium

Complete the code to export the list of files to a CSV file named report.csv.

PowerShell
Get-ChildItem -Path . | [1] -Path report.csv
Drag options to blanks, or click blank then click option'
AOut-File
BExport-Csv
CConvertTo-Csv
DSet-Content
Attempts:
3 left
💡 Hint
Common Mistakes
Using Out-File writes plain text, not structured CSV.
ConvertTo-Csv outputs CSV text but does not save to file.
3fill in blank
hard

Fix the error in the code to filter files larger than 1MB.

PowerShell
Get-ChildItem -Path . | Where-Object { $_.Length [1] 1MB }
Drag options to blanks, or click blank then click option'
A-gt
B<
C-eq
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > inside script blocks causes errors.
Using -eq checks for equality, not size comparison.
4fill in blank
hard

Fill both blanks to create a hashtable with file names as keys and sizes as values for files modified in the last 7 days.

PowerShell
$fileSizes = @{}
Get-ChildItem -Path . | Where-Object { $_.LastWriteTime [1] (Get-Date).AddDays(-7) } | ForEach-Object { $fileSizes[[2]] = $_.Length }
Drag options to blanks, or click blank then click option'
A-gt
B$_.Name
C$files.Name
D$fileSizes.Length
Attempts:
3 left
💡 Hint
Common Mistakes
Using $files.Name tries to access property on collection, not individual file.
Mixing variable names or using incorrect comparison operator causes errors.
5fill in blank
hard

Fill all three blanks to create a report dictionary with uppercase file names as keys, sizes as values, and only include files larger than 500KB.

PowerShell
$report = @{}
foreach ($file in Get-ChildItem -Path . | Where-Object { $file.Length [3] 500KB }) {
  $report[[1]] = [2]
}
Drag options to blanks, or click blank then click option'
A$file.Name.ToUpper()
B$file.Length
C-gt
D$file.LastWriteTime
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of -gt causes errors.
Using $file.LastWriteTime instead of size for filtering.