<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Scheduling with powershell - returncode in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Scheduling-with-powershell-returncode/m-p/676495#M203993</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I found an answer - there is automatic Powershell variable called $lastexitcode. So code can look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Execute sas code&lt;/P&gt;&lt;P&gt;C:\SAS\Config\Lev1\SASApp\BatchServer\sasbatch.bat -log C:\Temp\log.log -batch -noterminal -logparm ""rollover=session"" -sysin "C:\Temp\sasfile.sas"&lt;/P&gt;&lt;P&gt;#write information to log&lt;/P&gt;&lt;P&gt;(get-date -Format "yyyy.MM.dd HH:mm:ss").ToString() +&amp;nbsp;&amp;nbsp; "| &lt;STRONG&gt;$lastexitcode&lt;/STRONG&gt; |&amp;nbsp; My Job name" |Out-File -FilePath "C:\Temp\log_ps.log" -Append -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works good for me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Czarek&lt;/P&gt;</description>
    <pubDate>Thu, 13 Aug 2020 14:17:16 GMT</pubDate>
    <dc:creator>czarek</dc:creator>
    <dc:date>2020-08-13T14:17:16Z</dc:date>
    <item>
      <title>Scheduling with powershell - returncode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scheduling-with-powershell-returncode/m-p/675014#M203311</link>
      <description>&lt;P&gt;Good afternoon everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because I think, that scheduling in SAS Management Console has a lot of limitations, I'm trying to schedule my deployed DI jobs using powershell, which is more flexible than old vb scripts.&lt;/P&gt;&lt;P&gt;What I do now:&lt;/P&gt;&lt;P&gt;-deploy my job as before,&lt;/P&gt;&lt;P&gt;-create powershell file, which runs my sas file and creates a log, for now it looks like this:&lt;/P&gt;&lt;P&gt;$logname="C:\SAS\Config\Lev1\SchedulingServer\batchuser\SAP_RFC\Log\mylog_"+(get-date -uformat "%Y%m%d_%H%M%S").tostring()+".log"&lt;BR /&gt;C:\SAS\Config\Lev1\SASApp\BatchServer\sasbatch.bat -log $logname -batch -noterminal -logparm ""rollover=session"" -sysin "C:\SAS\Config\Lev1\SchedulingServer\batchuser\SAP_RFC\myprogram.sas"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run scheduled SAS job using the old method, I can see retun code (status) in small log from vbs script, eg:&lt;/P&gt;&lt;P&gt;Flow STARTING...&lt;BR /&gt;Job BOM_tab_A5P60HQJ_CE00000O STARTING 08/03/2020 04:00:00&lt;BR /&gt;Job BOM_tab_A5P60HQJ_CE00000O COMPLETE 08/03/2020 04:00:43 status=&lt;U&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/U&gt;.&lt;BR /&gt;Job MB51_tab_A5P60HQJ_CE00000Q STARTING 08/03/2020 04:00:43&lt;BR /&gt;Job MB51_tab_A5P60HQJ_CE00000Q COMPLETE 08/03/2020 04:09:05 status=&lt;U&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/U&gt;.&lt;/P&gt;&lt;P&gt;I can see it in Windows scheduler too (Last run result column)&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;My question is, how could I retrieve this value using powershell?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Czarek&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 14:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scheduling-with-powershell-returncode/m-p/675014#M203311</guid>
      <dc:creator>czarek</dc:creator>
      <dc:date>2020-08-06T14:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Scheduling with powershell - returncode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scheduling-with-powershell-returncode/m-p/676495#M203993</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I found an answer - there is automatic Powershell variable called $lastexitcode. So code can look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Execute sas code&lt;/P&gt;&lt;P&gt;C:\SAS\Config\Lev1\SASApp\BatchServer\sasbatch.bat -log C:\Temp\log.log -batch -noterminal -logparm ""rollover=session"" -sysin "C:\Temp\sasfile.sas"&lt;/P&gt;&lt;P&gt;#write information to log&lt;/P&gt;&lt;P&gt;(get-date -Format "yyyy.MM.dd HH:mm:ss").ToString() +&amp;nbsp;&amp;nbsp; "| &lt;STRONG&gt;$lastexitcode&lt;/STRONG&gt; |&amp;nbsp; My Job name" |Out-File -FilePath "C:\Temp\log_ps.log" -Append -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works good for me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Czarek&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 14:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scheduling-with-powershell-returncode/m-p/676495#M203993</guid>
      <dc:creator>czarek</dc:creator>
      <dc:date>2020-08-13T14:17:16Z</dc:date>
    </item>
  </channel>
</rss>

