Check multiple conditions, then if all are false do something
<p>Bit of background...</p>

<p>I'm trying to write a script which will run constantly. I need to it check to see if the Queue directory has an XML file in it, if it does, then send an API call to start some servers.</p>

<p>I've got this part sorted and it works.</p>

<p>I'm having issues with the second part where I need it to send another API Call to shutdown the servers if the following conditions are met;</p>

<ul>
<li>Queue Directory must be empty</li>
<li>Running Directory must be empty</li>
<li>The time between the servers starting and stopping must be to the nearest hour (its AWS so they charge by the hour, there's no point in stopping a server if its only been running for a few mins as we'll still be charged for the full hour. Then if we need to start again, we'll be charged another hour.)</li>
</ul>

<p>Here is what I have so far:</p>

<pre><code>$QueueDir = "D:\Test"
$RunningDir = "D:\Test\copydir"
while (!(Test-path $QueueDir\*.xml)) {Start-Sleep 10}
Write-Host "Starting Servers, API NORMALLY GOES HERE"
$Starttime = (Get-Date)
Write-Host "Started Servers @ $Starttime"
Start-Sleep -Seconds 30

while (!(Test-Path $rundir\*.xml)) {Start-Sleep 10}
$now = (Get-Date)
$timespan = (New-TimeSpan -Start $Starttime -End $now)
if ( (Test-Path $QueueDir\*.xml) -or (Test-Path $RunningDir\*.xml) -or ($timespan.Minutes -gt 50 -and -lt 55) ) {
  Write-Host "Stopping Servers, API NORMALLY GOES HERE"
  $StopTime = (Get-Date)
  Write-Host "Stopped Servers @ $Stoptime"
}
</code></pre>