0
0
PowerShellscripting~10 mins

Bulk user operations from CSV 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 import users from a CSV file.

PowerShell
Import-Csv [1]
Drag options to blanks, or click blank then click option'
A-Input 'users.csv'
B-File 'users.csv'
C-Path 'users.csv'
D-Source 'users.csv'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like -File or -Input.
Not enclosing the file name in quotes.
2fill in blank
medium

Complete the code to loop through each user imported from CSV.

PowerShell
foreach ($user in [1]) { Write-Output $user.Name }
Drag options to blanks, or click blank then click option'
AImport-Csv 'users.csv'
B$users
CGet-Content 'users.csv'
DRead-Host 'users.csv'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Get-Content which reads raw text lines, not objects.
Using a variable not defined before the loop.
3fill in blank
hard

Fix the error in the code to create a new user from CSV data.

PowerShell
New-ADUser -Name $user.Name -SamAccountName $user.[1] -AccountPassword (ConvertTo-SecureString $user.Password -AsPlainText -Force) -Enabled $true
Drag options to blanks, or click blank then click option'
AUserName
BUser
CSamAccountName
DUsername
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names that do not match CSV headers.
Ignoring case sensitivity in property names.
4fill in blank
hard

Fill both blanks to filter users with 'Admin' in their role and create them.

PowerShell
Import-Csv 'users.csv' | Where-Object { $_.Role [1] '*Admin*' } | ForEach-Object { New-ADUser -Name $_.Name -SamAccountName $_.UserName -UserPrincipalName $_.UserPrincipalName -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled [2] }
Drag options to blanks, or click blank then click option'
A-like
B-eq
C$true
D$false
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' which requires exact match instead of pattern match.
Setting -Enabled to $false which disables the account.
5fill in blank
hard

Fill all three blanks to update user email and enable the account only if status is 'Active'.

PowerShell
Import-Csv 'users.csv' | ForEach-Object { if ($_.Status [1] 'Active') { Set-ADUser -Identity $_.UserName -EmailAddress $_.[2] -Enabled [3] } }
Drag options to blanks, or click blank then click option'
A-eq
BEmail
C$true
D$false
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ne' or other operators instead of '-eq'.
Using wrong property names like 'EmailAddress' if CSV uses 'Email'.
Setting -Enabled to $false which disables the user.