Back to script samples page
List of all users in the Volunteers department to a CSV file

This command will export a list of all users in the “Volunteers” department to a CSV file. It is a good idea to review the names contained in the CSV file to ensure you have identified the correct users.

# This command will export a list of all users in the “Volunteers” department to a CSV file. It is a good idea to review the names contained in the CSV file to ensure you 

# This first command will import the Azure Active Directory module into your PowerShell session.
Import-Module MSOnline

# Capture administrative credential for future connections.
$credential = get-credential

# Establishes Online Services connection to Azure Active Directory  
Connect-MsolService -Credential $credential

# This command will export a list of all users in the “Volunteers” department to a CSV file. It is a good idea to review the names contained in the CSV file to ensure you have identified the correct users.
Get-MsolUser | Where { $_.department -eq "Volunteers" } | select UserPrincipalName | Export-Csv .\volunteers.csv -NoTypeInformation
Downloaded 0 times
* * * * - (1)
Comments