[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

exchange 2007 powershell - how continue a script when an error is found

Hi,

I am running this command and when there is an error in a user mailbox, the command doesn´t go to the next user  and quit the command .....

Get-Mailbox -resultsize 2500 | where {$_.servername -eq "server"} | Sort-Object SamAccountName | set-casmailbox -owaenabled $true

How can I use this command and skip to the next user if an error is found.

Thank you

0
decioracy
Asked:
decioracy
  • 5
  • 2
  • 2
  • +1
1 Solution
 
maumenCommented:
Maybe expanding your command to include the ForEach-Object command.
 
0
 
shauncroucherCommented:
Just add the following to the end of the command and you should be fine:

-ErrorAction SilentlyContinue

Shaun
0
 
decioracyAuthor Commented:
Hi Shauncroucher,

It didn´t work , The command stopped after ~300 users and returned:

WARNING: An unexpected error has occurred and debug information is being generated: The value 'HTTP§1§1§§§§§§' is already present in the collection
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
decioracyAuthor Commented:
Hi maumen,

Explain in details your full solution

Thank all of you
0
 
shauncroucherCommented:
That sounds more like an underlying issue to me.

Run Toolbox --> Exchange Best Practices Analyser --> Health Check and also check event logs.

Any errors found?

Shaun
0
 
krishnasmtpport25Commented:
Hi,

Can you try this ?

$users = Get-Mailbox -resultsize 2500 | where {$_.servername -eq "server"}

foreach ($user in $users)
{
set-casmailbox $user -owaenabled $true
}

Regards,
Krishna
0
 
maumenCommented:
In light of the new information, I doubt that the ForEach-Object command will help. krishnasmtpport25 has provided a common use for the command.
0
 
decioracyAuthor Commented:
hi krishnasmtpport25,

I am testing your solution ....

Thank you
0
 
decioracyAuthor Commented:
Perfect solution !
0
 
decioracyAuthor Commented:
I gave to krishnasmtpport25 the points because he gave  a complete solution.

Maumen gave a tip and not the complete command ....

Dear Maumem, If you don´t agree with this, please let me know about  and we will talk about that.

Thank you
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now