I am doing some testing and not sure the best way to accomplish the desired 
outcome.

I have a script with several functions. One advanced function will take a CSV 
file and generate AD users. I have a sub-function to validate names:

function Validate-Name ([string]$field) {
       if ($field -notmatch "[^\p{L}^\p{Pd}\s/']") {
              return $false
       } else {
              return $true
       }
}
During the Process{} block, I'd like to attempt to validate the first/last name 
and bail out for just the one user and continue attempting for any subsequent 
entries in the CSV file. My main question is there a best practice, or agreed 
general guideline for handling this? Do you wrap everything in an If statement 
before proceeding? Or do you have a Break/Return/Exit within the process block? 
I thought Exit/Return/Break end the entire function, but reading up I'm not 
sure if using Break to exit the Process{} block would also exit the parent 
function. I'm interested in how others handle this.

I'd like to be able to break out of processing that one row, then continue 
processing the CSV file:

Process {
       If (Validate-Name $FirstName) {
              # Log failure (TBD)
Break
       }
}

Process {
       If (Validate-Name $FirstName) {
              # Log failure (TBD)
              Exit
       }
}

Process {
       If (Validate-Name $FirstName) {
              $failed = $true
       }

       If ($failed) {
              # Log failure (TBD)
       } Else {
              #Process user Add
       }
}

Confidentiality Notice: This is a transmission from Community Hospital of the 
Monterey Peninsula. This message and any attached documents may be confidential 
and contain information protected by state and federal medical privacy 
statutes. They are intended only for the use of the addressee. If you are not 
the intended recipient, any disclosure, copying, or distribution of this 
information is strictly prohibited. If you received this transmission in error, 
please accept our apologies and notify the sender. Thank you.



Reply via email to