/// <summary>
        /// Gets list of mailboxes from the on permise environment.
        /// </summary>
        /// <param name="entity">An instance of <see cref="EnvironmentEntity"/> that represents the on permise environment.</param>
        /// <returns>A list of mailboxes from the on permise environment.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        public async Task <List <MailboxEntity> > GetMailboxesAsync(EnvironmentEntity entity)
        {
            Command command;
            CommandParameterCollection parameters;
            Collection <PSObject>      results;
            List <MailboxEntity>       mailboxes;
            PSCredential        credential;
            WSManConnectionInfo connectionInfo;
            string password;

            entity.AssertNotNull(nameof(entity));

            try
            {
                password = await service.Vault.GetAsync(entity.Password);

                credential = new PSCredential(entity.Username, password.ToSecureString());

                connectionInfo = GetConnectionInfo(new Uri(entity.Endpoint), MigrationConstants.SchemaUri, credential);

                command = new Command("Get-Mailbox");

                parameters = new CommandParameterCollection
                {
                    { "ResultSize", "Unlimited" }
                };

                using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
                {
                    results = scriptManager.InvokeCommand(runspace, command, parameters);
                }

                mailboxes = results.Select(m => new MailboxEntity
                {
                    DisplayName        = m.Properties["DisplayName"].Value.ToString(),
                    ETag               = "*",
                    Name               = m.Properties["Name"].Value.ToString(),
                    PartitionKey       = entity.RowKey,
                    PrimarySmtpAddress = m.Properties["PrimarySmtpAddress"].Value.ToString(),
                    RowKey             = m.Properties["Guid"].Value.ToString(),
                    SamAccountName     = m.Properties["SamAccountName"].Value.ToString(),
                    UserPrincipalName  = m.Properties["UserPrincipalName"].Value.ToString()
                }).ToList();

                return(mailboxes);
            }
            finally
            {
                command        = null;
                connectionInfo = null;
                credential     = null;
                parameters     = null;
                results        = null;
            }
        }
        /// <summary>
        /// Creates a new migration endpoint in Exchange Online.
        /// </summary>
        /// <param name="entity">An instance of <see cref="EnvironmentEntity"/> that represents the new migration endpoint.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="entity"/> is null.
        /// </exception>
        public async Task CreateMigrationEndpointAsync(EnvironmentEntity entity)
        {
            Command command;
            CommandParameterCollection parameters;
            PSCredential        credential;
            PSCredential        onPermiseCredential;
            Uri                 connectionUri;
            WSManConnectionInfo connectionInfo;
            string              onPermisePassword;

            entity.AssertNotNull(nameof(entity));

            try
            {
                credential = new PSCredential(
                    service.Configuration.ExchangeOnlineUsername,
                    service.Configuration.ExchangeOnlinePassword.ToSecureString());

                onPermisePassword = await service.Vault.GetAsync(entity.Password);

                onPermiseCredential = new PSCredential(entity.Username, onPermisePassword.ToSecureString());

                connectionUri  = new Uri($"{MigrationConstants.ExchangeOnlineEndpoint}{entity.Organization}");
                connectionInfo = GetConnectionInfo(connectionUri, MigrationConstants.SchemaUri, credential);

                command = new Command("New-MigrationEndpoint");

                parameters = new CommandParameterCollection
                {
                    { "Autodiscover" },
                    { "Credentials", onPermiseCredential },
                    { "EmailAddress", entity.Username },
                    { "ExchangeRemoteMove" },
                    { "Name", entity.Name }
                };

                using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
                {
                    scriptManager.InvokeCommand(runspace, command, parameters);
                }
            }
            finally
            {
                command             = null;
                connectionInfo      = null;
                connectionUri       = null;
                credential          = null;
                onPermiseCredential = null;
                parameters          = null;
            }
        }