Scripts:ExportO365UserList_v2.0 and Import_UserList_For_Archive_Mailbox

    Today, I manage to complete the bellow script, in order to automate exporting user list from Office 365 and also with a second script to enable mailbox archive for specific users

    Let’s take a closer look and see how it works

    What do you need to know before you begin?

    • Make sure you have already installed Windows Azure AD PowerShell
    • You must check and be sure your server or your computer has access to the internet

    Let’s have a quick look how to execute the script ExportO365UserList_v2.0 and Import_UserList_For_Archive_Mailbox.ps1 on Windows PowerShell and what this script do for us.

    1. Login to your computer with Administrator credentials
    2. Start Windows Azure AD PowerShell “As Administrator”


3. Next step, copy the scripts ExportO365UserList_v2.0 and Import_UserList_For_Archive_Mailbox.ps1 on (C:\) drive


4. Let’s start by running the script from Windows Azure AD PowerShell itself.
In case you get weird error messages when you try to run a script, the reason is only one, security settings built into Windows PowerShell include something called the “execution policy” the execution policy determines how (or if) PowerShell runs scripts. By default, PowerShell’s execution policy is set to Restricted that means that scripts – including those you write yourself – won’t run.
Navigate back to Windows PowerShell and set the Execution policy to unrestricted in order to be able to run the script, in that case, use this command to set your execution policy to RemoteSigned or Unrestricted


    Note: The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer.

    Windows PowerShell has four different execution policies:

    • Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
    • AllSigned – Only scripts signed by a trusted publisher can be run.
    • RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
    • Unrestricted – No restrictions; all Windows PowerShell scripts can be run.
    1. The most common (default) way to run a script is by calling it:

    PS C:\> & “C:\Admin\My first Script.ps1”

    If the path does not contain any spaces, then you can omit the quotes and the ‘&’ operator

    PS C:\> C:\Admin\Myscript.ps1

    If the script is in the current directory, you must indicate this using .\ (or ./ will also work)

    PS C:\> .\Myscript.ps1

    In our case scenario we run the script in the current directory “C:\” so, we must indicate this using .\ and we click Enter


5. Type your Global Admin credentials, Username and Password in order to login and the script automatically will export the Office 365 User List on C:\


6. Go to C:\ drive and check the list which is exported there, with the name O365UserList.csv


7. Next step, is to open the exported list with the excel file, on the list we can see all licensed users, SMTP addresses and display name


    Now we will filter this list and we’ll select only the users that we want to enable mailbox archive


8. I will copy on notepad only the SMTP addresses (UserPrincipalName) and paste them on the notepad as follow

    Note: on the top of the file type Identity


    Save the file on C:\ drive as UserListForMailboxArchive.csv

9. Navigate to Windows Azure Active Directory Module for Windows PowerShell and run the Import_UserList_For_Archive_Mailbox.ps1 script


    As we can see Mailbox Archive was enabled for those users


    You can download the scripts from TechNet Gallery, click here