[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 105
  • Last Modified:

Powershell logic

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
sirbounty
Asked:
sirbounty
1 Solution
 
Joe KlimisCommented:
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now