BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
elwayfan446
Barite | Level 11

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.

1 ACCEPTED SOLUTION

Accepted Solutions
elwayfan446
Barite | Level 11

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

3 REPLIES 3
elwayfan446
Barite | Level 11

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!

Kurt_Bremser
Super User

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

elwayfan446
Barite | Level 11

Thanks @Kurt_Bremser.  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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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