Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exchange 2007 delegates: add more than one

362 views
Skip to first unread message

Steven

unread,
Jul 7, 2008, 3:39:57 PM7/7/08
to

I’ve been working on some PowerShell scripts to create shared resources\rooms in Exchange 2007 (SP1) and I’ve hit something of a road block.  There are times where I’ll want to add more than one delegate (or let’s say…append one).

 

I’m essentially doing this:

 

$resource = Get-MailboxCalendarSettings –Identity <resource name>

$nDelegate = “<user name>”

$resource.ResourceDelegates += $nDelegate

 

But I get this error (so no ability to even run set-mailboxCalendarSettings):

Exception setting "ResourceDelegates": "Cannot convert value "System.Object[]" to type "Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.Directory.ADObjectId]". Error: "Failed to convert <user name> from System.String to Microsoft.Exchange.Data.Directory.ADObjectId.""

 

The thought was to approach it the same way I do when I’m adding additional email addresses to a mailbox (this is abbreviated to make it simple…there is actual error control in the actual script):

 

param([string]$UserName,[string]$EmailAddress)

$mailB = Get-Mailbox -Identity $UserName

$secAdd = $EmailAddress

$mailB.EmailAddresses += $secAdd

$mailB | Set-Mailbox

 

In the end I’d like I’m trying to write a script that’ll be able to append\add delegates to the current list.  Any thoughts on how one might do this?

RichS [MVP]

unread,
Jul 7, 2008, 4:38:02 PM7/7/08
to
To add multiple delegates to to a calendar for a shared resource try this

$delegates = ('user 1', 'user 2', 'user 3')

set-mailboxcalendarsettings -identity <mailbox> -resourcedelegates $delegates

--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Steven" wrote:

> I've been working on some PowerShell scripts to create shared
> resources\rooms in Exchange 2007 (SP1) and I've hit something of a road
> block. There are times where I'll want to add more than one delegate

> (or let's say.append one).


>
>
>
> I'm essentially doing this:
>
>
>

> $resource = Get-MailboxCalendarSettings -Identity <resource name>


>
> $nDelegate = "<user name>"
>
> $resource.ResourceDelegates += $nDelegate
>
>
>
> But I get this error (so no ability to even run
> set-mailboxCalendarSettings):
>
> Exception setting "ResourceDelegates": "Cannot convert value
> "System.Object[]" to type
> "Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.D
> irectory.ADObjectId]". Error: "Failed to convert <user name> from
> System.String to Microsoft.Exchange.Data.Directory.ADObjectId.""
>
>
>
> The thought was to approach it the same way I do when I'm adding
> additional email addresses to a mailbox (this is abbreviated to make it

> simple.there is actual error control in the actual script):

Steven

unread,
Jul 8, 2008, 9:55:00 AM7/8/08
to
Well yeah I can do that, but I guess my problem is that if a resource
already has say, 2 delegates, and I want to add a third. Currently if you
use Set-MailboxCalendarSettings -identity <mailbox> -ResourceDelegates
<new delegate> it'll overwrite what is there instead of adding. So what
I'm trying to figure out how to do is to take the current list (if there
is one) and append to it.

What I've done so far is get the list of current delegates and store them
as a string in a variable, adding the name of a new delegate, joining the
strings together with the comma as a separator, and then setting it:

-----Begin script-----
param(
[string]$resource = $(throw "You must specify a resource using -resource
<resource account name>"),
[string]$delegate = $(throw "You must specify a delegate using -delegate
<delegate account name>")
)

$xDelegates = (Get-MailboxCalendarSettings -Identity
$resource).ResourceDelegates | foreach {$_.name}
$xDelegates += $delegate

$delegates = [string]::Join(",",$xDelegates)

set-mailboxCalendarSettings -Identity $resource -ResourceDelegates
$delegates
-----End Script-----

In the end the problem that I have is that if there was just one existing
delegate (say userA), when I'd get to += part where I'm adding the next
one, it would append the existing string on the same line (userAuserB),
which won't work obviously. So what I'm trying to figure out is how I can
take the existing delegate list, store it in a variable, and then add to
it new names, and then run Set-MailboxCalendarSettings to add the resource
delegates back. I've tried this:

$xDelegates += "`n$delegate"

Which gets the delegate names on separate lines, but when I try to join
them it doesn't work (it doesn't join them at all). So in the end I'd
like to have it like you suggest, but I'm having a hard time figuring out
how to build the $delegates variable that includes existing delegates and
new ones.

I also tried this, but it didn't work either:

$xDelegates += ",$delegate"

It returns "Object "userA,userB" could not be found, presumably it's
trying to find the mailbox "userA,userB" instead of looking at these as
two separate mailboxes.

Any ideas on how I can make it so that I can get a variable that includes
existing and new delegates that I can successfully add using
set-mailboxcalendarsettings? Thanks for the help. I really appreciate i.

RichS [MVP]

unread,
Jul 8, 2008, 10:54:05 AM7/8/08
to
If I'm reading this right you produce an array of delegates

$xdelegates

why not just do

$xdelegates += "<new delegate>"

and then use $xdelegates in the set-mailboxcalendarsettings

the complication comes when you try to concatenate the delegate list into a
single string. set-mailboxcalendarsettings expects and array of identities
not a string with multiple identities in it

Marco Shaw [MVP]

unread,
Jul 8, 2008, 10:57:57 AM7/8/08
to
Steven wrote:
> Well yeah I can do that, but I guess my problem is that if a resource
> already has say, 2 delegates, and I want to add a third. Currently if you
> use Set-MailboxCalendarSettings -identity <mailbox> -ResourceDelegates
> <new delegate> it'll overwrite what is there instead of adding. So what
> I'm trying to figure out how to do is to take the current list (if there
> is one) and append to it.

I was able to do this with another cmdlet/property a few months ago. I
can't remember the method and my VM is acting weird.

Check back in a few hours after I reboot...

Marco


--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com

Steven

unread,
Jul 9, 2008, 7:16:27 AM7/9/08
to
Best way to explain why this doesn't work is an example:

$newDelegate = "userB"
$xDelegates = "userA"

$xDelegates += $newDelegates

When now look at $xDelegates it now looks like this:
userAuserB

So it comes out as one long string instead of a collection of two separate
strings.

Marco Shaw [MVP]

unread,
Jul 9, 2008, 8:12:15 AM7/9/08
to
Steven wrote:
> Best way to explain why this doesn't work is an example:
>
> $newDelegate = "userB"
> $xDelegates = "userA"
>
> $xDelegates += $newDelegates

If I follow your logic, you're last line should be like this:
[array]$xDelegates += $newDelegate

You could also set $xDelegates earlier like this:

$xDelegates=@() <--Before you even use it
or
[array]$xDelegates="userA" <--As soon as you declare it, make it an array.

Steven

unread,
Jul 9, 2008, 9:31:50 AM7/9/08
to
That was it! Thanks a TON!

-----Original Message-----
From: Marco Shaw [MVP] [mailto:marco.shaw@_NO_SPAM_gmail.com]
Posted At: Wednesday, July 09, 2008 8:12 AM
Posted To: microsoft.public.windows.powershell
Conversation: Exchange 2007 delegates: add more than one
Subject: Re: Exchange 2007 delegates: add more than one

0 new messages