IAM Labs· Lab record

Passed

PowerShell 101: filter a directory export

Filter a directory export down to IT's active staff.

PowerShell sandboxLevel: StarterStart with PowerShell

The ticket

Daniel Reyes
Director of IT, Larkspur Logistics (fictional)
Ticket
Who's on my team?

I need a quick list of everyone in the IT department whose account is active, with their:

  • name
  • sign-in name
  • job title

The directory export is attached.

What IAM Labs verified

IAM Labs ran the script below in its PowerShell sandbox, on the lab's data files, and checked the result:

Skills

Import-CsvWhere-ObjectSelect-ObjectExport-Csv

The script

The latest version that passed in the sandbox, on .

PowerShell · passed in the sandbox
# Import the directory.csv file.
Import-Csv ./directory.csv |

# Keep only active accounts in the IT department.
Where-Object { $_.Department -eq 'IT' -and $_.AccountEnabled -eq 'True' } |

# Select the columns we want to include in the output.
Select-Object DisplayName, UserPrincipalName, JobTitle |

# Export the results to a new CSV file without an extra type information header.
Export-Csv ./it-staff.csv -NoTypeInformation

Larkspur Logistics is a fictional company. Its tickets, people and data were made up for practice, and live in a practice tenant, not a real business. Tenant and org names, domains and IDs are replaced with placeholders like <tenant>.

A read-only record from IAM Labs, a private practice app of hands-on identity and access management labs.