Skip to content

New-ExchangeResource

Exchange: Creates a new Resource Mailbox

#Requires -Version 5.1

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true)]
    [string]$Name,

    [ValidateSet('Room', 'Equipment')]
    [string]$Type = 'Room',

    [string]$Alias,

    [string]$DisplayName,

    [int]$Capacity,

    [string]$PrimarySmtpAddress,

    [bool]$AccountDisabled = $true
)

Process {
    try {
        $params = @{
            'Name'            = $Name
            'Confirm'         = $false
            'ErrorAction'     = 'Stop'
            'AccountDisabled' = $AccountDisabled
        }
        if ($Type -eq 'Room') { $params.Add('Room', $true) } else { $params.Add('Equipment', $true) }
        if ($Alias) { $params.Add('Alias', $Alias) }
        if ($DisplayName) { $params.Add('DisplayName', $DisplayName) }
        if ($PrimarySmtpAddress) { $params.Add('PrimarySmtpAddress', $PrimarySmtpAddress) }
        if ($PSBoundParameters.ContainsKey('Capacity')) { $params.Add('ResourceCapacity', $Capacity) }

        $resource = New-Mailbox @params

        $result = [PSCustomObject]@{
            Name               = $resource.Name
            DisplayName        = $resource.DisplayName
            ResourceType       = $resource.RecipientTypeDetails
            PrimarySmtpAddress = $resource.PrimarySmtpAddress
            Action             = "ResourceCreated"
            Status             = "Success"
            Timestamp          = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the unique name of the resource.

Specifies the type of resource (Room or Equipment). Defaults to Room.

Optional. Specifies the Exchange alias.

Optional. Specifies the display name.

Optional. Specifies the capacity of the resource (e.g., number of seats).

Optional. Specifies the primary SMTP address.

If set, disables the associated Active Directory user account. Defaults to true for resource mailboxes.

An interactive directory of PowerShell scripts.