Continue execution on Exception
You use try {...} catch {...}
when you want to handle errors. If you want to ignore them, you should set $ErrorActionPreference = "Continue"
(or "SilentlyContinue"
) as @C.B. suggested, or use -ErrorAction "SilentlyContinue"
for the particular operation raising the error. If you want to handle errors from a certain instruction, you'd put that instruction in the try {...} catch {...}
block, not the entire loop, e.g.:
foreach($user in $users) {
...
try {
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)
}
}