Yes.

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Orlebeck, Geoffrey
Sent: Wednesday, November 16, 2016 1:04 PM
To: 'powershell@lists.myitforum.com'
Subject: [powershell] RE: Breaking Process { } Block:

I just want to regurgitate this in my own words to make sure I'm grasping this 
concept.

I can create an outer loop (e.g. ":Outerloop") inside the Process{} block. Then 
if the Validate-Name fails I can instead execute a "Break :Outerloop" to end 
that object's processing, but the Process{} block will continue executing on 
additional objects being passed through the pipeline. So in essence you're 
defining the scope of the break. Right?

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Michael B. Smith
Sent: Tuesday, November 15, 2016 4:54 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: [powershell] RE: Breaking Process { } Block:


ATTENTION: This email came from an external source. DO NOT open attachments or 
click on links from unknown senders or unexpected emails.

If you do a break in the outer loop (or mainline) of a process{} block, you 
will exit the process block.

Using a named break or continue is a good solution with low overhead.

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Webster
Sent: Tuesday, November 15, 2016 5:42 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: [powershell] RE: Breaking Process { } Block:

Here is something MBS showed me a little while ago. See if it might give you an 
idea.

Function GetBadStreamingIPAddresses
{
                Param([string]$ComputerName)

                #loop through the configured streaming ip address and compare 
to the physical configured ip addresses
                #if a streaming ip address is not in the list of physical ip 
addresses, it is a bad streaming ip address
                ForEach ($Stream in ($Script:StreamingIPAddresses | Where 
{$_.Servername -eq $ComputerName})) {
                                $exists = $false
                                :outerLoop ForEach ($ServerNIC in 
$Script:NICIPAddresses.Item($ComputerName))
                                {
                                                ForEach ($IP in $ServerNIC)
                                                {
                                                            # there could be 
more than one IP
                                                                If 
($Stream.IPAddress -eq $IP)
                                                                {
                                                                                
$Exists = $true
                                                                           
break :outerLoop
                                                                }
                                                }
                                }
                                if (!$exists)
                                {
                                               $obj1 = New-Object -TypeName 
PSObject
                                                $obj1 | Add-Member -MemberType 
NoteProperty -Name ServerName               -Value $ComputerName
                                                $obj1 | Add-Member -MemberType 
NoteProperty -Name IPAddress                    -Value $Stream.IPAddress
                                                $Script:BadIPs += $obj1
                                }
                }
}

Thanks


Carl Webster
Citrix Technology Professional
http://www.CarlWebster.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__t.sidekickopen01.com_e1t_c_5_f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJN7t5XYgdV8QRW2zWLDn4XrdjzW7fK3rs56dwxZf67wwsR02-3Ft-3Dhttp-253A-252F-252Fwww.carlwebster.com-252F-26si-3D6012126861197312-26pi-3D4311b7b1-2D332d-2D4242-2D8585-2D36954b184dc7&d=CwMFAg&c=GtV7VYka8XzFJya76SH24R7OU_QKFTyBlklHoDMCjFY&r=WF1NZuUqAd1bRIxLFT_0wz8npqTRKjPr3_qzGO_dTx_Q3Taym2JWM42n-cKyG-6W&m=wYIdGC9rT6VPBtS90N-_5zcZPBlstb9ODP_ptwnMCpA&s=uhAM3qlSDinX3tvnLPsvWaVqVBOxsj9Az7y4GMy0lyY&e=>
The Accidental Citrix Admin

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Orlebeck, Geoffrey
Sent: Tuesday, November 15, 2016 4:30 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: [powershell] Breaking Process { } Block:

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