Script Powershell In Place Hold Mailbox with Exchange 2010

Hello, 

I have a script that allows me to make a InPlaceHold newly created mailboxes via Exchange 2010.

But every time I run, he released me an error message: See attached picture.

Here is the script in question:

#Initialize variables
$policyname = "In Place - Hold"
$members = Import-CSV "C:\migration\Script\New_User\New_User_List.csv"  -delimiter ";" 
$Result = "C:\migration\Script\New_User\New_User_Result.log"

$powerUser = "******"
$powerPass = "******"
$password = ConvertTo-SecureString $powerPass -AsPlainText -Force
$adminCredential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $powerUser,$password

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $adminCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

#Get current mailboxes in our mailbox search
$InPlaceHoldMailboxes = (Get-MailboxSearch $policyname).sourceMailboxes

#Add another user to the array, the line bellow can be a loop of more than one user.
foreach ( $member in $members)
{
    if ($InPlaceHoldMailboxes -contains($member.name))
    {
    Write-Host $("User " + $member.name + " already present") -ForegroundColor:yellow
    Out-File -FilePath $Result -InputObject $("IN-PLACE HOLD - WARNING, User " + $member.name + " already present in members")  -Encoding UTF8 -append
    }

    else
    {
        $InPlaceHoldMailboxes += $member.upn
        Write-Host $("User " + $member.name + " added") -ForegroundColor:green
        Out-File -FilePath $Result -InputObject $("IN-PLACE HOLD - SUCCESS, User " + $member.name + " added to members")  -Encoding UTF8 -append
    }

}

#Add them to the MailboxSearch
Try
{
    Set-MailboxSearch $policyname -SourceMailboxes $InPlaceHoldMailboxes -Force -ErrorAction 'Stop'
    Write-Host $("SUCCESS, " + $policyname + " updated") -ForegroundColor:green
    Out-File -FilePath $Result -InputObject $("IN-PLACE HOLD - SUCCESS, " + $policyname + " updated")  -Encoding UTF8 -append
}
Catch
{
    Write-Host $("ERROR, policie " + $policyname + " NOT updated") -ForegroundColor:red
    Out-File -FilePath $Result -InputObject $("IN-PLACE HOLD - ERROR, " + $policyname + " NOT updated")  -Encoding UTF8 -append
    Write-Error $_.Exception.ToString() > $Result
    Exit
}

#start the mailboxsearch
Start-MailboxSearch -Identity $policyname -Force

Remove-PSSession $Session

I use Powershell 4.0

Thank you for your help.

February 10th, 2015 4:51pm

Please read the error message carefully as it tells you what is wrong. "You cannot update multiple mailboxes".  You must do one at a time.
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 5:17pm

Thank you for your reply.

I do it one at time.

February 10th, 2015 5:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics