Note that there are some explanatory texts on larger screens.

plurals
  1. POContinue execution on Exception
    text
    copied!<p>Below is the script I want to execute. The issue here is once an exception occurs it stops executing, I used <code>continue</code> in the catch block but that did not work. How do I get it working even after an exception occurs it should loop in <code>foreach</code>.</p> <p>I also used a <code>while($true)</code> loop but that went into infinite loop. How to go about it?</p> <pre><code>$ErrorActionPreference = "Stop"; try { # Loop through each of the users in the site foreach($user in $users) { # Create an array that will be used to split the user name from the domain/membership provider $a=@() $displayname = $user.DisplayName $userlogin = $user.UserLogin # Separate the user name from the domain/membership provider if($userlogin.Contains('\')) { $a = $userlogin.split("\") $username = $a[1] } elseif($userlogin.Contains(':')) { $a = $userlogin.split(":") $username = $a[1] } # Create the new username based on the given input $newalias = $newprovider + "\" + $username if (-not $convert) { $answer = Read-Host "Your first user will be changed from $userlogin to $newalias. Would you like to continue processing all users? [Y]es, [N]o" switch ($answer) { "Y" {$convert = $true} "y" {$convert = $true} default {exit} } } if(($userlogin -like "$oldprovider*") -and $convert) { LogWrite ("Migrating User old : " + $user + " New user : " + $newalias + " ") move-spuser -identity $user -newalias $newalias -ignoresid -Confirm:$false LogWrite ("Done") } } } catch { LogWrite ("Caught the exception") LogWrite ($Error[0].Exception) } </code></pre> <p>Kindly help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload