10

I am using ops tool Rundeck that allows for execution of arbitrary scripts. I enter the script text in the web application widget and upon execution, Rundeck saves it to temporary file and calls interpreter. The problem is that the temporary file doesn't have ps1 extension and Powershell refuses to execute it.

Is there any way to set up Powershell to ignore extension ?

=== EDIT 2018 ===

Rundeck now has an option for this within a job definition.

Nuno André
  • 4,739
  • 1
  • 33
  • 46
majkinetor
  • 8,730
  • 9
  • 54
  • 72
  • 1
    Are you using Rundeck or Rundeck Pro? Rundeck Pro includes the capability to run PowerShell scripts. – HAL9256 Aug 03 '18 at 20:49
  • 1
    I would say, this is not really a programming question, as you want to _configure_ an application (PowerShell) to run differently. If you'd want to program an alternative interpreter (let's say a short C# tool taking your file as argument and executing it in PowerShell) it would fit better imho. – Clijsters Aug 09 '18 at 11:07
  • Maybe this could help you somehow http://vcloud-lab.com/entries/powershell/powershell-trick-execute-or-run-any-file-as-a-script-file – TobyU Aug 09 '18 at 13:07
  • I found this thread which discusses the topic. Not fully convincing though.https://social.technet.microsoft.com/Forums/scriptcenter/en-US/08d3baf2-2e79-40b7-96d5-ff05fc516e3a/additional-powershell-file-extension?forum=ITCG – d-stroyer Aug 10 '18 at 10:17

1 Answers1

5

I know I'm not strictly answering your questions regarding setting up PowerShell to ignore extensions, but here is one way of executing code from a textfile:

Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content .\file.txt)))

This reads the contents of file.txt and converts it into a scriptblock, before executing it using Invoke-Command.

ojk
  • 2,502
  • 15
  • 17
  • I know that, but I can't use it, since I can only specify interpreter as a prefix, not insert the temporary file somewhere in between commands. – majkinetor Aug 20 '14 at 11:49
  • 1
    I would suggest to save the above line in a script file: powershellwrap.ps1, and designate this file as the interpreter executable for Rundeck. – d-stroyer Aug 10 '18 at 10:19
  • This was not an option back then. Now it is, and hence the question is now outdated. – majkinetor Aug 11 '18 at 08:56