for-each ($objObject in $colObjects){
if (!$?) {
$foreach.movenext() }
else {
do some processing here
}I used this in my script for exporting mailbox statistics from Exchange (see post: PowerShell - Mailbox Size to CSV). I had some problems with aliases not being unique and it was causing the script to error. To avoid this, I simply said if there was any error, move to the next record.
Another way to handle this would be using the $lastexitcode variable. This returns an integer, rather than true or false. If the lost operation was successful, 0 (zero) is returned and 1 (one) is returned if the last operation failed.
These are global variables built-in to PowerShell. So, you don't have to assign them. Much like Err.Number in VBScript the system handles the assignment of the variable.
0 comments:
Post a Comment