title: Assign the result of a query to a variable in powershell in Azure-Runbooks
body: <p>I have a runbook using automation in Azure.  It is getting a single integer result from a table and it can return the correct value.  The code I am using is below and it works.</p>
  <pre><code> $SQLServerCred = Get-AutomationPSCredential -Name &quot;SqlCredential&quot;
   #Import the SQL Server Name from the Automation variable.
   $SQL_Server_Name = Get-AutomationVariable -Name &quot;SqlServer&quot;
   #Import the SQL DB from the Automation variable.
   $SQL_DB_Name = Get-AutomationVariable -Name &quot;Database&quot;
  
  
   $Query = &quot;select max(je.ExecutionOrder) as LastStepExecuted
  from PPoint.JobExecutionHistory je
  where je.EventType = 'Start'
  and je.JobRunId = PPoint.fnGetJobRunID()&quot;
  
   invoke-sqlcmd -ServerInstance &quot;$SQL_Server_Name&quot; -Database &quot;$SQL_DB_Name&quot; -Credential $SQLServerCred -Query &quot;$Query&quot; -Encrypt
  </code></pre>
  <p>The next step for me is to assign the result from the query to a variable and then evaluate it to see if it should call another runbook. So I want to have a variable named LastStep and assign it the integer result of LastStepExecuted from the query below.  I then want to do something along this line (this is pseudocode)</p>
  <pre><code>if LastStep = 2147483647
   call another runbook
  else
   do nothing - end the runbook
  </code></pre>
  <p>I have tried several ways to capture the LastStepExecuted in a variable but I can't figure it out.  Can anyone help?</p>
  <p>Any help or advice much appreciated.</p>