Skip to content

New-Resource

Exchange Online: Creates a new resource mailbox

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$Name,
    [switch]$AccountDisabled,
    [string]$Alias,
    [string]$DisplayName,
    [int]$ResourceCapacity,
    [string]$WindowsEmailAddress
)

Process {
    try {
        [string[]]$Properties = @('AccountDisabled','Alias','DisplayName','ResourceCapacity','WindowsEmailAddress')

        $box = New-Mailbox -Name $Name -Room -Force -ErrorAction Stop

        if (-not [System.String]::IsNullOrWhiteSpace($Alias)) {
            $null = Set-Mailbox -Identity $Name -Alias $Alias -ErrorAction Stop
        }
        if (-not [System.String]::IsNullOrWhiteSpace($DisplayName)) {
            $null = Set-Mailbox -Identity $Name -DisplayName $DisplayName -ErrorAction Stop
        }
        if ($PSBoundParameters.ContainsKey('ResourceCapacity')) {
            $null = Set-Mailbox -Identity $Name -ResourceCapacity $ResourceCapacity -ErrorAction Stop
        }
        if (-not [System.String]::IsNullOrWhiteSpace($WindowsEmailAddress)) {
            $null = Set-Mailbox -Identity $Name -WindowsEmailAddress $WindowsEmailAddress -ErrorAction Stop
        }
        if ($PSBoundParameters.ContainsKey('AccountDisabled')) {
            $null = Set-Mailbox -Identity $Name -AccountDisabled $true -Confirm:$false -ErrorAction Stop
        }

        $result = Get-Mailbox -Identity $box.UserPrincipalName -ErrorAction Stop | Select-Object $Properties
        $result | ForEach-Object {
            $_ | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force
        }
    }
    catch { throw }
}

Unique name of the resource, maximum 64 characters

Off

Disable the account associated with the resource

Alias name of the resource

Display name of the resource

Capacity of the resource

Windows email address of the resource

An interactive directory of PowerShell scripts.