PowerShell for Loop Ideas

Hello,

I have recently came across a need for a powershell script for executing multiple curl commands via Api .

I am executing a Curl Post to trigger a work flow, and using a curl get to tap into the rss feed. I cant wrap my head around how to execute multiple Curl posts in a loop only to continue if the workflow was successful. The Rss feed will show running, until it either fails or succeeds. So Im thinking

for Loop
– Execute Curl Post
–> execute Curl Get and Watch
----> This is where Im confused, so how do I handle the three phases running/Failed/Success
Running I need to continue to watch, or do i do some kind of until but can I do it with multiple conditions Like
Until Curl Command If = Failed Break else if = success Continue?

I know its a newbie question, but any help would be appreciated as I am on a time crunch.

I would suggest using a switch statement. You would want to capture the output of the Curl get and run different code depending on the result. I’m not familiar with Curl, but here is a switch statement that should get the concept across.

$Bitness = Get-WmiObject win32_operatingsystem

Switch ($Bitness.OSArchitecture)
    {    
    "64-bit"
        {
          #Code here
        }

    "32-bit"
        {
            #Code here
        }
    }

I imagine with Curl, you would probably only get a few different results. You want to put all possible results (also known as a case) in quotes, with a corresponding script block right afterwards. For my example, there will only ever be two cases, 32-bit and 64-bit, so those are the only ones necessary. You can also set a default case if there are no matches. You can do that by doing something like this:

$Bitness = Get-WmiObject win32_operatingsystem

Switch ($Bitness.OSArchitecture)
    {

    default 
        {
         #Default code here
        }
      
    "64-bit"
        {
          #Code here
        }

    "32-bit"
        {
            #Code here
        }
    }