Solved

Powershell logic

Posted on 2014-10-30
1
98 Views
Last Modified: 2014-10-30
Need to make sure I'm thinking this through.

If a criteria is true, then I need to perform another test, otherwise perform the default test.
Thus, I need to drop out of an if statement, but continue my foreach....is break the statement I need for this?

foreach ($cog in $widgests) {
if ($something -eq $true) {
  if ($something else -eq $true) {
    #do something
  } else {
    #This is bad - don't even try the additional tests
    break; #??
  }
} else {
  if ($test -eq $true) {write-host 'All is right with the world'} else {write-host 'Who moved my cheese?'}
}
}

Open in new window

0
Comment
Question by:sirbounty
1 Comment
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40413580
Hi

Change line 7 to Continue
This will just skip the loop itteration

break will end the foreach loop

I hope this helps

see here for a good explanation

Joe
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Synchronize a new Active Directory domain with an existing Office 365 tenant
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now