Any ideas on a cleaner way to write this? - run through a function with multiple steps; if any step fails, restart the function from the begining

Basically there are 3 different functions for various "tests"; they each return "1" if the test passes and "0" on failure.  A "master" function calls these 3 functions in the desired order and keeps a counter
of tests that pass.  The counter has to be 1 to proceed to step 2, has to be 2 to proceed to step 3, and when it's 3 the loop closes.
This approach is giving the expected results, but I was wondering if anyone has ideas on a cleaner approach?  What I really wanted to accomplish was to have the 3 tests past in succession and to provide an overall pass and proceed to the next step;
and also to exit the function if any step fails rather than running through each step before trying again.  If the script were to for example loop through the 3 tests and wait until each one passes, tests 1 and 2 might pass, but then 3 might fail
a few times and finally pass before the script exits.  I did not want to allow for that scenario to count as an overall pass.
Function Test1 {
If PASS Return 1
If FAIL Return 0
Function Test2 {
If PASS Return 1
If FAIL Return 0
Function Test3 {
If PASS Return 1
If FAIL Return 0
Function TestAll
[int]$counter = 0
$Check1 = Test1
If ($check1 -eq 1) {$counter++}
If ($counter -lt 1) {Exit}
Start-Sleep -s 15
$check2 = Test2
If ($check2 -eq 1) {$counter++}
If ($counter -lt 2) {Exit}
Start-Sleep -s 15
$check3 = Test3
If ($check3 -eq 1) {$counter++}
If ($counter -lt 3) {Exit}
Return $counter
Do {$STATUSCOUNT = TestAll}
While ($STATUSCOUNT -lt "3")

This is cleaner:
Function Test1 {
If PASS Return 1
If FAIL Return 0
Function Test2 {
If PASS Return 1
If FAIL Return 0
Function Test3 {
If PASS Return 1
If FAIL Return 0
Function TestAll{
while($true){
while($true){
$counter=0
if(($counter+=Test1) -ne 1){break}
if(($counter+=Test2) -ne 2){break}
if(($counter+=Test2) -ne 3){break}
return
Write-Host ('try again' + $counter) -fore
TestAll
Of course all of your test functions have syntax errors.
\_(ツ)_/

Similar Messages

  • After downloading the latest update, my playlists now go into shuffle mode everytime I try to play.  I have turn6ed off shuffle on both my computer and ipod, and even tried recreating a new list, to no avail.  Any ideas as to what may be causing this?

    After downloading the latest update for my Ipod touch, my playlists now go into "shuffle" mode everytime I try to play.  I have turned off shuffle on both itunes and my ipod and even tried recreating the playlist and syncing with no luck.  I don't know what is causing this, because before the last download, it never happened.  Any ideas on how to fix?

    Since this is an XP machine, which version of iTunes do you have installed?  Is it the latest version?
    Have you tried starting iTunes, attach the USB end of the cable, then while holding the home button on the iPod connect the 30-pin connector end of the cable to the iPod...that is the recovery mode but also should make iTunes see the iPod.
    If that doesn't work you may need to take the iPod back and have it tested by the genius bar techs to make sure the connector is not bad.

  • When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    When I take my phone off charge in the morning I get an info box on the front which has the sound trumpet icon with a line through it and the word Mute.  The only way to get rid of it is to reboot the phone any ideas as to how I can stop this happening?

    Hello cor-el, thanks for your reply. I changed my settings for downloads to desktop and it has appeared on there. When I double click I am asked which program I want to open file. I click firefox and another box "opening install" says I have chosen to open the file which is an application and do I want to save it. This is the only real option so I press save file. I get a box saying this is an executable file which may contain viruses - do you want to run. I press ok and the final box showing C drive file name and desktop appears stating application not found.
    This happens the same whenever I try to install.
    To my untrained eye the application is not being recognised as an application and I cannot work out how to get it to do that.
    My plugin is still showing as out of date.
    Is there anything you could suggest. Thanks for your time.

  • I'm trying to sync a new i phone to i tunes.  I get message that says cannot be used because the apple mobile device service is not started.  Any idea what I can do to solve this issue?

    I'm trying to sync a new iphone into i tunes.  I'm getting a message that says that this iphone cannot be used because the apple mobile device service is not started.  Any idea what I can do to solve this issue?

    See Here...
    AMDS for Windows
    http://support.apple.com/kb/TS1567
    AMDS for Mac
    http://support.apple.com/kb/ht1747

  • I had to reformat my desktop pc and lost all my music. Is there any way to transfer the music from the ipod to the pc?

    I lost the music on my pc when I had to reformat the disk.  Is there any way to transfer the music from the Ipod to the pc?  I am told that if I try to sync the music that it will erase all the music on my Ipod.

    Transfer iTunes purchases by:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    Transfer other music by using a third-party programlike one of those discussed here:
    Copy music from Ipod to new computer...: Apple Support Communities
    You can also rredownload mos iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • If meta data LUN is totaly destroied , is there any way to rebuild the data from the video LUN

    If meta data LUN is totaly destroied , is there any way to rebuild the data from the video LUN ????

    What happened to your metadata? Are you sure the metadata is gone?
    In theory, file carving could be attempted on the data LUNs, but you would need a tool that understands how Xsan lays out data across LUNs in a stripe group and hope your fragmentation isn't too bad. I doubt such a tool exists, but if one does it almost certainly is not publicly available. You should probably contact a data recovery service with experience recovering data from Xsan. Do that before you do anything else if this data is really important.

  • HT4859 Is there any way to restore the contacts from the iCloud onto my existing phone?

    I had all my contacts disappear this afternoon.  Is there any way to restore the contacts from the iCloud onto my existing phone?  This article makes it seem as if the iCloud information is only accessible upon setup of a new devise.

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • Is there any way to remove the duration from the course outline in Presenter 8?

    Is there any way to remove the duration from the course outline in Presenter 8? I would prefer to not have that listed if at all posible and can't find a solution.

    Are you talking about the Time Remaining display on the side bar? The text for that field is in the Modify Text Labels... tool in the Theme Editor of Presenter. You can change it to whatever you want, but you may want to keep a record of what the default text labels are, as there is no restore to default option. The Elapsed Time field is what you would want to change. I have seen this modified to show no text, copyright information or other general info.

  • I am moving from PC to Mac.  My PC has two internal drives and I have a 3Tb external.  What is best way to move the data from the internal drives to Mac and the best way to make the external drive read write without losing data

    I am moving from PC to Mac.  My PC has two internal drives and I have a 3Tb external.  What is best way to move the data from the internal drives to Mac and the best way to make the external drive read write without losing data

    Paragon even has non-destriuctive conversion utility if you do want to change drive.
    Hard to imagine using 3TB that isn't NTFS. Mac uses GPT for default partition type as well as HFS+
    www.paragon-software.com
    Some general Apple Help www.apple.com/support/
    Also,
    Mac OS X Help
    http://www.apple.com/support/macbasics/
    Isolating Issues in Mac OS
    http://support.apple.com/kb/TS1388
    https://www.apple.com/support/osx/
    https://www.apple.com/support/quickassist/
    http://www.apple.com/support/mac101/help/
    http://www.apple.com/support/mac101/tour/
    Get Help with your Product
    http://docs.info.apple.com/article.html?artnum=304725
    Apple Mac App Store
    https://discussions.apple.com/community/mac_app_store/using_mac_apple_store
    How to Buy Mac OS X Mountain Lion/Lion
    http://www.apple.com/osx/how-to-upgrade/
    TimeMachine 101
    https://support.apple.com/kb/HT1427
    http://www.apple.com/support/timemachine
    Mac OS X Community
    https://discussions.apple.com/community/mac_os

  • I am unable to sync all my selected songs to my iphone.  The error message is that the computer is not authorized.  However, I have authorized the computer and iTunes confirms that.  Any ideas what can be done to fix this.  My phone is an iPhone 4S.

    I am unable to sync all my selected songs to my iphone.  The error message is that the computer is not authorized.  However, I have authorized the computer and iTunes confirms that.  Any ideas what can be done to fix this.  My phone is an iPhone 4S.

    Were some of the songs purchased from a different itunes account?

  • My iphone 4s has the connect to itunes screen. I have tried to reset, recover, etc but I keep getting and error-51 message. Any ideas how I can get my phone working again? I am not worried about saving any info just having a phone to use!

    I was in the middle of the iOS 8 update and tried to turn my phone off (yes, I realize this was dumb) But what happened was it tried to reset. Now,  my iphone 4s has the connect to itunes screen. I have tried to reset, recover, etc but I keep getting and error -51 message. Any ideas how I can get my phone working again? I am not worried about saving any info just having a phone to use!

    Try a Hard Reset.....
    Press and hold the Wake / Sleep button AND the Home button at the same time, keep them both pressed until the Apple Logo appears on the screen, it can take 10 or more seconds.  Ignore the swipe to turn off message.

  • I connected a digital camera memory chip with approximately 100 photos on it. The photos showed up in iPhoto. I believe I deleted the photos from the memory chip before importing them. Is there any way I can get the photos back?

    I connected a digital camera memory chip with approximately 100 photos on it to import into iPhoto. The photos showed up in iPhoto. I believe I deleted the photos from the memory chip before importing them to iPhoto. Is there any way I can get the photos back?

    Terence, thanks that site is a gem...have to explore it more fully at home as it drove security here crazy
    Looks like just the ticket for saving mistakes.

  • Best way to write this sql ?

    Please let me know best way to write this SQL.
    select col1, count(*)
    from TableA
    group by col1
    having count(*) =
    (select max(vals)
    from
    select col1, count(*) as vals
    from TableA
    group by col1
    having count(*) > 1
    )

    post EXPLAIN PLAN
    SELECT col1,
           COUNT(*)
    FROM   tablea
    GROUP  BY col1
    HAVING COUNT(*) = (SELECT MAX(vals)
                       FROM   (SELECT col1,
                                      COUNT(*) AS vals
                               FROM   tablea
                               GROUP  BY col1
                               HAVING COUNT(*) > 1))

  • Best way to write this report

    I hope someone can help. I am fairly new to Oracle Reports.
    I need to compile a report with totals only. The problem is I need to pull the detail data in to perform fuctions on that detail data but I don't want to display the detail data, only the bottom line numbers. Each time I try this I get numerous blank pages where the detail would be.
    What is my best option if any and where can I find information on this?

    For performance your report should be based on a single query that returns only the total amounts. If you do not need to display the details, why return them? Using multi-level functions you can write a single query to return your desired totals - and rather than having the functions inside the report, you can have them on the server, further increasing performance.
    HTH,
    Troy
    I hope someone can help. I am fairly new to Oracle Reports.
    I need to compile a report with totals only. The problem is I need to pull the detail data in to perform fuctions on that detail data but I don't want to display the detail data, only the bottom line numbers. Each time I try this I get numerous blank pages where the detail would be.
    What is my best option if any and where can I find information on this?

  • Any ideas why a film I have  converted to mp4 format, that plays with sound through my PC windows media file- only has a picture but no sound when transferred to my ipod touch via the Itunes?

    Any ideas why a film I have  converted to mp4 format, that plays with sound through my PC windows media file- only has a picture but no sound when transferred to my ipod touch via the Itunes?

    See:
    iTunes: May be unable to transfer videos to iPhone, iPad, or iPod
    iTunes: Frequently asked questions about viewing and syncing videos

Maybe you are looking for