# Office 365 – Creating Archive Mailboxes with PowerShell in bulk

Quick PowerShell Script that allows to enable Archive Mailboxes for users that don’t have it enabled. Below script just does…

blog

24 Oct 2018 fr

![Office 365 – Creating Archive Mailboxes with PowerShell in bulk](/wp-content/uploads/2018/10/img_5bd02343c15f2.png)

Quick PowerShell Script that allows to enable Archive Mailboxes for users that don't have it enabled. Below script just does 2 steps:

- 📝 Connect to Office 365
- 📝 Add Archive Mailbox that doesn't have it

There are some additional configuration options in there allowing one to do things one step at the time.

### 💡 Office 365 – PowerShell Script to create archive mailboxes

```powershell
Clear-Host
Import-Module PSSharedGoods #-Force

$Configuration = @{
    Tenant = @{
        UserName         = 'przemyslaw.klys@domain.com'
        Password         = 'C:\Users\pklys\OneDrive - Evotec\Support\GitHub\PSWinDocumentation\Ignore\MySecurePassword.txt'
        PasswordSecure   = $true
        PasswordFromFile = $true
        ConnectionURI    = 'https://outlook.office365.com/powershell-liveid/'
        Authentication   = 'Basic'
        SessionAzure     = 'Azure'
        SessionAzureAD   = 'AzureAD'
        SessionExchange  = 'Exchange'
    }
    Steps  = @{
        ConnectTenant            = @{
            Azure          = $false
            AzureAD        = $false
            ExchangeOnline = $true
        }
        AddArchiveToAllMailboxes = $true
    }
}
if ($Configuration.Steps.ConnectTenant.Azure) {
    $SessionAzure = Connect-WinAzure -SessionName $Configuration.Tenant.SessionAzure -Username $Configuration.Tenant.UserName -Password $Configuration.Tenant.Password -AsSecure:$Configuration.Tenant.PasswordSecure -FromFile:$Configuration.Tenant.PasswordFromFile
}
if ($Configuration.Steps.ConnectTenant.AzureAD) {
    $SessionAzureAD = Connect-WinAzureAD -SessionName $Configuration.Tenant.SessionAzureAD -Username $Configuration.Tenant.UserName -Password $Configuration.Tenant.Password -AsSecure:$Configuration.Tenant.PasswordSecure -FromFile:$Configuration.Tenant.PasswordFromFile
}
if ($Configuration.Steps.ConnectTenant.ExchangeOnline) {
    $Session = Connect-WinExchange -SessionName $Configuration.Tenant.SessionExchange -Username $Configuration.Tenant.UserName -Password $Configuration.Tenant.Password -AsSecure:$Configuration.Tenant.PasswordSecure -FromFile:$Configuration.Tenant.PasswordFromFile -ConnectionURI $Configuration.Tenant.ConnectionURI -Authentication $Configuration.Tenant.Authentication
    Import-PSSession $Session -AllowClobber
}

if ($Configuration.Steps.AddArchiveToAllMailboxes) {
    $Users = Get-Mailbox -Filter {ArchiveStatus -Eq "None" -AND RecipientTypeDetails -eq "UserMailbox"}
    foreach ($User in $Users) {
        Write-Color 'Enabling archive for user ', $User.UserPrincipalName -Color White, Yellow
        $Output = $User | Enable-Mailbox -Archive
    }
}
```

### 💡 You will need those

Below are 2 modules that I use to **Connect to Office 365 **and to use **colorful** output. You still will need standard modules required to connect to Office 365 because **PSSharedGoods** provides just a wrapper that allow easy connection setup. While you could skip those (and the script that is linked above doesn't require it) I've wrote some simple wrappers that allow me to manage things in easy way, and the way I want it.

```powershell
Install-Module PSSharedGoods
Install-Module PSWriteColor
```

## Projets associés

Projets liés aux tags, catégories et au contenu de cet article.

[Tous les projets](/fr/projets/)

Recherche des projets associés...

[Retour au blog](/blog)

## Articles associés

- [Office 365 – Find Users Forwarding Emails (PowerShell)](/fr/blog/office-365-find-users-forwarding-emails-powershell/)
- [Sending email as an alias (proxy address) with Office 365](/fr/blog/sending-email-as-an-alias-proxy-address-with-office-365/)
- [Creating Visual Indicators for spoofed / external emails with PowerShell](/fr/blog/creating-visual-indicators-for-spoofed-external-emails-with-powershell/)

<!-- PowerForge markdown artifact sha256:51617E1D268D0CB223407724324E7F5876D1D4A3ABA5660B6295C27331536A15 -->
