Foreach ($line in $valuesfield){ $PosIdentity = $line.identity; $PosUser = $line.user; $PosRight = $line.right; $PosInheritance=$line.inheritance; If (-NOT(validate $PosIdentity){"$PosIdentity was not found!";Exit 2} ElseIf {(-NOT(validate $PosUser){"$PosUser was not found!";Exit 3} Else{ $ErrorActionPreference="stop"; #Dynamic change begins trap {"Error in the allocation. `n let's try the other changes";continue} Add-MailboxPermission -Identity $PosIdentity -User $PosUser -AccessRights $Posright -Inheritance $PosInheritance; }