Quantcast
Viewing all articles
Browse latest Browse all 7132

PowerShell Remoting in Exchange - Return String as RecipientIdParameter

I previously posted this question in the Microsoft Exchange Partner Forum and was asked to post it in MSDN for higher level thinking.

We can manually add source mailboxes to our command to thusly:

Set-MailboxSearch "Test Search" -SourceMailboxes "user1@domain.tld","user2@domain.tld"

To automate the solution, we have created the following script:

$MyMailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.UserPrincipalName -notlike "DiscoverySearchMailbox*"} | Select-Object UserPrincipalName
$MyMailboxSearch = "Test"
$MySourceMailboxes = $null
$x = 0
Foreach ($MyMailbox in $MyMailboxes) {
    if ($x -eq 0) {$MySourceMailboxes += '"' + $MyMailbox.UserPrincipalName + '"'}
    else {$MySourceMailboxes += ',"' + $MyMailbox.UserPrincipalName + '"'}
    $x++
    }

Set-MailboxSearch -Identity $MyMailboxSearch -SourceMailboxes $MySourceMailboxes

When we run this script, we are given an error stating that the mailbox ""user1@domain.tld","user2@domain.tld"" is not valid. I understand that the data type that the -SourceMailbox is expecting is a RecipientIDParameter. I assumed that returning a string would allow the input to work just like if I manually typed the value.

We cannot issue a foreach loop adding a mailbox one-by-one because each entry overwrites the last.

My questions are this:

  1. How can we provide the $MyMailbox.UserPrincipalName in a comma separated single line?
  2. Is there a better way? From what I understand since we are remoting it is not possible to access the assembly "Microsoft.Exchange.Configuration.ObjectModel".

Thank you for your consideration!


-- Ty R. Mote Manager, Specialized Services Hitachi Consulting


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>