Bird
Raised Fist0
PowerShellscripting~20 mins

Report generation automation in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Report Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of CSV report generation script
What is the output of this PowerShell script that generates a CSV report from a list of users?
PowerShell
 $users = @(
    @{Name='Alice'; Age=30; Department='HR'},
    @{Name='Bob'; Age=25; Department='IT'},
    @{Name='Charlie'; Age=35; Department='Finance'}
)
$users | Export-Csv -Path 'report.csv' -NoTypeInformation
Get-Content 'report.csv' | Select-Object -First 3
A
"\"Name\",\"Age\",\"Department\""
"\"Alice\",30,\"HR\""
"\"Bob\",25,\"IT\""
B
Name,Age,Department
Alice,30,HR
Bob,25,IT
C
Name Age Department
Alice 30 HR
Bob 25 IT
D
"Name,Age,Department"
"Alice,30,HR"
"Bob,25,IT"
Attempts:
2 left
💡 Hint
Think about how Export-Csv formats the output with quotes and commas.
📝 Syntax
intermediate
2:00remaining
Correct syntax for filtering report data
Which option correctly filters a list of processes to include only those with CPU usage greater than 10 and exports to a CSV report?
AGet-Process | Filter-Object { $_.CPU > 10 } | Export-Csv -Path 'high_cpu.csv' -NoTypeInformation
BGet-Process | Where { CPU > 10 } | Export-Csv 'high_cpu.csv' -NoTypeInformation
CGet-Process | Where-Object CPU -gt 10 | Export-Csv -Path 'high_cpu.csv'
DGet-Process | Where-Object { $_.CPU -gt 10 } | Export-Csv -Path 'high_cpu.csv' -NoTypeInformation
Attempts:
2 left
💡 Hint
Remember the correct cmdlet and syntax for filtering objects in PowerShell.
🔧 Debug
advanced
2:00remaining
Identify the error in report generation script
What error will this script produce when run, and why? $services = Get-Service $services | Where-Object Status -eq 'Running' | Export-Csv -Path 'running_services.csv' -NoTypeInformation
PowerShell
$services = Get-Service
$services | Where-Object Status -eq 'Running' | Export-Csv -Path 'running_services.csv' -NoTypeInformation
ATypeError: Cannot compare Status property directly without script block
BNo error, script runs and exports running services
CSyntaxError: Missing script block in Where-Object
DRuntimeError: Export-Csv path not found
Attempts:
2 left
💡 Hint
Check the syntax of Where-Object usage.
🚀 Application
advanced
2:00remaining
Automate report generation with date-stamped filename
Which script correctly generates a report of disk usage and saves it with a filename including the current date in YYYY-MM-DD format?
A
$date = Get-Date -Format 'yyyy-MM-dd'
Get-PSDrive -PSProvider FileSystem | Select-Object Name,Free,Used | Export-Csv -Path "disk_report_$date.csv" -NoTypeInformation
B
$date = Get-Date -Format 'dd-MM-yyyy'
Get-PSDrive -PSProvider FileSystem | Select Name,Free,Used | Export-Csv -Path "disk_report_$date.csv"
C
$date = Get-Date -Format 'yyyyMMdd'
Get-PSDrive -PSProvider FileSystem | Select-Object Name,Free,Used | Export-Csv -Path 'disk_report_$date.csv' -NoTypeInformation
D
$date = Get-Date -Format 'yyyy-MM-dd'
Get-PSDrive -PSProvider FileSystem | Select-Object Name,Free,Used | Export-Csv -Path 'disk_report_date.csv' -NoTypeInformation
Attempts:
2 left
💡 Hint
Check date format and variable interpolation in strings.
🧠 Conceptual
expert
2:00remaining
Understanding pipeline behavior in report automation
In a PowerShell script that generates a report, what happens if you place Export-Csv before filtering the data with Where-Object in the pipeline?
AThe script will fail with a pipeline error because Export-Csv must be last.
BThe CSV file will contain all data before filtering, so the report is not filtered.
CThe CSV file will be empty because Export-Csv clears the pipeline.
DThe filtering will still apply after Export-Csv, so the report is filtered correctly.
Attempts:
2 left
💡 Hint
Think about how pipelines process commands in order.

Practice

(1/5)
1. What is the main benefit of automating report generation using PowerShell scripts?
easy
A. It saves time and reduces manual errors.
B. It makes the computer run faster.
C. It removes the need for any data input.
D. It automatically fixes all data mistakes.

Solution

  1. Step 1: Understand automation benefits

    Automation helps by doing repetitive tasks quickly and accurately.
  2. Step 2: Relate to report generation

    Generating reports manually can be slow and prone to errors, automation fixes this.
  3. Final Answer:

    It saves time and reduces manual errors. -> Option A
  4. Quick Check:

    Automation = Saves time and reduces errors [OK]
Hint: Think why computers automate tasks: speed and accuracy [OK]
Common Mistakes:
  • Confusing automation with hardware speed
  • Assuming automation removes all data input
  • Believing automation fixes data errors automatically
2. Which PowerShell command correctly exports data to a CSV file named report.csv?
easy
A. Get-Process > report.csv
B. Export-Data -File report.csv
C. Get-Process | Export-Csv -Path report.csv
D. Save-Report report.csv

Solution

  1. Step 1: Identify correct export command

    PowerShell uses Export-Csv to save objects as CSV files.
  2. Step 2: Check syntax correctness

    Get-Process | Export-Csv -Path report.csv uses Get-Process piped to Export-Csv with -Path parameter correctly.
  3. Final Answer:

    Get-Process | Export-Csv -Path report.csv -> Option C
  4. Quick Check:

    Export-Csv with -Path = Get-Process | Export-Csv -Path report.csv [OK]
Hint: Use Export-Csv with -Path to save CSV files [OK]
Common Mistakes:
  • Using redirection operator > which saves raw text, not CSV
  • Using non-existent commands like Export-Data or Save-Report
  • Omitting the -Path parameter in Export-Csv
3. What will be the output of this PowerShell script?
Get-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object -First 2 | Export-Csv -Path running.csv -NoTypeInformation; Get-Content running.csv
medium
A. Empty file because no services are running.
B. An error because Export-Csv cannot be piped.
C. All services regardless of status.
D. The first two running services listed in CSV format.

Solution

  1. Step 1: Filter running services and select first two

    The script filters services with Status 'Running' and selects first two.
  2. Step 2: Export to CSV and display content

    Export-Csv saves these two services to running.csv, then Get-Content shows the CSV text.
  3. Final Answer:

    The first two running services listed in CSV format. -> Option D
  4. Quick Check:

    Filter + Export-Csv + Get-Content = The first two running services listed in CSV format. [OK]
Hint: Export-Csv saves objects; Get-Content reads file text [OK]
Common Mistakes:
  • Thinking Export-Csv cannot be piped
  • Assuming all services are output without filtering
  • Believing file will be empty if services run
4. Identify the error in this script snippet for generating a report:
$data = Get-Process
$data | Export-Csv report.csv -NoTypeInformation
Import-Csv report.csv | Where-Object { Status -eq 'Running' }
medium
A. Missing $_ before Status in Where-Object filter.
B. Export-Csv cannot be used without -Path parameter.
C. Get-Process does not return objects.
D. Import-Csv cannot read CSV files.

Solution

  1. Step 1: Check Where-Object filter syntax

    The filter uses Status without $_, which is required to reference the current object.
  2. Step 2: Validate other commands

    Export-Csv works without -Path if file name is given; Get-Process returns objects; Import-Csv reads CSV files correctly.
  3. Final Answer:

    Missing $_ before Status in Where-Object filter. -> Option A
  4. Quick Check:

    Where-Object needs $_ for property access [OK]
Hint: Use $_.Property inside script blocks for object properties [OK]
Common Mistakes:
  • Omitting $_ in script block filters
  • Thinking Export-Csv always needs -Path parameter
  • Believing Get-Process returns text, not objects
5. You want to automate a daily report that lists all processes running for more than 1 hour and save it as long_processes.csv. Which script snippet correctly achieves this?
hard
A.
$threshold = (Get-Date).AddHours(-1)
Get-Process | Where-Object { $_.ExitTime -lt $threshold } | Export-Csv -Path long_processes.csv -NoTypeInformation
B.
$threshold = (Get-Date).AddHours(-1)
Get-Process | Where-Object { $_.StartTime -lt $threshold } | Export-Csv -Path long_processes.csv -NoTypeInformation
C.
$threshold = (Get-Date).AddHours(-1)
Get-Process | Where-Object { $_.StartTime -gt $threshold } | Export-Csv -Path long_processes.csv -NoTypeInformation
D.
Get-Process | Where-Object { $_.LastRunTime -lt (Get-Date).AddHours(-1) } | Export-Csv long_processes.csv

Solution

  1. Step 1: Identify property for running duration

    Processes have StartTime indicating when started; running processes with StartTime < threshold means running longer than 1 hour.
  2. Step 2: Check filter logic and export

    $threshold = (Get-Date).AddHours(-1)
    Get-Process | Where-Object { $_.StartTime -lt $threshold } | Export-Csv -Path long_processes.csv -NoTypeInformation
    filters processes started more than 1 hour ago, then exports correctly with -NoTypeInformation.
  3. Final Answer:

    $threshold = (Get-Date).AddHours(-1) Get-Process | Where-Object { $_.StartTime -lt $threshold } | Export-Csv -Path long_processes.csv -NoTypeInformation -> Option B
  4. Quick Check:

    StartTime -lt threshold = long running processes [OK]
Hint: Use StartTime property to check how long process running [OK]
Common Mistakes:
  • Using non-existent ExitTime or LastRunTime properties
  • Filtering recently started processes with StartTime -gt threshold
  • Omitting -NoTypeInformation in Export-Csv