Invoking Stored Processes with Powershell - the easy way

There are a number of ways to run SAS from Powershell:

  1. Using SAS Integration Technologies (Chris Hemedinger has some great resources on this)
  2. Directly by calling sas.exe (presuming you are running on a box with a local install)
  3. Indirectly via the SAS Stored Process Web Application.
Let me explain the awesomeness of option 3:
  • It deals with authentication (no need for embedded passwords)
  • Can perform tasks using system account (sassrv), as SAS code is secured server-side
  • Resource management (no need to tidy up any redundant sessions)
  • Can be done in just ONE LINE of Powershell code!
For the sake of mobile readers, I’m going to split the example over three lines:
$pgm=“/Products/SAS Intelligence Platform/Samples/Sample: Hello World”
invoke-webrequest -Uri $($uri)?_program=$pgm -UseDefaultCredentials
Which gives the response:

The key part to this request, to avoid HTTP Status 401 and "This request requires HTTP authentication" response, is the -UseDefaultCredentials parameter.  This uses the account that Powershell is running in, to connect to the server.

Some prerequisites: