Search code examples
.netpowershellexchange-server

How to create Microsoft.Exchange.Data.Unlimited<T> structure with Powershell?


I'm developing a powershell script to modify some Microsoft Exchange mailboxes. I want to add a parameter to my function with data type "ByteQuantifiedSize" as it is used for mailbox quotas.

A simple example:

function generateSubscriptionInformation
{
param(            
    [Parameter(Mandatory=$true)][Microsoft.Exchange.Data.ByteQuantifiedSize]$StandardQuota         
)
write-host $StandardQuota
}
generateSubscriptionInformation -StandardQuota 12345 #works
generateSubscriptionInformation -StandardQuota unlimited #doesn't work

How can I set a unlimited value via parameter? Look also at https://learn.microsoft.com/en-us/previous-versions/exchange-server/exchange-150/ff340799%28v%3dexchg.150%29 .

I cannot create a unlimited value or variable like

1. new-object "Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize, Microsoft.Exchange .Data,Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]"

  1. New-Object 'Microsoft.Exchange.Data.Unlimited[ByteQuantifiedSize]'

Who can help?


Solution

  • Try this:

    $typeParam    = [Microsoft.Exchange.Data.ByteQuantifiedSize]
    $concreteType = [Microsoft.Exchange.Data.Unlimited`1].MakeGenericType(@($typeParam))
    $unlimitedBQS = [System.Activator]::CreateInstance($concreteType)