Bird
0
0

Which of the following is the correct syntax to process each user from a CSV file named users.csv in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Active Directory
Which of the following is the correct syntax to process each user from a CSV file named users.csv in PowerShell?
AImport-Csv users.csv | ForEach-Object { Write-Host $_.Name }
BForEach-Object Import-Csv users.csv { Write-Host $_.Name }
CImport-Csv users.csv ForEach { Write-Host $_.Name }
DGet-Csv users.csv | ForEach-Object { Write-Host $_.Name }
Step-by-Step Solution
Solution:
  1. Step 1: Recognize correct pipeline usage

    Import-Csv users.csv outputs objects piped into ForEach-Object to process each user.
  2. Step 2: Validate syntax correctness

    Import-Csv users.csv | ForEach-Object { Write-Host $_.Name } correctly uses the pipeline and script block syntax to access each user's Name property.
  3. Final Answer:

    Import-Csv users.csv | ForEach-Object { Write-Host $_.Name } -> Option A
  4. Quick Check:

    Pipeline with Import-Csv and ForEach-Object is correct [OK]
Quick Trick: Use pipeline: Import-Csv | ForEach-Object { } [OK]
Common Mistakes:
  • Misplacing ForEach-Object before Import-Csv
  • Using Get-Csv which doesn't exist
  • Omitting the pipeline operator |

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes