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?
$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):
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.
$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
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
$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.
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.
-----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