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.