DATA Step, Macro, Functions and more

Executing a powershell script from SAS

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 140
Accepted Solution

Executing a powershell script from SAS

Hello,

 

I am trying to find the best solution for executing a powershell script from a sas program.  I have found a few articles that discuss pulling information into SAS EG with powershell or calling SAS EG jobs using powershell but I have not seen anything that will show me how to execute a powershell command to run a script.

 

Any help would be appreciated.


Accepted Solutions
Solution
‎04-14-2016 04:14 PM
Frequent Contributor
Posts: 140

Re: Executing a powershell script from SAS

[ Edited ]

Ok, I figured it out by pieceing some articles I found together.

 

Within a SAS program, insert the following code.

 

%let machine = pp7h56j082; /* Machine name with admin privledges */
x 'C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe' -file "L:\Powershell Files\PrintFromExcelToPDF.ps1" &machine;

The Macro sets the machine name that has administrator permissions in order to call the powershell commands in the .ps1 file.  The remaining code opens powershell via windows command and passes in the powershell command to execute the powershell script needed. 

 

Hope this helps others!

View solution in original post


All Replies
Solution
‎04-14-2016 04:14 PM
Frequent Contributor
Posts: 140

Re: Executing a powershell script from SAS

[ Edited ]

Ok, I figured it out by pieceing some articles I found together.

 

Within a SAS program, insert the following code.

 

%let machine = pp7h56j082; /* Machine name with admin privledges */
x 'C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe' -file "L:\Powershell Files\PrintFromExcelToPDF.ps1" &machine;

The Macro sets the machine name that has administrator permissions in order to call the powershell commands in the .ps1 file.  The remaining code opens powershell via windows command and passes in the powershell command to execute the powershell script needed. 

 

Hope this helps others!

Super User
Posts: 6,963

Re: Executing a powershell script from SAS

Your code is not syntactically correct.

- there is a missing single quote to close the command string

- single quotes prevent the resolution of the macro variable

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 140

Re: Executing a powershell script from SAS

Thanks @KurtBremser.  It was a typo in my code but it seemed to work anyway.  I have corrected the code and the post above.  I appreciate the heads up!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 718 views
  • 0 likes
  • 2 in conversation